style: polish logging and lint hints

This commit is contained in:
Peter Steinberger
2025-12-20 01:48:22 +01:00
parent b2e11c504b
commit d67bec0740
13 changed files with 73 additions and 23 deletions

View File

@@ -113,7 +113,7 @@ final class NodeAppModel {
contextJSON: contextJSON) contextJSON: contextJSON)
let ok: Bool let ok: Bool
var errorText: String? = nil var errorText: String?
if await !self.isBridgeConnected() { if await !self.isBridgeConnected() {
ok = false ok = false
errorText = "bridge not connected" errorText = "bridge not connected"
@@ -362,6 +362,7 @@ final class NodeAppModel {
return false return false
} }
// swiftlint:disable:next function_body_length cyclomatic_complexity
private func handleInvoke(_ req: BridgeInvokeRequest) async -> BridgeInvokeResponse { private func handleInvoke(_ req: BridgeInvokeRequest) async -> BridgeInvokeResponse {
let command = req.command let command = req.command

View File

@@ -33,7 +33,11 @@ final class CanvasManager {
placement: CanvasPlacement? = nil) throws -> CanvasShowResult placement: CanvasPlacement? = nil) throws -> CanvasShowResult
{ {
Self.logger.debug( Self.logger.debug(
"showDetailed start session=\(sessionKey, privacy: .public) target=\(target ?? "", privacy: .public) placement=\(placement != nil)") """
showDetailed start session=\(sessionKey, privacy: .public) \
target=\(target ?? "", privacy: .public) \
placement=\(placement != nil)
""")
let anchorProvider = self.defaultAnchorProvider ?? Self.mouseAnchorProvider let anchorProvider = self.defaultAnchorProvider ?? Self.mouseAnchorProvider
let session = sessionKey.trimmingCharacters(in: .whitespacesAndNewlines) let session = sessionKey.trimmingCharacters(in: .whitespacesAndNewlines)
let normalizedTarget = target? let normalizedTarget = target?

View File

@@ -685,7 +685,10 @@ private final class CanvasA2UIActionMessageHandler: NSObject, WKScriptMessageHan
} }
if !result.ok { if !result.ok {
canvasWindowLogger.error( canvasWindowLogger.error(
"A2UI action send failed name=\(name, privacy: .public) error=\(result.error ?? "unknown", privacy: .public)") """
A2UI action send failed name=\(name, privacy: .public) \
error=\(result.error ?? "unknown", privacy: .public)
""")
} }
} }
} }

View File

@@ -433,7 +433,7 @@ enum ControlRequestHandler {
logger: Logger) async -> Response logger: Logger) async -> Response
{ {
do { do {
var paramsObj: Any? = nil var paramsObj: Any?
let raw = (paramsJSON ?? "").trimmingCharacters(in: .whitespacesAndNewlines) let raw = (paramsJSON ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
if !raw.isEmpty { if !raw.isEmpty {
if let data = raw.data(using: .utf8) { if let data = raw.data(using: .utf8) {

View File

@@ -100,12 +100,15 @@ enum GatewayEnvironment {
if let bundled = self.bundledGatewayExecutable() { if let bundled = self.bundledGatewayExecutable() {
let installed = self.readGatewayVersion(binary: bundled) let installed = self.readGatewayVersion(binary: bundled)
if let expected, let installed, !installed.compatible(with: expected) { if let expected, let installed, !installed.compatible(with: expected) {
let message =
"Bundled gateway \(installed.description) is incompatible with app " +
"\(expected.description); rebuild the app bundle."
return GatewayEnvironmentStatus( return GatewayEnvironmentStatus(
kind: .incompatible(found: installed.description, required: expected.description), kind: .incompatible(found: installed.description, required: expected.description),
nodeVersion: nil, nodeVersion: nil,
gatewayVersion: installed.description, gatewayVersion: installed.description,
requiredGateway: expected.description, requiredGateway: expected.description,
message: "Bundled gateway \(installed.description) is incompatible with app \(expected.description); rebuild the app bundle.") message: message)
} }
let gatewayVersionText = installed?.description ?? "unknown" let gatewayVersionText = installed?.description ?? "unknown"
return GatewayEnvironmentStatus( return GatewayEnvironmentStatus(
@@ -258,18 +261,29 @@ enum GatewayEnvironment {
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000) let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
if elapsedMs > 500 { if elapsedMs > 500 {
self.logger.warning( self.logger.warning(
"gateway --version slow (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public)") """
gateway --version slow (\(elapsedMs, privacy: .public)ms) \
bin=\(binary, privacy: .public)
""")
} else { } else {
self.logger.debug( self.logger.debug(
"gateway --version ok (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public)") """
gateway --version ok (\(elapsedMs, privacy: .public)ms) \
bin=\(binary, privacy: .public)
""")
} }
let data = pipe.fileHandleForReading.readToEndSafely() let data = pipe.fileHandleForReading.readToEndSafely()
let raw = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) let raw = String(data: data, encoding: .utf8)?
.trimmingCharacters(in: .whitespacesAndNewlines)
return Semver.parse(raw) return Semver.parse(raw)
} catch { } catch {
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000) let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
self.logger.error( self.logger.error(
"gateway --version failed (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public) err=\(error.localizedDescription, privacy: .public)") """
gateway --version failed (\(elapsedMs, privacy: .public)ms) \
bin=\(binary, privacy: .public) \
err=\(error.localizedDescription, privacy: .public)
""")
return nil return nil
} }
} }

View File

@@ -94,7 +94,12 @@ final class GatewayProcessManager {
self.lastFailureReason = nil self.lastFailureReason = nil
self.status = .stopped self.status = .stopped
let bundlePath = Bundle.main.bundleURL.path let bundlePath = Bundle.main.bundleURL.path
Task { _ = await GatewayLaunchAgentManager.set(enabled: false, bundlePath: bundlePath, port: GatewayEnvironment.gatewayPort()) } Task {
_ = await GatewayLaunchAgentManager.set(
enabled: false,
bundlePath: bundlePath,
port: GatewayEnvironment.gatewayPort())
}
} }
func refreshEnvironmentStatus(force: Bool = false) { func refreshEnvironmentStatus(force: Bool = false) {

View File

@@ -7,7 +7,6 @@ struct GeneralSettings: View {
@AppStorage(cameraEnabledKey) private var cameraEnabled: Bool = false @AppStorage(cameraEnabledKey) private var cameraEnabled: Bool = false
private let healthStore = HealthStore.shared private let healthStore = HealthStore.shared
private let gatewayManager = GatewayProcessManager.shared private let gatewayManager = GatewayProcessManager.shared
// swiftlint:disable:next inclusive_language
@State private var gatewayDiscovery = GatewayDiscoveryModel() @State private var gatewayDiscovery = GatewayDiscoveryModel()
@State private var isInstallingCLI = false @State private var isInstallingCLI = false
@State private var cliStatus: String? @State private var cliStatus: String?
@@ -598,7 +597,6 @@ extension GeneralSettings {
alert.runModal() alert.runModal()
} }
// swiftlint:disable:next inclusive_language
private func applyDiscoveredGateway(_ gateway: GatewayDiscoveryModel.DiscoveredGateway) { private func applyDiscoveredGateway(_ gateway: GatewayDiscoveryModel.DiscoveredGateway) {
MacNodeModeCoordinator.shared.setPreferredBridgeStableID(gateway.stableID) MacNodeModeCoordinator.shared.setPreferredBridgeStableID(gateway.stableID)

View File

@@ -35,7 +35,7 @@ final class MacNodeModeCoordinator {
private func run() async { private func run() async {
var retryDelay: UInt64 = 1_000_000_000 var retryDelay: UInt64 = 1_000_000_000
var lastCameraEnabled: Bool? = nil var lastCameraEnabled: Bool?
let defaults = UserDefaults.standard let defaults = UserDefaults.standard
while !Task.isCancelled { while !Task.isCancelled {
if await MainActor.run(body: { AppStateStore.shared.isPaused }) { if await MainActor.run(body: { AppStateStore.shared.isPaused }) {

View File

@@ -7,6 +7,7 @@ actor MacNodeRuntime {
private let cameraCapture = CameraCaptureService() private let cameraCapture = CameraCaptureService()
@MainActor private let screenRecorder = ScreenRecordService() @MainActor private let screenRecorder = ScreenRecordService()
// swiftlint:disable:next function_body_length
func handleInvoke(_ req: BridgeInvokeRequest) async -> BridgeInvokeResponse { func handleInvoke(_ req: BridgeInvokeRequest) async -> BridgeInvokeResponse {
let command = req.command let command = req.command
if command.hasPrefix("canvas.") || command.hasPrefix("canvas.a2ui."), !Self.canvasEnabled() { if command.hasPrefix("canvas.") || command.hasPrefix("canvas.a2ui."), !Self.canvasEnabled() {

View File

@@ -189,13 +189,20 @@ final class NodePairingApprovalPrompter {
if self.activeRequestId == req.requestId, self.activeAlert != nil { if self.activeRequestId == req.requestId, self.activeAlert != nil {
self.remoteResolutionsByRequestId[req.requestId] = resolution self.remoteResolutionsByRequestId[req.requestId] = resolution
self.logger.info( self.logger.info(
"pairing request resolved elsewhere; closing dialog requestId=\(req.requestId, privacy: .public) resolution=\(resolution.rawValue, privacy: .public)") """
pairing request resolved elsewhere; closing dialog \
requestId=\(req.requestId, privacy: .public) \
resolution=\(resolution.rawValue, privacy: .public)
""")
self.endActiveAlert() self.endActiveAlert()
continue continue
} }
self.logger.info( self.logger.info(
"pairing request resolved elsewhere requestId=\(req.requestId, privacy: .public) resolution=\(resolution.rawValue, privacy: .public)") """
pairing request resolved elsewhere requestId=\(req.requestId, privacy: .public) \
resolution=\(resolution.rawValue, privacy: .public)
""")
self.queue.removeAll { $0 == req } self.queue.removeAll { $0 == req }
Task { @MainActor in Task { @MainActor in
await self.notify(resolution: resolution, request: req, via: "remote") await self.notify(resolution: resolution, request: req, via: "remote")
@@ -623,7 +630,11 @@ final class NodePairingApprovalPrompter {
if self.activeRequestId == resolved.requestId, self.activeAlert != nil { if self.activeRequestId == resolved.requestId, self.activeAlert != nil {
self.remoteResolutionsByRequestId[resolved.requestId] = resolution self.remoteResolutionsByRequestId[resolved.requestId] = resolution
self.logger.info( self.logger.info(
"pairing request resolved elsewhere; closing dialog requestId=\(resolved.requestId, privacy: .public) resolution=\(resolution.rawValue, privacy: .public)") """
pairing request resolved elsewhere; closing dialog \
requestId=\(resolved.requestId, privacy: .public) \
resolution=\(resolution.rawValue, privacy: .public)
""")
self.endActiveAlert() self.endActiveAlert()
return return
} }

View File

@@ -77,7 +77,6 @@ struct OnboardingView: View {
@State private var gatewayInstallMessage: String? @State private var gatewayInstallMessage: String?
@State private var showAdvancedConnection = false @State private var showAdvancedConnection = false
@State private var preferredGatewayID: String? @State private var preferredGatewayID: String?
// swiftlint:disable:next inclusive_language
@State private var gatewayDiscovery: GatewayDiscoveryModel @State private var gatewayDiscovery: GatewayDiscoveryModel
@Bindable private var state: AppState @Bindable private var state: AppState
private var permissionMonitor: PermissionMonitor private var permissionMonitor: PermissionMonitor
@@ -489,8 +488,8 @@ struct OnboardingView: View {
} }
Text( Text(
"This lets Pi use Claude immediately. Credentials are stored at `~/.pi/agent/oauth.json` (owner-only). " + "This lets Pi use Claude immediately. Credentials are stored at " +
"You can redo this anytime.") "`~/.pi/agent/oauth.json` (owner-only). You can redo this anytime.")
.font(.subheadline) .font(.subheadline)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true) .fixedSize(horizontal: false, vertical: true)
@@ -993,7 +992,8 @@ struct OnboardingView: View {
} else { } else {
Text( Text(
"Tip: edit AGENTS.md in this folder to shape the assistants behavior. " + "Tip: edit AGENTS.md in this folder to shape the assistants behavior. " +
"For backup, make the workspace a private git repo so your agents “memory” is versioned.") "For backup, make the workspace a private git repo so your agents " +
"“memory” is versioned.")
.font(.caption) .font(.caption)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
.lineLimit(2) .lineLimit(2)

View File

@@ -138,17 +138,27 @@ enum RuntimeLocator {
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000) let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
if elapsedMs > 500 { if elapsedMs > 500 {
self.logger.warning( self.logger.warning(
"runtime --version slow (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public)") """
runtime --version slow (\(elapsedMs, privacy: .public)ms) \
bin=\(binary, privacy: .public)
""")
} else { } else {
self.logger.debug( self.logger.debug(
"runtime --version ok (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public)") """
runtime --version ok (\(elapsedMs, privacy: .public)ms) \
bin=\(binary, privacy: .public)
""")
} }
let data = pipe.fileHandleForReading.readToEndSafely() let data = pipe.fileHandleForReading.readToEndSafely()
return String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) return String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
} catch { } catch {
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000) let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
self.logger.error( self.logger.error(
"runtime --version failed (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public) err=\(error.localizedDescription, privacy: .public)") """
runtime --version failed (\(elapsedMs, privacy: .public)ms) \
bin=\(binary, privacy: .public) \
err=\(error.localizedDescription, privacy: .public)
""")
return nil return nil
} }
} }

View File

@@ -2,6 +2,7 @@ import ClawdisIPC
import Darwin import Darwin
import Foundation import Foundation
// swiftlint:disable type_body_length
@main @main
struct ClawdisCLI { struct ClawdisCLI {
static func main() async { static func main() async {
@@ -535,6 +536,7 @@ struct ClawdisCLI {
return CanvasPlacement(x: x, y: y, width: width, height: height) return CanvasPlacement(x: x, y: y, width: width, height: height)
} }
// swiftlint:disable:next cyclomatic_complexity
private static func printText(parsed: ParsedCLIRequest, response: Response) throws { private static func printText(parsed: ParsedCLIRequest, response: Response) throws {
guard response.ok else { guard response.ok else {
let msg = response.message ?? "failed" let msg = response.message ?? "failed"
@@ -1056,6 +1058,7 @@ struct ClawdisCLI {
try? await Task.sleep(nanoseconds: 100_000_000) try? await Task.sleep(nanoseconds: 100_000_000)
} }
} }
// swiftlint:enable type_body_length
enum CLIError: Error { case help, version } enum CLIError: Error { case help, version }