chore(swift): run swiftformat and clear swiftlint

main
Peter Steinberger 2025-12-13 19:53:17 +00:00
parent 39c232548c
commit 6143338116
18 changed files with 713 additions and 723 deletions

View File

@ -51,8 +51,7 @@ actor BridgeClient {
nodeId: hello.nodeId,
displayName: hello.displayName,
platform: hello.platform,
version: hello.version
),
version: hello.version),
over: connection)
onStatus?("Waiting for approval…")

View File

@ -1,5 +1,13 @@
import ClawdisKit
import SwiftUI
@MainActor
private final class ConnectStatusStore: ObservableObject {
@Published var text: String?
}
extension ConnectStatusStore: @unchecked Sendable {}
struct SettingsTab: View {
@EnvironmentObject private var appModel: NodeAppModel
@Environment(\.dismiss) private var dismiss
@ -8,7 +16,7 @@ struct SettingsTab: View {
@AppStorage("voiceWake.enabled") private var voiceWakeEnabled: Bool = false
@AppStorage("bridge.preferredStableID") private var preferredBridgeStableID: String = ""
@StateObject private var discovery = BridgeDiscoveryModel()
@State private var connectStatus: String?
@StateObject private var connectStatus = ConnectStatusStore()
@State private var connectingBridgeID: String?
@State private var didAutoConnect = false
@ -47,8 +55,8 @@ struct SettingsTab: View {
self.bridgeList(showing: .all)
}
if let connectStatus {
Text(connectStatus)
if let text = self.connectStatus.text {
Text(text)
.font(.footnote)
.foregroundStyle(.secondary)
}
@ -86,13 +94,11 @@ struct SettingsTab: View {
displayName: self.displayName,
token: existing,
platform: self.platformString(),
version: self.appVersion()
)
)
self.connectStatus = nil
version: self.appVersion()))
self.connectStatus.text = nil
}
.onChange(of: self.appModel.bridgeServerName) { _, _ in
self.connectStatus = nil
self.connectStatus.text = nil
}
}
}
@ -178,17 +184,16 @@ struct SettingsTab: View {
displayName: self.displayName,
token: existingToken,
platform: self.platformString(),
version: self.appVersion()
)
version: self.appVersion())
let token = try await BridgeClient().pairAndHello(
endpoint: bridge.endpoint,
hello: hello,
onStatus: { status in
let store = self.connectStatus
Task { @MainActor in
self.connectStatus = status
store.text = status
}
}
)
})
if !token.isEmpty, token != existingToken {
_ = KeychainStore.saveString(
@ -204,12 +209,10 @@ struct SettingsTab: View {
displayName: self.displayName,
token: token,
platform: self.platformString(),
version: self.appVersion()
)
)
version: self.appVersion()))
} catch {
self.connectStatus = "Failed: \(error.localizedDescription)"
self.connectStatus.text = "Failed: \(error.localizedDescription)"
}
}

View File

@ -4,6 +4,11 @@ import SwiftUI
struct ConfigSettings: View {
private let isPreview = ProcessInfo.processInfo.isPreview
private let labelColumnWidth: CGFloat = 120
private static let browserAttachOnlyHelp =
"When enabled, the browser server will only connect if the clawd browser is already running."
private static let browserProfileNote =
"Clawd uses a separate Chrome profile and ports (default 18791/18792) "
+ "so it wont interfere with your daily browser."
@State private var configModel: String = ""
@State private var customModel: String = ""
@State private var configSaving = false
@ -203,16 +208,12 @@ struct ConfigSettings: View {
.toggleStyle(.checkbox)
.disabled(!self.browserEnabled)
.onChange(of: self.browserAttachOnly) { _, _ in self.autosaveConfig() }
.help(
"When enabled, the browser server will only connect if the clawd browser is already running."
)
.help(Self.browserAttachOnlyHelp)
}
GridRow {
Color.clear
.frame(width: self.labelColumnWidth, height: 1)
Text(
"Clawd uses a separate Chrome profile and ports (default 18791/18792) so it wont interfere with your daily browser."
)
Text(Self.browserProfileNote)
.font(.footnote)
.foregroundStyle(.secondary)
.frame(maxWidth: .infinity, alignment: .leading)

View File

@ -71,8 +71,7 @@ struct CronSettings: View {
}
Text(
"Jobs are saved, but they will not run automatically until `cron.enabled` is set to `true` " +
"and the Gateway restarts."
)
"and the Gateway restarts.")
.font(.footnote)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
@ -497,6 +496,21 @@ private struct CronJobEditor: View {
let onSave: ([String: Any]) -> Void
private let labelColumnWidth: CGFloat = 160
private static let introText =
"Create a schedule that wakes clawd via the Gateway. "
+ "Use an isolated session for agent turns so your main chat stays clean."
private static let sessionTargetNote =
"Main jobs post a system event into the current main session. "
+ "Isolated jobs run clawd in a dedicated session and can deliver results (WhatsApp/Telegram/etc)."
private static let scheduleKindNote =
"“At” runs once, “Every” repeats with a duration, “Cron” uses a 5-field Unix expression."
private static let isolatedPayloadNote =
"Isolated jobs always run an agent turn. The result can be delivered to a surface, "
+ "and a short summary is posted back to your main chat."
private static let mainPayloadNote =
"System events are injected into the current main session. Agent turns require an isolated session target."
private static let mainSummaryNote =
"Controls the label used when posting the completion summary back to the main session."
@State private var name: String = ""
@State private var enabled: Bool = true
@ -527,9 +541,7 @@ private struct CronJobEditor: View {
VStack(alignment: .leading, spacing: 6) {
Text(self.job == nil ? "New cron job" : "Edit cron job")
.font(.title3.weight(.semibold))
Text(
"Create a schedule that wakes clawd via the Gateway. Use an isolated session for agent turns so your main chat stays clean."
)
Text(Self.introText)
.font(.callout)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
@ -575,8 +587,7 @@ private struct CronJobEditor: View {
Color.clear
.frame(width: self.labelColumnWidth, height: 1)
Text(
"Main jobs post a system event into the current main session. Isolated jobs run clawd in a dedicated session and can deliver results (WhatsApp/Telegram/etc)."
)
Self.sessionTargetNote)
.font(.footnote)
.foregroundStyle(.secondary)
.frame(maxWidth: .infinity, alignment: .leading)
@ -601,8 +612,7 @@ private struct CronJobEditor: View {
Color.clear
.frame(width: self.labelColumnWidth, height: 1)
Text(
"“At” runs once, “Every” repeats with a duration, “Cron” uses a 5-field Unix expression."
)
Self.scheduleKindNote)
.font(.footnote)
.foregroundStyle(.secondary)
.frame(maxWidth: .infinity, alignment: .leading)
@ -646,9 +656,7 @@ private struct CronJobEditor: View {
GroupBox("Payload") {
VStack(alignment: .leading, spacing: 10) {
if self.sessionTarget == .isolated {
Text(
"Isolated jobs always run an agent turn. The result can be delivered to a surface, and a short summary is posted back to your main chat."
)
Text(Self.isolatedPayloadNote)
.font(.footnote)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
@ -669,8 +677,7 @@ private struct CronJobEditor: View {
Color.clear
.frame(width: self.labelColumnWidth, height: 1)
Text(
"System events are injected into the current main session. Agent turns require an isolated session target."
)
Self.mainPayloadNote)
.font(.footnote)
.foregroundStyle(.secondary)
.frame(maxWidth: .infinity, alignment: .leading)
@ -703,8 +710,7 @@ private struct CronJobEditor: View {
Color.clear
.frame(width: self.labelColumnWidth, height: 1)
Text(
"Controls the label used when posting the completion summary back to the main session."
)
Self.mainSummaryNote)
.font(.footnote)
.foregroundStyle(.secondary)
.frame(maxWidth: .infinity, alignment: .leading)

View File

@ -149,8 +149,7 @@ struct DebugSettings: View {
.help(
"When enabled in local mode, the mac app will only connect " +
"to an already-running gateway " +
"and will not start one itself."
)
"and will not start one itself.")
}
GridRow {
self.gridLabel("Deep links")
@ -237,8 +236,7 @@ struct DebugSettings: View {
.toggleStyle(.checkbox)
.help(
"Writes a rotating, local-only diagnostics log under ~/Library/Logs/Clawdis/. " +
"Enable only while actively debugging."
)
"Enable only while actively debugging.")
HStack(spacing: 8) {
Button("Open folder") {
NSWorkspace.shared.open(DiagnosticsFileLog.logDirectoryURL())
@ -490,8 +488,7 @@ struct DebugSettings: View {
.toggleStyle(.checkbox)
.help(
"When off, agent Canvas requests return “Canvas disabled by user”. " +
"Manual debug actions still work."
)
"Manual debug actions still work.")
HStack(spacing: 8) {
TextField("Session", text: self.$canvasSessionKey)
@ -593,8 +590,7 @@ struct DebugSettings: View {
.toggleStyle(.checkbox)
.help(
"When enabled, the menu bar chat window/panel uses the native SwiftUI UI instead of the " +
"bundled WKWebView."
)
"bundled WKWebView.")
}
}
}
@ -757,7 +753,7 @@ struct DebugSettings: View {
.appendingPathComponent(".clawdis")
.appendingPathComponent("clawdis.json")
}
}
}
extension DebugSettings {
// MARK: - Canvas debug actions
@ -854,8 +850,7 @@ extension DebugSettings {
let session = self.canvasSessionKey.trimmingCharacters(in: .whitespacesAndNewlines)
let result = try await CanvasManager.shared.eval(
sessionKey: session.isEmpty ? "main" : session,
javaScript: self.canvasEvalJS
)
javaScript: self.canvasEvalJS)
self.canvasEvalResult = result
} catch {
self.canvasError = error.localizedDescription
@ -870,8 +865,7 @@ extension DebugSettings {
let session = self.canvasSessionKey.trimmingCharacters(in: .whitespacesAndNewlines)
let path = try await CanvasManager.shared.snapshot(
sessionKey: session.isEmpty ? "main" : session,
outPath: nil
)
outPath: nil)
self.canvasSnapshotPath = path
} catch {
self.canvasError = error.localizedDescription
@ -879,7 +873,7 @@ extension DebugSettings {
}
}
private struct PlainSettingsGroupBoxStyle: GroupBoxStyle {
private struct PlainSettingsGroupBoxStyle: GroupBoxStyle {
func makeBody(configuration: Configuration) -> some View {
VStack(alignment: .leading, spacing: 10) {
configuration.label
@ -889,10 +883,10 @@ extension DebugSettings {
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
#if DEBUG
struct DebugSettings_Previews: PreviewProvider {
#if DEBUG
struct DebugSettings_Previews: PreviewProvider {
static var previews: some View {
DebugSettings()
.frame(width: SettingsTab.windowWidth, height: SettingsTab.windowHeight)

View File

@ -1,7 +1,7 @@
import AppKit
import SwiftUI
struct GeneralSettings: View {
struct GeneralSettings: View {
@ObservedObject var state: AppState
@ObservedObject private var healthStore = HealthStore.shared
@ObservedObject private var gatewayManager = GatewayProcessManager.shared

View File

@ -121,8 +121,7 @@ struct OnboardingView: View {
.font(.largeTitle.weight(.semibold))
Text(
"Your macOS menu bar companion for notifications, screenshots, and agent automation — " +
"setup takes just a few minutes."
)
"setup takes just a few minutes.")
.font(.body)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
@ -167,8 +166,7 @@ struct OnboardingView: View {
.font(.largeTitle.weight(.semibold))
Text(
"Clawdis has one primary Gateway (“master”) that runs continuously. " +
"Connect locally or over SSH/Tailscale so the agent can work on any Mac."
)
"Connect locally or over SSH/Tailscale so the agent can work on any Mac.")
.font(.body)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
@ -303,8 +301,7 @@ struct OnboardingView: View {
} else {
Text(
"Uses \"npm install -g clawdis@<version>\" on your PATH. " +
"We keep the gateway on port 18789."
)
"We keep the gateway on port 18789.")
.font(.caption)
.foregroundStyle(.secondary)
.lineLimit(2)

View File

@ -20,17 +20,17 @@ enum PermissionManager {
private static func ensureCapability(_ cap: Capability, interactive: Bool) async -> Bool {
switch cap {
case .notifications:
return await self.ensureNotifications(interactive: interactive)
await self.ensureNotifications(interactive: interactive)
case .appleScript:
return await self.ensureAppleScript(interactive: interactive)
await self.ensureAppleScript(interactive: interactive)
case .accessibility:
return await self.ensureAccessibility(interactive: interactive)
await self.ensureAccessibility(interactive: interactive)
case .screenRecording:
return await self.ensureScreenRecording(interactive: interactive)
await self.ensureScreenRecording(interactive: interactive)
case .microphone:
return await self.ensureMicrophone(interactive: interactive)
await self.ensureMicrophone(interactive: interactive)
case .speechRecognition:
return await self.ensureSpeechRecognition(interactive: interactive)
await self.ensureSpeechRecognition(interactive: interactive)
}
}
@ -45,7 +45,8 @@ enum PermissionManager {
guard interactive else { return false }
let granted = await (try? center.requestAuthorization(options: [.alert, .sound, .badge])) ?? false
let updated = await center.notificationSettings()
return granted && (updated.authorizationStatus == .authorized || updated.authorizationStatus == .provisional)
return granted &&
(updated.authorizationStatus == .authorized || updated.authorizationStatus == .provisional)
case .denied:
if interactive {
NotificationPermissionHelper.openSettings()

View File

@ -451,8 +451,7 @@ struct WebChatView: View {
Text(
self.viewModel.healthOK
? "This is the native SwiftUI debug chat."
: "Connecting to the gateway…"
)
: "Connecting to the gateway…")
.font(.subheadline)
.foregroundStyle(.secondary)
}

View File

@ -105,8 +105,8 @@ enum BrowserCLI {
sub: String,
options: RunOptions,
baseURL: URL,
jsonOutput: Bool
) async throws -> Int32 {
jsonOutput: Bool) async throws -> Int32
{
switch sub {
case "status":
return try await self.handleStatus(baseURL: baseURL, jsonOutput: jsonOutput)
@ -172,8 +172,7 @@ enum BrowserCLI {
method: "POST",
url: url,
body: ["url": urlString],
timeoutInterval: 15.0
)
timeoutInterval: 15.0)
self.printResult(jsonOutput: jsonOutput, res: res)
return 0
}
@ -188,8 +187,7 @@ enum BrowserCLI {
method: "POST",
url: url,
body: ["targetId": id],
timeoutInterval: 5.0
)
timeoutInterval: 5.0)
self.printResult(jsonOutput: jsonOutput, res: res)
return 0
}
@ -250,8 +248,7 @@ enum BrowserCLI {
"targetId": options.targetId ?? "",
"await": options.awaitPromise,
],
timeoutInterval: 15.0
)
timeoutInterval: 15.0)
if jsonOutput {
self.printJSON(ok: true, result: res)

View File

@ -123,8 +123,7 @@ struct ClawdisCLI {
guard let t = title, let b = body else { throw CLIError.help }
return ParsedCLIRequest(
request: .notify(title: t, body: b, sound: sound, priority: priority, delivery: delivery),
kind: .generic
)
kind: .generic)
}
private static func parseEnsurePermissions(args: inout [String]) -> ParsedCLIRequest {
@ -174,10 +173,8 @@ struct ClawdisCLI {
cwd: cwd,
env: env.isEmpty ? nil : env,
timeoutSec: timeout,
needsScreenRecording: needsSR
),
kind: .generic
)
needsScreenRecording: needsSR),
kind: .generic)
}
private static func parseEnvPair(_ pair: String, into env: inout [String: String]) {
@ -212,8 +209,7 @@ struct ClawdisCLI {
guard let message else { throw CLIError.help }
return ParsedCLIRequest(
request: .agent(message: message, thinking: thinking, session: session, deliver: deliver, to: to),
kind: .generic
)
kind: .generic)
}
private static func parseNode(args: inout [String]) throws -> ParsedCLIRequest {
@ -237,8 +233,7 @@ struct ClawdisCLI {
guard let nodeId, let command else { throw CLIError.help }
return ParsedCLIRequest(
request: .nodeInvoke(nodeId: nodeId, command: command, paramsJSON: paramsJSON),
kind: .generic
)
kind: .generic)
default:
throw CLIError.help
}
@ -253,8 +248,7 @@ struct ClawdisCLI {
let placement = self.parseCanvasPlacement(args: &args, session: &session, path: &path)
return ParsedCLIRequest(
request: .canvasShow(session: session, path: path, placement: placement),
kind: .generic
)
kind: .generic)
case "hide":
var session = "main"
while !args.isEmpty {
@ -272,8 +266,7 @@ struct ClawdisCLI {
guard let path else { throw CLIError.help }
return ParsedCLIRequest(
request: .canvasGoto(session: session, path: path, placement: placement),
kind: .generic
)
kind: .generic)
case "eval":
var session = "main"
var js: String?
@ -307,8 +300,8 @@ struct ClawdisCLI {
private static func parseCanvasPlacement(
args: inout [String],
session: inout String,
path: inout String?
) -> CanvasPlacement? {
path: inout String?) -> CanvasPlacement?
{
var x: Double?
var y: Double?
var width: Double?