Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
2 changes: 1 addition & 1 deletion .github/swift-file-length-budget.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
534 Packages/macOS/CmuxControlSocket/Sources/CmuxControlSocket/Coordinator/Surface/ControlCommandCoordinator+Surface.swift
531 Sources/App/WorkspaceRuntimeSettings.swift
530 Packages/iOS/CmuxMobileTerminal/Sources/CmuxMobileTerminal/GhosttyRuntime.swift
532 Packages/macOS/CmuxSettingsUI/Sources/CmuxSettingsUI/Scene/SettingsWindowScene.swift
535 Packages/macOS/CmuxSettingsUI/Sources/CmuxSettingsUI/Scene/SettingsWindowScene.swift
528 cmuxTests/CLINotifyProcessTestSupport.swift
528 cmuxUITests/AutomationSocketUITests.swift
527 CLI/CLISocketPathResolver.swift
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Foundation

/// Settings under the dotted-id prefix `inlineVSCode.*`.
///
/// These control how the built-in "Open Current Directory in VS Code (Inline)"
/// command launches VS Code's `serve-web`. All four keys are JSON-backed so they
/// live in `~/.config/cmux/cmux.json` and can be edited either through the
/// Settings UI or by hand. They are read by the macOS app's serve-web launcher
/// at (re)start time; changing a value takes effect the next time inline VS Code
/// starts (use "Restart Inline VS Code" to apply immediately).
public struct InlineVSCodeCatalogSection: SettingCatalogSection {
/// Whether `serve-web` keeps its state (sign-in, Settings Sync, …) across
/// launches. Default `true`. When `false` (and no ``serverDataDir`` is set),
/// a throwaway data directory is used so nothing persists between launches.
public let persistServeWebState = JSONKey<Bool>(
id: "inlineVSCode.persistServeWebState",
defaultValue: true
)

/// Local port `serve-web` binds. Default `0`, which selects a random free
/// port. Set a value in `1...65535` to pin the port.
public let port = JSONKey<Int>(
id: "inlineVSCode.port",
defaultValue: 0
)

/// The `serve-web` server data directory (`--server-data-dir`). Empty (the
/// default) uses the upstream VS Code default location. A leading `~`
/// expands to the home directory.
public let serverDataDir = JSONKey<String>(
id: "inlineVSCode.serverDataDir",
defaultValue: ""
)

/// Advanced upstream VS Code `serve-web` flags appended after the
/// cmux-managed arguments. cmux-owned flags (host, port, connection token,
/// server data dir) are stripped so the loopback + connection-token
/// invariants hold. Empty by default.
public let extraArgs = JSONKey<[String]>(
id: "inlineVSCode.extraArgs",
defaultValue: []
)

public init() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public struct SettingCatalog: SettingCatalogSection {
public let betaFeatures = BetaFeaturesCatalogSection()
/// Settings for custom (user/agent-authored) sidebars (the `customSidebars.*` keys).
public let customSidebars = CustomSidebarsCatalogSection()
/// Settings for the Inline VS Code `serve-web` launcher (the `inlineVSCode.*` keys).
public let inlineVSCode = InlineVSCodeCatalogSection()
public let shortcuts = KeyboardShortcutsCatalogSection()
public let integrations = IntegrationsCatalogSection()
public let account = AccountCatalogSection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,36 @@ extension Array where Element == CuratedSettingEntry {
.init(section: .automation, id: "port-base", title: "Port Base", synonyms: "automation.portBase cmux_port start first base env environment variable"),
.init(section: .automation, id: "port-range", title: "Port Range Size", synonyms: "automation.portRange cmux_port_end range size count env ports"),

// Inline VS Code
.init(
section: .inlineVSCode,
id: "persist-state",
title: String(localized: "settings.inlineVSCode.persistState", defaultValue: "Persist serve-web State"),
paths: ["inlineVSCode.persistServeWebState"],
synonyms: "inlineVSCode.persistServeWebState vscode vs code serve web serve-web inline persist state sign in auth settings sync session ephemeral throwaway"
),
.init(
section: .inlineVSCode,
id: "port",
title: String(localized: "settings.inlineVSCode.port", defaultValue: "Port"),
paths: ["inlineVSCode.port"],
synonyms: "inlineVSCode.port vscode vs code serve web serve-web inline port localhost 127.0.0.1 pin random free"
),
.init(
section: .inlineVSCode,
id: "server-data-dir",
title: String(localized: "settings.inlineVSCode.serverDataDir", defaultValue: "Server Data Directory"),
paths: ["inlineVSCode.serverDataDir"],
synonyms: "inlineVSCode.serverDataDir vscode vs code serve web serve-web inline server data dir directory location path storage"
),
.init(
section: .inlineVSCode,
id: "extra-args",
title: String(localized: "settings.inlineVSCode.extraArgs", defaultValue: "Extra serve-web Arguments"),
paths: ["inlineVSCode.extraArgs"],
synonyms: "inlineVSCode.extraArgs vscode vs code serve web serve-web inline extra arguments args flags upstream advanced code-tunnel"
),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// Browser
.init(section: .browser, id: "enable-browser", title: "Enable cmux Browser", synonyms: "browser.disabled enable disable webview embedded browser tabs links"),
.init(section: .browser, id: "search-engine", title: "Default Search Engine", synonyms: "browser.defaultSearchEngine omnibar address bar google duckduckgo bing kagi brave startpage perplexity exa yahoo ecosia qwant mojeek wikipedia github baidu yandex custom search provider engine name url template"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum SettingsSectionID: String, CaseIterable, Identifiable, Sendable, Has
case customSidebars
case betaFeatures
case automation
/// Inline VS Code `serve-web` launch options.
case inlineVSCode
case browser
case browserImport
case globalHotkey
Expand All @@ -46,6 +48,7 @@ public enum SettingsSectionID: String, CaseIterable, Identifiable, Sendable, Has
case .customSidebars: return String(localized: "settings.section.customSidebars", defaultValue: "Custom Sidebars")
case .betaFeatures: return "Beta Features"
case .automation: return "Automation"
case .inlineVSCode: return String(localized: "settings.section.inlineVSCode", defaultValue: "Inline VS Code")
case .browser: return "Browser"
case .browserImport: return "Import Browser Data"
case .globalHotkey: return "Global Hotkey"
Expand All @@ -69,6 +72,7 @@ public enum SettingsSectionID: String, CaseIterable, Identifiable, Sendable, Has
case .customSidebars: return "sidebar.squares.left"
case .betaFeatures: return "exclamationmark.triangle"
case .automation: return "wand.and.sparkles"
case .inlineVSCode: return "chevron.left.forwardslash.chevron.right"
case .browser: return "globe"
case .browserImport: return "square.and.arrow.down"
case .globalHotkey: return "keyboard.badge.ellipsis"
Expand All @@ -94,6 +98,7 @@ public enum SettingsSectionID: String, CaseIterable, Identifiable, Sendable, Has
case .customSidebars: return "custom sidebars vibe swift json interpreted renderer in-process remote worker isolated"
case .betaFeatures: return "beta experimental unstable feed dock right sidebar"
case .automation: return "socket integrations hooks ports claude cursor gemini naming auto naming workspace tabs"
case .inlineVSCode: return "vscode vs code serve web serve-web inline editor port server data directory persist state extra args code-tunnel"
case .browser: return "search engine links history theme"
case .browserImport: return "browser import bookmarks history cookies"
case .globalHotkey: return "system wide shortcut"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ public struct SettingsWindowRoot: View {
)
.id(anchorID(for: .automation))

InlineVSCodeSection(jsonStore: jsonStore, catalog: catalog, errorLog: runtime.errorLog)
.id(anchorID(for: .inlineVSCode))

BrowserSection(
defaultsStore: defaultsStore,
catalog: catalog,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
import CmuxFoundation
import CmuxSettings
import SwiftUI

/// **Inline VS Code** section — controls how the built-in "Open Current
/// Directory in VS Code (Inline)" command launches VS Code's `serve-web`:
/// persistent state, the local port, the server data directory, and any extra
/// upstream `serve-web` flags. All four keys are JSON-backed (`inlineVSCode.*`
/// in `~/.config/cmux/cmux.json`); the macOS app reads them when inline VS Code
/// (re)starts.
@MainActor
public struct InlineVSCodeSection: View {
@State private var persist: JSONValueModel<Bool>
@State private var port: JSONValueModel<Int>
@State private var serverDataDir: JSONValueModel<String>
@State private var extraArgs: JSONValueModel<[String]>

@State private var portDraft: String = ""
@State private var portLoaded: Bool = false
@State private var serverDataDirDraft: String = ""
@State private var serverDataDirLoaded: Bool = false
@State private var extraArgsDraft: String = ""
@State private var extraArgsLoaded: Bool = false
@FocusState private var focusedField: Field?

private enum Field: Hashable {
case port
case serverDataDir
case extraArgs
}

public init(
jsonStore: JSONConfigStore,
catalog: SettingCatalog,
errorLog: SettingsErrorLog
) {
_persist = State(initialValue: JSONValueModel(
store: jsonStore,
key: catalog.inlineVSCode.persistServeWebState,
errorLog: errorLog
))
_port = State(initialValue: JSONValueModel(
store: jsonStore,
key: catalog.inlineVSCode.port,
errorLog: errorLog
))
_serverDataDir = State(initialValue: JSONValueModel(
store: jsonStore,
key: catalog.inlineVSCode.serverDataDir,
errorLog: errorLog
))
_extraArgs = State(initialValue: JSONValueModel(
store: jsonStore,
key: catalog.inlineVSCode.extraArgs,
errorLog: errorLog
))
}

public var body: some View {
Group {
SettingsSectionHeader(
String(localized: "settings.section.inlineVSCode", defaultValue: "Inline VS Code"),
section: .inlineVSCode
)
SettingsCard {
persistRow
SettingsCardDivider()
portRow
SettingsCardDivider()
serverDataDirRow
SettingsCardDivider()
extraArgsRow
SettingsCardDivider()
SettingsCardNote(String(
localized: "settings.inlineVSCode.note",
defaultValue: "These options apply when you run \"Open Current Directory in VS Code (Inline)\". Changes take effect the next time inline VS Code starts — use \"Restart Inline VS Code\" to apply them now. cmux always binds serve-web to 127.0.0.1 with a connection token; extra arguments are advanced and unsupported."
))
}
}
.task { startObservingSettings() }
.onChange(of: port.current) { _, newValue in
let normalized = Self.portText(newValue)
if Self.parsePort(portDraft) != newValue {
portDraft = normalized
}
}
.onChange(of: serverDataDir.current) { _, newValue in
if serverDataDirDraft != newValue {
serverDataDirDraft = newValue
}
}
.onChange(of: extraArgs.current) { _, newValue in
if Self.parseExtraArgs(extraArgsDraft) != newValue {
extraArgsDraft = newValue.joined(separator: "\n")
}
}
.onChange(of: focusedField) { previous, _ in
// Commit the field that just lost focus so edits aren't lost when the
// user tabs away, clicks elsewhere, or closes the Settings window
// without pressing Return.
switch previous {
case .port: commitPort()
case .serverDataDir: commitServerDataDir()
case .extraArgs: commitExtraArgs()
case nil: break
}
}
}

private func startObservingSettings() {
let models: [any SettingObservationStarting] = [persist, port, serverDataDir, extraArgs]
models.forEach { $0.startObserving() }
if !portLoaded {
portDraft = Self.portText(port.current)
portLoaded = true
}
if !serverDataDirLoaded {
serverDataDirDraft = serverDataDir.current
serverDataDirLoaded = true
}
if !extraArgsLoaded {
extraArgsDraft = extraArgs.current.joined(separator: "\n")
extraArgsLoaded = true
}
}

@ViewBuilder
private var persistRow: some View {
SettingsCardRow(
configurationReview: .json("inlineVSCode.persistServeWebState"),
String(localized: "settings.inlineVSCode.persistState", defaultValue: "Persist serve-web State"),
subtitle: persist.current
? String(localized: "settings.inlineVSCode.persistState.subtitleOn", defaultValue: "Keeps sign-in and Settings Sync state across restarts.")
: String(localized: "settings.inlineVSCode.persistState.subtitleOff", defaultValue: "Uses a throwaway data directory; nothing persists between launches.")
) {
Toggle("", isOn: Binding(get: { persist.current }, set: { persist.set($0) }))
.labelsHidden()
.controlSize(.small)
.accessibilityIdentifier("SettingsInlineVSCodePersistToggle")
}
}

@ViewBuilder
private var portRow: some View {
SettingsCardRow(
configurationReview: .json("inlineVSCode.port"),
String(localized: "settings.inlineVSCode.port", defaultValue: "Port"),
subtitle: String(localized: "settings.inlineVSCode.port.subtitle", defaultValue: "Local serve-web port. Leave empty (or 0) to pick a random free port. Range 1–65535."),
controlWidth: 120
) {
TextField(
String(localized: "settings.inlineVSCode.port.placeholder", defaultValue: "random"),
text: $portDraft
)
.focused($focusedField, equals: .port)
.onSubmit { commitPort() }
.textFieldStyle(.roundedBorder)
.multilineTextAlignment(.trailing)
.accessibilityIdentifier("SettingsInlineVSCodePortField")
}
}

@ViewBuilder
private var serverDataDirRow: some View {
SettingsCardRow(
configurationReview: .json("inlineVSCode.serverDataDir"),
String(localized: "settings.inlineVSCode.serverDataDir", defaultValue: "Server Data Directory"),
subtitle: String(localized: "settings.inlineVSCode.serverDataDir.subtitle", defaultValue: "serve-web --server-data-dir. Leave empty to use the VS Code default. A leading ~ expands to your home directory."),
controlWidth: 240
) {
TextField(
String(localized: "settings.inlineVSCode.serverDataDir.placeholder", defaultValue: "e.g. ~/Library/Application Support/cmux/vscode-serve-web"),
text: $serverDataDirDraft
)
.focused($focusedField, equals: .serverDataDir)
.onSubmit { commitServerDataDir() }
.textFieldStyle(.roundedBorder)
.accessibilityIdentifier("SettingsInlineVSCodeServerDataDirField")
}
}

@ViewBuilder
private var extraArgsRow: some View {
VStack(alignment: .leading, spacing: 6) {
SettingsCardRow(
configurationReview: .json("inlineVSCode.extraArgs"),
String(localized: "settings.inlineVSCode.extraArgs", defaultValue: "Extra serve-web Arguments"),
subtitle: String(localized: "settings.inlineVSCode.extraArgs.subtitle", defaultValue: "Advanced upstream VS Code serve-web flags, one per line. cmux-managed flags (host, port, connection token, server data dir) are ignored.")
) {
EmptyView()
}
TextEditor(text: $extraArgsDraft)
.focused($focusedField, equals: .extraArgs)
.cmuxFont(.body, design: .monospaced)
.frame(minHeight: 56, maxHeight: 120)
.scrollContentBackground(.hidden)
.padding(6)
.background(Color(nsColor: .controlBackgroundColor))
.cornerRadius(6)
.overlay(
RoundedRectangle(cornerRadius: 6)
.stroke(Color(nsColor: .separatorColor), lineWidth: 0.5)
)
.padding(.horizontal, 16)
.padding(.bottom, 12)
.accessibilityIdentifier("SettingsInlineVSCodeExtraArgsEditor")
}
}

private func commitPort() {
let parsed = Self.parsePort(portDraft)
if parsed != port.current {
port.set(parsed)
}
portDraft = Self.portText(parsed)
}

private func commitServerDataDir() {
let trimmed = serverDataDirDraft.trimmingCharacters(in: .whitespacesAndNewlines)
if trimmed != serverDataDir.current {
serverDataDir.set(trimmed)
}
serverDataDirDraft = trimmed
}

private func commitExtraArgs() {
let parsed = Self.parseExtraArgs(extraArgsDraft)
if parsed != extraArgs.current {
extraArgs.set(parsed)
}
}

/// Parses the port draft, clamping to the valid `serve-web` range. Empty or
/// out-of-range input resolves to `0` (a random free port).
static func parsePort(_ text: String) -> Int {
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
guard let value = Int(trimmed), (0...65535).contains(value) else { return 0 }
return value
}

/// Renders a stored port for the text field: `0` shows as empty (random).
static func portText(_ port: Int) -> String {
port == 0 ? "" : String(port)
}

/// Splits the multi-line draft into one argument per non-empty trimmed line.
static func parseExtraArgs(_ text: String) -> [String] {
text
.split(separator: "\n", omittingEmptySubsequences: false)
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
.filter { !$0.isEmpty }
}
}
Loading
Loading