Repository navigation
Extract cmux settings into SPM packages #4921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // swift-tools-version: 5.9 | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "CmuxSettings", | ||
| platforms: [ | ||
| .macOS(.v13) | ||
| ], | ||
| products: [ | ||
| .library( | ||
| name: "CmuxSettings", | ||
| targets: ["CmuxSettings"] | ||
| ), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "CmuxSettings", | ||
| path: "Sources/CmuxSettings" | ||
| ), | ||
| .testTarget( | ||
| name: "CmuxSettingsTests", | ||
| dependencies: ["CmuxSettings"], | ||
| path: "Tests/CmuxSettingsTests" | ||
| ), | ||
| ] | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import Foundation | ||
|
|
||
| public struct CmuxSettingsJSONPathDescriptor: Equatable, Hashable, Sendable { | ||
| public let path: String | ||
| public let section: String | ||
|
|
||
| public init(path: String, section: String? = nil) { | ||
| self.path = path | ||
| self.section = section ?? path.split(separator: ".", maxSplits: 1).first.map(String.init) ?? path | ||
| } | ||
| } | ||
|
|
||
| public enum CmuxSettingsCatalog { | ||
| public static let currentSchemaVersion = 1 | ||
|
|
||
| public static let schemaURLString = | ||
| "https://raw.githubusercontent.com/manaflow-ai/cmux/main/web/data/cmux.schema.json" | ||
|
|
||
| public static func defaultPrimaryURL(homeDirectoryURL: URL = FileManager.default.homeDirectoryForCurrentUser) -> URL { | ||
| homeDirectoryURL | ||
| .appendingPathComponent(".config", isDirectory: true) | ||
| .appendingPathComponent("cmux", isDirectory: true) | ||
| .appendingPathComponent("cmux.json", isDirectory: false) | ||
| } | ||
|
|
||
| public static func defaultLegacyURL(homeDirectoryURL: URL = FileManager.default.homeDirectoryForCurrentUser) -> URL { | ||
| homeDirectoryURL | ||
| .appendingPathComponent(".config", isDirectory: true) | ||
| .appendingPathComponent("cmux", isDirectory: true) | ||
| .appendingPathComponent("settings.json", isDirectory: false) | ||
| } | ||
|
|
||
| public static func defaultApplicationSupportLegacyURL( | ||
| applicationSupportDirectoryURL: URL, | ||
| releaseBundleIdentifier: String = "com.cmuxterm.app" | ||
| ) -> URL { | ||
| applicationSupportDirectoryURL | ||
| .appendingPathComponent(releaseBundleIdentifier, isDirectory: true) | ||
| .appendingPathComponent("settings.json", isDirectory: false) | ||
| } | ||
|
|
||
| public static let supportedJSONPathDescriptors: [CmuxSettingsJSONPathDescriptor] = | ||
| supportedJSONPathValues.map { CmuxSettingsJSONPathDescriptor(path: $0) } | ||
|
|
||
| public static let supportedJSONPaths: Set<String> = Set(supportedJSONPathValues) | ||
|
|
||
| private static let supportedJSONPathValues: [String] = [ | ||
| "app.language", | ||
| "app.appearance", | ||
| "app.appIcon", | ||
| "app.menuBarOnly", | ||
| "app.newWorkspacePlacement", | ||
| "app.workspaceInheritWorkingDirectory", | ||
| "app.minimalMode", | ||
| "app.keepWorkspaceOpenWhenClosingLastSurface", | ||
| "app.focusPaneOnFirstClick", | ||
| "app.preferredEditor", | ||
| "app.openSupportedFilesInCmux", | ||
| "app.openMarkdownInCmuxViewer", | ||
| "app.iMessageMode", | ||
| "app.reorderOnNotification", | ||
| "app.sendAnonymousTelemetry", | ||
| "app.confirmQuit", | ||
| "app.warnBeforeQuit", | ||
| "app.warnBeforeClosingTab", | ||
| "app.warnBeforeClosingTabXButton", | ||
| "app.hideTabCloseButton", | ||
| "app.renameSelectsExistingName", | ||
| "app.commandPaletteSearchesAllSurfaces", | ||
| "terminal.showScrollBar", | ||
| "terminal.copyOnSelect", | ||
| "terminal.autoResumeAgentSessions", | ||
| "terminal.agentHibernation.enabled", | ||
| "terminal.agentHibernation.idleSeconds", | ||
| "terminal.agentHibernation.maxLiveTerminals", | ||
| "terminal.textBoxMaxLines", | ||
| "terminal.resumeCommands", | ||
| "notifications.dockBadge", | ||
| "notifications.showInMenuBar", | ||
| "notifications.unreadPaneRing", | ||
| "notifications.paneFlash", | ||
| "notifications.sound", | ||
| "notifications.customSoundFilePath", | ||
| "notifications.command", | ||
| "notifications.hooks", | ||
| "notifications.hooksMode", | ||
| "sidebar.hideAllDetails", | ||
| "sidebar.wrapWorkspaceTitles", | ||
| "sidebar.showWorkspaceDescription", | ||
| "sidebar.branchLayout", | ||
| "sidebar.stackBranchDirectory", | ||
| "sidebar.pathLastSegmentOnly", | ||
| "sidebar.showNotificationMessage", | ||
| "sidebar.showBranchDirectory", | ||
| "sidebar.showPullRequests", | ||
| "sidebar.watchGitStatus", | ||
| "sidebar.makePullRequestsClickable", | ||
| "sidebar.openPullRequestLinksInCmuxBrowser", | ||
| "sidebar.openPortLinksInCmuxBrowser", | ||
| "sidebar.showSSH", | ||
| "sidebar.showPorts", | ||
| "sidebar.showLog", | ||
| "sidebar.showProgress", | ||
| "sidebar.showCustomMetadata", | ||
| "workspaceColors.indicatorStyle", | ||
| "workspaceColors.selectionColor", | ||
| "workspaceColors.notificationBadgeColor", | ||
| "workspaceColors.colors", | ||
| "workspaceColors.paletteOverrides", | ||
| "workspaceColors.customColors", | ||
| "sidebarAppearance.matchTerminalBackground", | ||
| "sidebarAppearance.tintColor", | ||
| "sidebarAppearance.lightModeTintColor", | ||
| "sidebarAppearance.darkModeTintColor", | ||
| "sidebarAppearance.tintOpacity", | ||
| "automation.socketControlMode", | ||
| "automation.socketPassword", | ||
| "automation.claudeCodeIntegration", | ||
| "automation.claudeBinaryPath", | ||
| "automation.ripgrepBinaryPath", | ||
| "automation.suppressSubagentNotifications", | ||
| "automation.cursorIntegration", | ||
| "automation.geminiIntegration", | ||
| "automation.portBase", | ||
| "automation.portRange", | ||
| "browser.defaultSearchEngine", | ||
| "browser.customSearchEngineName", | ||
| "browser.customSearchEngineURLTemplate", | ||
| "browser.showSearchSuggestions", | ||
| "browser.theme", | ||
| "browser.discardHiddenWebViews", | ||
| "browser.hiddenWebViewDiscardDelaySeconds", | ||
| "browser.openTerminalLinksInCmuxBrowser", | ||
| "browser.interceptTerminalOpenCommandInCmuxBrowser", | ||
| "browser.hostsToOpenInEmbeddedBrowser", | ||
| "browser.urlsToAlwaysOpenExternally", | ||
| "browser.insecureHttpHostsAllowedInEmbeddedBrowser", | ||
| "browser.showImportHintOnBlankTabs", | ||
| "browser.reactGrabVersion", | ||
| "shortcuts.bindings", | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import Dispatch | ||
| import Foundation | ||
|
|
||
| public struct CmuxSettingsFileSnapshot: Equatable, Sendable { | ||
| public var url: URL | ||
| public var contents: String | ||
|
|
||
| public init(url: URL, contents: String) { | ||
| self.url = url | ||
| self.contents = contents | ||
| } | ||
| } | ||
|
|
||
| public enum CmuxSettingsStoreError: Error, Equatable { | ||
| case unreadableData(URL) | ||
| } | ||
|
|
||
| public actor CmuxSettingsStore { | ||
| public let primaryURL: URL | ||
| public let fallbackURLs: [URL] | ||
|
|
||
| private let fileManager: FileManager | ||
|
|
||
| public init( | ||
| primaryURL: URL = CmuxSettingsCatalog.defaultPrimaryURL(), | ||
| fallbackURLs: [URL] = [CmuxSettingsCatalog.defaultLegacyURL()], | ||
| fileManager: FileManager = .default | ||
| ) { | ||
| self.primaryURL = primaryURL | ||
| self.fallbackURLs = fallbackURLs | ||
| self.fileManager = fileManager | ||
| } | ||
|
|
||
| public func readActiveSnapshot() throws -> CmuxSettingsFileSnapshot { | ||
| let activeURL = ([primaryURL] + fallbackURLs).first { url in | ||
| fileManager.fileExists(atPath: url.path) | ||
| } ?? primaryURL | ||
| return try readSnapshot(at: activeURL) | ||
| } | ||
|
|
||
| public func readPrimarySnapshot() throws -> CmuxSettingsFileSnapshot { | ||
| try readSnapshot(at: primaryURL) | ||
| } | ||
|
|
||
| public func writePrimaryContents(_ contents: String) throws { | ||
| try fileManager.createDirectory( | ||
| at: primaryURL.deletingLastPathComponent(), | ||
| withIntermediateDirectories: true | ||
| ) | ||
| try contents.write(to: primaryURL, atomically: true, encoding: .utf8) | ||
| } | ||
|
|
||
| public nonisolated func primaryChanges() -> AsyncStream<CmuxSettingsFileSnapshot> { | ||
| fileChanges(at: primaryURL) | ||
| } | ||
|
|
||
| public nonisolated func fileChanges(at url: URL) -> AsyncStream<CmuxSettingsFileSnapshot> { | ||
| AsyncStream { continuation in | ||
| let watcher = CmuxSettingsFileWatcher(url: url) { | ||
| guard let contents = try? String(contentsOf: url, encoding: .utf8) else { return } | ||
| continuation.yield(CmuxSettingsFileSnapshot(url: url, contents: contents)) | ||
| } | ||
| continuation.onTermination = { _ in watcher.cancel() } | ||
| } | ||
|
Comment on lines
+57
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate the watcher implementation and the store method
rg -n "class CmuxSettingsFileWatcher|struct CmuxSettingsFileWatcher|CmuxSettingsFileWatcher" -S Packages/CmuxSettings/Sources/CmuxSettings || true
rg -n "nonisolated func fileChanges\\(at url: URL\\)" -S Packages/CmuxSettings/Sources/CmuxSettings || true
# Show the cited regions
sed -n '1,140p' Packages/CmuxSettings/Sources/CmuxSettings/CmuxSettingsStore.swift | cat -n
# If the watcher is in another file, print that too
WATCHER_FILE="$(rg -l "CmuxSettingsFileWatcher" Packages/CmuxSettings/Sources/CmuxSettings | head -n 20)"
echo "Watcher files:"
echo "$WATCHER_FILE"
for f in $WATCHER_FILE; do
echo "---- $f ----"
# Avoid huge output: print first ~220 lines or until match region
sed -n '1,220p' "$f" | cat -n
done
# Also inspect around lines mentioned "Also applies to: 90-111"
# (These are within the same file; we already printed to 140 with line numbers.)Repository: manaflow-ai/cmux Length of output: 10504 Fix CmuxSettingsStore fileChanges watcher to emit cleared/created states (missing-at-subscription + delete/rename)
Suggested direction- let descriptor = open(url.path, O_EVTONLY)
+ // Watch parent directory when file may not exist yet, and (re)arm file-specific watch
+ // after create/rename. Emit an empty snapshot when file is missing/deleted.🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| private func readSnapshot(at url: URL) throws -> CmuxSettingsFileSnapshot { | ||
| guard fileManager.fileExists(atPath: url.path) else { | ||
| return CmuxSettingsFileSnapshot(url: url, contents: "") | ||
| } | ||
| guard let contents = try? String(contentsOf: url, encoding: .utf8) else { | ||
| throw CmuxSettingsStoreError.unreadableData(url) | ||
| } | ||
| return CmuxSettingsFileSnapshot(url: url, contents: contents) | ||
| } | ||
| } | ||
|
Comment on lines
+4
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document the public store API with Swift-DocC comments. All exported symbols in this new package source file need As per coding guidelines: 🤖 Prompt for AI Agents |
||
|
|
||
| private final class CmuxSettingsFileWatcher: @unchecked Sendable { | ||
| private let queue: DispatchQueue | ||
| private let source: DispatchSourceFileSystemObject? | ||
| private let fileDescriptor: CInt | ||
| private let onChange: @Sendable () -> Void | ||
| private let lock = NSLock() | ||
| private var isCancelled = false | ||
|
|
||
| init(url: URL, onChange: @escaping @Sendable () -> Void) { | ||
| self.queue = DispatchQueue(label: "com.cmux.settings.file-watcher.\(UUID().uuidString)") | ||
| self.onChange = onChange | ||
|
|
||
| let descriptor = open(url.path, O_EVTONLY) | ||
| guard descriptor >= 0 else { | ||
| fileDescriptor = -1 | ||
|
Comment on lines
+82
to
+92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| source = nil | ||
| return | ||
| } | ||
|
|
||
| fileDescriptor = descriptor | ||
| let source = DispatchSource.makeFileSystemObjectSource( | ||
| fileDescriptor: descriptor, | ||
| eventMask: [.write, .delete, .rename, .revoke], | ||
| queue: queue | ||
| ) | ||
| self.source = source | ||
| source.setEventHandler { [weak self] in | ||
| self?.onChange() | ||
| } | ||
| source.setCancelHandler { | ||
| close(descriptor) | ||
| } | ||
| source.resume() | ||
| } | ||
|
Comment on lines
+99
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the |
||
|
|
||
| deinit { | ||
| cancel() | ||
| } | ||
|
|
||
| func cancel() { | ||
| lock.lock() | ||
| defer { lock.unlock() } | ||
| guard !isCancelled else { return } | ||
| isCancelled = true | ||
| source?.cancel() | ||
| if source == nil, fileDescriptor >= 0 { | ||
| close(fileDescriptor) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import XCTest | ||
| @testable import CmuxSettings | ||
|
|
||
| final class CmuxSettingsCatalogTests: XCTestCase { | ||
| func testSupportedJSONPathsContainCurrentSettingsSurface() { | ||
| XCTAssertTrue(CmuxSettingsCatalog.supportedJSONPaths.contains("app.appearance")) | ||
| XCTAssertTrue(CmuxSettingsCatalog.supportedJSONPaths.contains("terminal.autoResumeAgentSessions")) | ||
| XCTAssertTrue(CmuxSettingsCatalog.supportedJSONPaths.contains("browser.defaultSearchEngine")) | ||
| XCTAssertTrue(CmuxSettingsCatalog.supportedJSONPaths.contains("shortcuts.bindings")) | ||
| } | ||
|
|
||
| func testDefaultPrimaryURLUsesCmuxJSON() { | ||
| let home = URL(fileURLWithPath: "/tmp/cmux-settings-home", isDirectory: true) | ||
| XCTAssertEqual( | ||
| CmuxSettingsCatalog.defaultPrimaryURL(homeDirectoryURL: home).path, | ||
| "/tmp/cmux-settings-home/.config/cmux/cmux.json" | ||
| ) | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
FILE="Packages/CmuxSettings/Tests/CmuxSettingsTests/CmuxSettingsCatalogTests.swift"
echo "=== File exists? ==="
ls -la "$FILE" || true
echo "=== First 120 lines of file ==="
sed -n '1,120p' "$FILE" | cat -n
echo "=== Search for XCTest usage in Packages/CmuxSettings/Tests ==="
rg -n --hidden --glob 'Packages/CmuxSettings/Tests/**/*.swift' 'import XCTest|XCTestCase|XCTAssert' || true
echo "=== Search for Swift Testing usage in Packages/CmuxSettings/Tests ==="
rg -n --hidden --glob 'Packages/CmuxSettings/Tests/**/*.swift' 'import Testing|`@Suite`|`@Test`|`#expect`|`#require`' || true
echo "=== Locate review-bot rules for Swift Testing guidance ==="
ls -la .github/review-bot-rules || true
rg -n --hidden 'Swift Testing framework|import Testing|`@Suite`|`@Test`|`#expect`|`#require`' .github/review-bot-rules || trueRepository: manaflow-ai/cmux Length of output: 4406 Migrate package tests from XCTest to Swift Testing
🧰 Tools🪛 SwiftLint (0.63.2)[Warning] 4-4: Classes should have an explicit deinit method (required_deinit) 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import XCTest | ||
| @testable import CmuxSettings | ||
|
|
||
| final class CmuxSettingsStoreTests: XCTestCase { | ||
| func testWriteAndReadPrimarySnapshot() async throws { | ||
| let directory = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-settings-\(UUID().uuidString)", isDirectory: true) | ||
| let primaryURL = directory.appendingPathComponent("cmux.json", isDirectory: false) | ||
| let store = CmuxSettingsStore(primaryURL: primaryURL, fallbackURLs: []) | ||
|
|
||
| try await store.writePrimaryContents("{\"schemaVersion\":1}") | ||
| let snapshot = try await store.readPrimarySnapshot() | ||
|
|
||
| XCTAssertEqual(snapshot.url, primaryURL) | ||
| XCTAssertEqual(snapshot.contents, "{\"schemaVersion\":1}") | ||
| } | ||
|
|
||
| func testActiveSnapshotFallsBackWhenPrimaryIsMissing() async throws { | ||
| let directory = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-settings-\(UUID().uuidString)", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) | ||
|
|
||
| let primaryURL = directory.appendingPathComponent("cmux.json", isDirectory: false) | ||
| let fallbackURL = directory.appendingPathComponent("settings.json", isDirectory: false) | ||
| try "{\"legacy\":true}".write(to: fallbackURL, atomically: true, encoding: .utf8) | ||
|
|
||
| let store = CmuxSettingsStore(primaryURL: primaryURL, fallbackURLs: [fallbackURL]) | ||
| let snapshot = try await store.readActiveSnapshot() | ||
|
|
||
| XCTAssertEqual(snapshot.url, fallbackURL) | ||
| XCTAssertEqual(snapshot.contents, "{\"legacy\":true}") | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
FILE="Packages/CmuxSettings/Tests/CmuxSettingsTests/CmuxSettingsStoreTests.swift"
echo "=== File: $FILE ==="
if [ -f "$FILE" ]; then
wc -l "$FILE"
sed -n '1,200p' "$FILE" | cat -n
else
echo "Missing: $FILE"
exit 1
fi
echo
echo "=== Search for Swift Testing usage in Packages/CmuxSettings/Tests ==="
rg -n --hidden --no-ignore-vcs "import Testing|`#expect`\\(|`@Test`|`@Suite`" Packages/CmuxSettings/Tests || true
echo
echo "=== Search for XCTest usage in Packages/CmuxSettings/Tests ==="
rg -n --hidden --no-ignore-vcs "import XCTest|XCTestCase|XCTAssert" Packages/CmuxSettings/Tests || true
echo
echo "=== Search for Swift Testing usage across repo tests (quick check) ==="
rg -n --hidden --no-ignore-vcs "import Testing" Packages/**/Tests/**/*.swift | head -n 50 || trueRepository: manaflow-ai/cmux Length of output: 5164 Replace XCTest with Swift Testing in CmuxSettings package tests
🧰 Tools🪛 SwiftLint (0.63.2)[Warning] 4-4: Classes should have an explicit deinit method (required_deinit) 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // swift-tools-version: 5.9 | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "CmuxSettingsUI", | ||
| platforms: [ | ||
| .macOS(.v13) | ||
| ], | ||
| products: [ | ||
| .library( | ||
| name: "CmuxSettingsUI", | ||
| targets: ["CmuxSettingsUI"] | ||
| ), | ||
| ], | ||
| dependencies: [ | ||
| .package(path: "../CmuxSettings"), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "CmuxSettingsUI", | ||
| dependencies: ["CmuxSettings"], | ||
| path: "Sources/CmuxSettingsUI" | ||
| ), | ||
| .testTarget( | ||
| name: "CmuxSettingsUITests", | ||
| dependencies: ["CmuxSettingsUI"], | ||
| path: "Tests/CmuxSettingsUITests" | ||
| ), | ||
| ] | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add DocC comments for all public API in this package file.
This new package source exports public types/members without
///documentation, which violates the package API documentation requirement.As per coding guidelines:
Packages/**/Sources/**/*.swift: “Everypublicsymbol in any new Swift package underPackages/must be documented with a Swift-DocC triple-slash comment…”.🤖 Prompt for AI Agents