Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6e2b458
feat(browser): host web extensions via WKWebExtension (Bitwarden supp…
KyloJorgensen Jul 9, 2026
f6bd395
fix(browser): address review findings on web-extension support
KyloJorgensen Jul 9, 2026
8aa9030
feat(settings): browser extension management in Settings > Browser
KyloJorgensen Jul 9, 2026
a18a5f4
feat(settings): import-based extension list instead of auto-discovery
KyloJorgensen Jul 9, 2026
775753c
refactor(browser): drop Bitwarden auto-seed; settings are the only so…
KyloJorgensen Jul 9, 2026
591415e
fix(browser): address review findings on extension management
KyloJorgensen Jul 9, 2026
e8b1dbb
Address browser extension review feedback
austinywang Jul 9, 2026
beb4209
Fix web extension unload and duplicate path state
austinywang Jul 9, 2026
d4d537e
Show duplicate web extension add feedback
austinywang Jul 9, 2026
bda4975
Fix browser extension panel lifecycle
austinywang Jul 9, 2026
5afd758
Address web extension review comments
austinywang Jul 9, 2026
223a38a
Order focused web extension window first
austinywang Jul 9, 2026
5ba4f0d
Use localized format for duplicate extension alert
austinywang Jul 9, 2026
87a0707
Fix web extension popout and window host wiring
austinywang Jul 9, 2026
f8849d5
Use localized format for manifest alert
austinywang Jul 9, 2026
677411c
Allow WebKit native messaging bridge
austinywang Jul 9, 2026
908140a
Forward web extension tab lifecycle
austinywang Jul 9, 2026
c3a9f1b
Hide imported extension paths from import menu
austinywang Jul 9, 2026
e685c71
Support extension tabs and action updates
austinywang Jul 9, 2026
cc43b81
Align web extension tab lifecycle with cmux focus
austinywang Jul 9, 2026
b6bda5b
Deduplicate Safari extension resource paths
austinywang Jul 9, 2026
c2bb853
Persist web extension navigation state
austinywang Jul 9, 2026
7774770
Guard web extension imports until settings load
austinywang Jul 9, 2026
c134130
Fix web extension review findings
austinywang Jul 9, 2026
c515a14
Harden web extension loading gates
austinywang Jul 9, 2026
622e5d1
Avoid redundant Safari extension reloads
austinywang Jul 9, 2026
8ac7905
fix(browser): repair three compile errors on the extension branch
KyloJorgensen Jul 9, 2026
cb2171e
Route web extension tabs from dock panels
austinywang Jul 9, 2026
39f66d8
Fix web extension window and toolbar updates
austinywang Jul 9, 2026
1dd14fc
Fix web extension private windows and activation
austinywang Jul 9, 2026
2d678da
test(browser): cover extension review regressions
austinywang Jul 9, 2026
7c9c455
fix(browser): address extension review findings
austinywang Jul 9, 2026
9c10d76
test(browser): cover remaining extension review regressions
austinywang Jul 9, 2026
721d772
fix(browser): address remaining extension review findings
austinywang Jul 9, 2026
c5677dc
Fix browser extension review findings
austinywang Jul 9, 2026
7c6bb51
test(browser): cover extension settings feedback
austinywang Jul 9, 2026
a9724a5
fix(browser): address remaining extension feedback
austinywang Jul 9, 2026
d56edb2
test(browser): cover clearing stale extension errors
austinywang Jul 9, 2026
63fd83a
fix(browser): reconcile extension feedback state
austinywang Jul 9, 2026
5508607
test(browser): cover extension lifecycle review regressions
austinywang Jul 9, 2026
8f0f20f
fix(browser): address extension lifecycle review regressions
austinywang Jul 10, 2026
4d3ad73
fix: hoist web-extension host creation out of StateObject autoclosure
austinywang Jul 10, 2026
fc8e336
test(browser): give each fake extension navigation a fresh configuration
austinywang Jul 10, 2026
32a7650
Route extension commands (e.g. Bitwarden ⌘⇧L) while browser focus mod…
lawrence703 Jul 10, 2026
f75b432
ci: follow cmuxAuxiliaryWindowIdentifiers to its new file in the clos…
austinywang Jul 10, 2026
e352be5
fix: drop no-op await flagged by the Swift warning budget
austinywang Jul 10, 2026
6063f15
fix(settings): don't flash 'no extensions added' before settings load
austinywang Jul 10, 2026
b5278d2
Complete user-managed browser web extensions
0xCUB3 Jul 10, 2026
b0fff2f
Address browser extension review feedback
0xCUB3 Jul 10, 2026
8d0d68d
Address remaining browser extension review feedback
0xCUB3 Jul 10, 2026
f2e19f1
Fix browser extension review regressions
0xCUB3 Jul 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/swift-file-length-budget.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
982 Packages/Shared/CmuxAgentChat/Tests/CmuxAgentChatTests/ChatConversationStoreTests.swift
951 Packages/macOS/CmuxControlSocket/Sources/CmuxControlSocket/Coordinator/Workspace/ControlCommandCoordinator+Workspace.swift
951 Sources/App/TerminalDirectoryOpenSupport.swift
948 Sources/App/ShortcutRoutingSupport.swift
966 Sources/App/ShortcutRoutingSupport.swift
947 Sources/TerminalNotificationPolicy.swift
945 Sources/SessionIndexRegisteredAgents.swift
944 Sources/CommandPalette/CommandPaletteSettingsToggle.swift
Expand Down Expand Up @@ -205,7 +205,7 @@
576 Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/MobileTerminalRenderGrid.swift
575 Packages/macOS/CmuxWorkspaces/Sources/CmuxWorkspaces/Coordinators/WorkspaceGroupCoordinator.swift
572 Sources/Feed/FeedTextEditorDebugWindowController.swift
567 Packages/macOS/CmuxSettingsUI/Sources/CmuxSettingsUI/Sections/BrowserSection.swift
581 Packages/macOS/CmuxSettingsUI/Sources/CmuxSettingsUI/Sections/BrowserSection.swift
567 Packages/macOS/CmuxTerminalCore/Sources/CmuxTerminalCore/ConfigDiscovery/GhosttyConfigDiscovery.swift
562 cmuxTests/AgentExecutableResolverTests.swift
561 cmuxTests/GhosttyConfigPathResolverTests.swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,12 @@ public struct BrowserCatalogSection: SettingCatalogSection {
userDefaultsKey: "browserImportHintDismissed"
)

/// Web extensions configured for the built-in browser (macOS 15.4+).
/// See ``BrowserWebExtensionEntry``; only `enabled` entries load.
public let webExtensions = JSONKey<[BrowserWebExtensionEntry]>(
id: "browser.webExtensions",
defaultValue: []
)

public init() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import Foundation

/// One web extension the user has configured for the built-in browser, stored
/// under `browser.webExtensions` in `cmux.json`.
///
/// Extensions come from two places: Safari web extensions installed on this
/// Mac inside another app's bundle (discovered automatically), and unpacked
/// WebExtension directories the user added by hand. Only entries with
/// ``enabled`` set actually load; discovered-but-untouched extensions have no
/// entry at all.
///
/// ```swift
/// BrowserWebExtensionEntry(
/// id: "com.bitwarden.desktop.safari",
/// kind: .safariAppExtension,
/// path: "/Applications/Bitwarden.app/Contents/PlugIns/safari.appex",
/// enabled: true
/// )
/// ```
public struct BrowserWebExtensionEntry: Codable, Sendable, Equatable, Hashable, Identifiable {
/// Where the extension's resources come from.
public enum Kind: String, Codable, Sendable {
/// A Safari web extension `.appex` bundled inside an installed app.
case safariAppExtension
/// A directory containing an unpacked WebExtension (`manifest.json` at
/// its root), Chrome/Firefox load-unpacked style.
case unpackedDirectory
}

/// Stable identity: the appex plug-in identifier for Safari extensions, or
/// the directory path for unpacked ones.
public var id: String
/// Where the extension's resources come from.
public var kind: Kind
/// Absolute path to the `.appex` bundle or unpacked directory.
public var path: String
/// Whether the extension loads into the browser.
public var enabled: Bool
/// Human-readable name captured when the extension was imported
/// (e.g. the containing app's name), shown in the settings list.
public var displayName: String?

/// - Parameters:
/// - id: Stable identity (appex plug-in identifier, or directory path).
/// - kind: Where the extension's resources come from.
/// - path: Absolute path to the `.appex` bundle or unpacked directory.
/// - enabled: Whether the extension loads into the browser.
/// - displayName: Human-readable name captured at import time.
public init(id: String, kind: Kind, path: String, enabled: Bool, displayName: String? = nil) {
self.id = id
self.kind = kind
self.path = path
self.enabled = enabled
self.displayName = displayName
}

/// Absolute, standardized path used to identify the effective extension
/// resource root for duplicate detection and reconciliation.
public var standardizedResourceRootPath: String {
Self.standardizedResourceRootPath(for: kind, path: path)
}

/// Returns a standardized filesystem path.
///
/// - Parameter path: The path to normalize.
/// - Returns: The standardized file URL path.
public static func standardizedPath(_ path: String) -> String {
URL(fileURLWithPath: path)
.resolvingSymlinksInPath()
.standardizedFileURL
.path
}

/// Returns the effective resource root for a configured extension path.
///
/// Safari app extensions load from `Contents/Resources` inside the `.appex`
/// bundle, so the bundle path and its resource directory compare equal.
///
/// - Parameters:
/// - kind: The configured extension kind.
/// - path: The `.appex` bundle path or unpacked extension directory.
/// - Returns: The standardized effective resource-root path.
public static func standardizedResourceRootPath(for kind: Kind, path: String) -> String {
switch kind {
case .safariAppExtension:
return standardizedSafariAppExtensionResourceRootPath(path)
case .unpackedDirectory:
return standardizedPath(path)
}
}

/// Returns the resource root WebKit uses for a Safari app extension.
///
/// - Parameter path: The `.appex` bundle path.
/// - Returns: `Contents/Resources` inside the bundle when `path` points at
/// an `.appex`, otherwise the standardized original path.
public static func standardizedSafariAppExtensionResourceRootPath(_ path: String) -> String {
let url = URL(fileURLWithPath: path)
.resolvingSymlinksInPath()
.standardizedFileURL
guard url.pathExtension == "appex" else { return url.path }
return url
.appendingPathComponent("Contents/Resources", isDirectory: true)
.resolvingSymlinksInPath()
.standardizedFileURL
.path
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}

// MARK: - SettingCodable

/// Stored as a nested JSON object; a malformed entry is rejected (decodes to
/// `nil`) rather than partially applied, so bad config fails closed.
extension BrowserWebExtensionEntry: SettingCodable {
public static func decodeFromUserDefaults(_ raw: Any?) -> BrowserWebExtensionEntry? {
decodeFromJSON(raw)
}

public func encodeForUserDefaults() -> Any {
encodeForJSON()
}

public static func decodeFromJSON(_ raw: Any?) -> BrowserWebExtensionEntry? {
guard let object = raw as? [String: Any] else { return nil }
guard let data = try? JSONSerialization.data(withJSONObject: object) else { return nil }
return try? JSONDecoder().decode(BrowserWebExtensionEntry.self, from: data)
}

public func encodeForJSON() -> Any {
guard let data = try? JSONEncoder().encode(self),
let object = try? JSONSerialization.jsonObject(with: data) else {
return NSNull()
}
return object
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Foundation
import Testing
@testable import CmuxSettings

@Suite("Browser web extension resource identity")
struct BrowserWebExtensionEntryTests {
@Test
func unpackedDirectorySymlinkAliasSharesResourceIdentity() throws {
let root = FileManager.default.temporaryDirectory
.appendingPathComponent("cmux-web-extension-\(UUID().uuidString)", isDirectory: true)
let realDirectory = root.appendingPathComponent("real", isDirectory: true)
let aliasDirectory = root.appendingPathComponent("alias", isDirectory: true)
try FileManager.default.createDirectory(at: realDirectory, withIntermediateDirectories: true)
try FileManager.default.createSymbolicLink(at: aliasDirectory, withDestinationURL: realDirectory)
defer { try? FileManager.default.removeItem(at: root) }

let realIdentity = BrowserWebExtensionEntry.standardizedResourceRootPath(
for: .unpackedDirectory,
path: realDirectory.path
)
let aliasIdentity = BrowserWebExtensionEntry.standardizedResourceRootPath(
for: .unpackedDirectory,
path: aliasDirectory.path
)

#expect(realIdentity == realDirectory.standardizedFileURL.path)
#expect(aliasIdentity == realIdentity)
}

@Test
func safariAppExtensionSymlinkAliasSharesResourcesIdentity() throws {
let root = FileManager.default.temporaryDirectory
.appendingPathComponent("cmux-safari-extension-\(UUID().uuidString)", isDirectory: true)
let realAppExtension = root.appendingPathComponent("Real.appex", isDirectory: true)
let resources = realAppExtension.appendingPathComponent("Contents/Resources", isDirectory: true)
let aliasAppExtension = root.appendingPathComponent("Alias.appex", isDirectory: true)
try FileManager.default.createDirectory(at: resources, withIntermediateDirectories: true)
try FileManager.default.createSymbolicLink(at: aliasAppExtension, withDestinationURL: realAppExtension)
defer { try? FileManager.default.removeItem(at: root) }

let realIdentity = BrowserWebExtensionEntry.standardizedResourceRootPath(
for: .safariAppExtension,
path: realAppExtension.path
)
let aliasIdentity = BrowserWebExtensionEntry.standardizedResourceRootPath(
for: .safariAppExtension,
path: aliasAppExtension.path
)

#expect(realIdentity == resources.standardizedFileURL.path)
#expect(aliasIdentity == realIdentity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,25 @@ public final class JSONValueModel<Value: SettingCodable> {
/// watcher.
public private(set) var current: Value

/// Monotonic identity for each value delivered by the change stream.
/// Consumers can use this to reject observations captured before a write.
public private(set) var observationRevision: UInt64 = 0

/// Whether the JSON change stream has yielded at least once.
public private(set) var hasObservedValue = false

/// Error from the most recent set/reset attempt, or `nil`.
public private(set) var lastWriteError: Error?
/// Monotonic identifier of the most recently completed set/reset attempt.
public private(set) var lastCompletedWriteID: UInt64 = 0
private(set) var writeResultRevision = 0

private let store: JSONConfigStore
private let key: JSONKey<Value>
private let errorLog: SettingsErrorLog
@ObservationIgnored private let makeStream: () -> AsyncStream<Value>
@ObservationIgnored private var nextWriteID: UInt64 = 0
@ObservationIgnored private var writeTask: Task<Void, Never>?

/// Owns the change-stream subscription and cancels it when this model
/// deallocates.
Expand Down Expand Up @@ -87,7 +99,10 @@ public final class JSONValueModel<Value: SettingCodable> {
/// lifecycle hook such as `.task`, not from their initializer.
public func startObserving() {
observation.activate(makeStream) { [weak self] value in
self?.current = value
guard let self else { return }
self.observationRevision &+= 1
self.current = value
self.hasObservedValue = true
}
}

Expand All @@ -96,35 +111,67 @@ public final class JSONValueModel<Value: SettingCodable> {
/// yields it back. On failure ``lastWriteError`` is populated and
/// recorded in the error log. Synchronous because SwiftUI `Binding`
/// setters can't `await`.
public func set(_ value: Value) {
@discardableResult
public func set(_ value: Value) -> UInt64 {
let keyID = key.id
Task { [weak self, store, key] in
let requestID = makeWriteRequestID()
let previousWriteTask = writeTask
writeTask = Task { [weak self, store, key] in
await previousWriteTask?.value
do {
try await store.set(value, for: key)
await MainActor.run { self?.lastWriteError = nil }
await MainActor.run {
guard let self else { return }
self.finishWrite(requestID: requestID, error: nil)
}
} catch {
await MainActor.run {
self?.lastWriteError = error
self?.errorLog.record(error, keyID: keyID)
guard let self else { return }
self.finishWrite(requestID: requestID, error: error)
self.errorLog.record(error, keyID: keyID)
}
}
}
return requestID
}

/// Removes the JSON entry (parents that become empty are pruned).
/// ``current`` updates when the stream observes the reset.
public func reset() {
@discardableResult
public func reset() -> UInt64 {
let keyID = key.id
Task { [weak self, store, key] in
let requestID = makeWriteRequestID()
let previousWriteTask = writeTask
writeTask = Task { [weak self, store, key] in
await previousWriteTask?.value
do {
try await store.reset(key)
await MainActor.run { self?.lastWriteError = nil }
await MainActor.run {
guard let self else { return }
self.finishWrite(requestID: requestID, error: nil)
}
} catch {
await MainActor.run {
self?.lastWriteError = error
self?.errorLog.record(error, keyID: keyID)
guard let self else { return }
self.finishWrite(requestID: requestID, error: error)
self.errorLog.record(error, keyID: keyID)
}
}
}
return requestID
}

private func makeWriteRequestID() -> UInt64 {
nextWriteID &+= 1
return nextWriteID
}

private func finishWrite(requestID: UInt64, error: Error?) {
lastCompletedWriteID = requestID
lastWriteError = error
writeResultRevision &+= 1
if requestID == nextWriteID {
writeTask = nil
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation

/// A Safari web extension found installed on this Mac, as reported by the
/// host through ``SettingsHostActions/discoverBrowserWebExtensions()``.
///
/// This is display metadata only; the persisted setting is
/// `BrowserWebExtensionEntry` in the catalog. `id` matches the entry's `id`
/// (the appex plug-in identifier) so the Browser section can join the two.
public struct SettingsDiscoveredBrowserExtension: Sendable, Identifiable, Equatable {
/// The appex plug-in identifier (e.g. `com.bitwarden.desktop.safari`).
public let id: String
/// Human-readable name resolved from the extension bundle, if available.
public let displayName: String?
/// The extension's version string, if available.
public let version: String?
/// Absolute path to the `.appex` bundle.
public let path: String

/// - Parameters:
/// - id: The appex plug-in identifier.
/// - displayName: Human-readable name from the extension bundle.
/// - version: The extension's version string.
/// - path: Absolute path to the `.appex` bundle.
public init(id: String, displayName: String?, version: String?, path: String) {
self.id = id
self.displayName = displayName
self.version = version
self.path = path
}
}
Loading