style: polish logging and lint hints
This commit is contained in:
@@ -113,7 +113,7 @@ final class NodeAppModel {
|
||||
contextJSON: contextJSON)
|
||||
|
||||
let ok: Bool
|
||||
var errorText: String? = nil
|
||||
var errorText: String?
|
||||
if await !self.isBridgeConnected() {
|
||||
ok = false
|
||||
errorText = "bridge not connected"
|
||||
@@ -362,6 +362,7 @@ final class NodeAppModel {
|
||||
return false
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length cyclomatic_complexity
|
||||
private func handleInvoke(_ req: BridgeInvokeRequest) async -> BridgeInvokeResponse {
|
||||
let command = req.command
|
||||
|
||||
|
||||
@@ -33,7 +33,11 @@ final class CanvasManager {
|
||||
placement: CanvasPlacement? = nil) throws -> CanvasShowResult
|
||||
{
|
||||
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 session = sessionKey.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let normalizedTarget = target?
|
||||
|
||||
@@ -685,7 +685,10 @@ private final class CanvasA2UIActionMessageHandler: NSObject, WKScriptMessageHan
|
||||
}
|
||||
if !result.ok {
|
||||
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)
|
||||
""")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ enum ControlRequestHandler {
|
||||
logger: Logger) async -> Response
|
||||
{
|
||||
do {
|
||||
var paramsObj: Any? = nil
|
||||
var paramsObj: Any?
|
||||
let raw = (paramsJSON ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if !raw.isEmpty {
|
||||
if let data = raw.data(using: .utf8) {
|
||||
|
||||
@@ -100,12 +100,15 @@ enum GatewayEnvironment {
|
||||
if let bundled = self.bundledGatewayExecutable() {
|
||||
let installed = self.readGatewayVersion(binary: bundled)
|
||||
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(
|
||||
kind: .incompatible(found: installed.description, required: expected.description),
|
||||
nodeVersion: nil,
|
||||
gatewayVersion: installed.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"
|
||||
return GatewayEnvironmentStatus(
|
||||
@@ -258,18 +261,29 @@ enum GatewayEnvironment {
|
||||
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||
if elapsedMs > 500 {
|
||||
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 {
|
||||
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 raw = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let raw = String(data: data, encoding: .utf8)?
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return Semver.parse(raw)
|
||||
} catch {
|
||||
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,12 @@ final class GatewayProcessManager {
|
||||
self.lastFailureReason = nil
|
||||
self.status = .stopped
|
||||
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) {
|
||||
|
||||
@@ -7,7 +7,6 @@ struct GeneralSettings: View {
|
||||
@AppStorage(cameraEnabledKey) private var cameraEnabled: Bool = false
|
||||
private let healthStore = HealthStore.shared
|
||||
private let gatewayManager = GatewayProcessManager.shared
|
||||
// swiftlint:disable:next inclusive_language
|
||||
@State private var gatewayDiscovery = GatewayDiscoveryModel()
|
||||
@State private var isInstallingCLI = false
|
||||
@State private var cliStatus: String?
|
||||
@@ -598,7 +597,6 @@ extension GeneralSettings {
|
||||
alert.runModal()
|
||||
}
|
||||
|
||||
// swiftlint:disable:next inclusive_language
|
||||
private func applyDiscoveredGateway(_ gateway: GatewayDiscoveryModel.DiscoveredGateway) {
|
||||
MacNodeModeCoordinator.shared.setPreferredBridgeStableID(gateway.stableID)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ final class MacNodeModeCoordinator {
|
||||
|
||||
private func run() async {
|
||||
var retryDelay: UInt64 = 1_000_000_000
|
||||
var lastCameraEnabled: Bool? = nil
|
||||
var lastCameraEnabled: Bool?
|
||||
let defaults = UserDefaults.standard
|
||||
while !Task.isCancelled {
|
||||
if await MainActor.run(body: { AppStateStore.shared.isPaused }) {
|
||||
|
||||
@@ -7,6 +7,7 @@ actor MacNodeRuntime {
|
||||
private let cameraCapture = CameraCaptureService()
|
||||
@MainActor private let screenRecorder = ScreenRecordService()
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func handleInvoke(_ req: BridgeInvokeRequest) async -> BridgeInvokeResponse {
|
||||
let command = req.command
|
||||
if command.hasPrefix("canvas.") || command.hasPrefix("canvas.a2ui."), !Self.canvasEnabled() {
|
||||
|
||||
@@ -189,13 +189,20 @@ final class NodePairingApprovalPrompter {
|
||||
if self.activeRequestId == req.requestId, self.activeAlert != nil {
|
||||
self.remoteResolutionsByRequestId[req.requestId] = resolution
|
||||
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()
|
||||
continue
|
||||
}
|
||||
|
||||
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 }
|
||||
Task { @MainActor in
|
||||
await self.notify(resolution: resolution, request: req, via: "remote")
|
||||
@@ -623,7 +630,11 @@ final class NodePairingApprovalPrompter {
|
||||
if self.activeRequestId == resolved.requestId, self.activeAlert != nil {
|
||||
self.remoteResolutionsByRequestId[resolved.requestId] = resolution
|
||||
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()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ struct OnboardingView: View {
|
||||
@State private var gatewayInstallMessage: String?
|
||||
@State private var showAdvancedConnection = false
|
||||
@State private var preferredGatewayID: String?
|
||||
// swiftlint:disable:next inclusive_language
|
||||
@State private var gatewayDiscovery: GatewayDiscoveryModel
|
||||
@Bindable private var state: AppState
|
||||
private var permissionMonitor: PermissionMonitor
|
||||
@@ -489,8 +488,8 @@ struct OnboardingView: View {
|
||||
}
|
||||
|
||||
Text(
|
||||
"This lets Pi use Claude immediately. Credentials are stored at `~/.pi/agent/oauth.json` (owner-only). " +
|
||||
"You can redo this anytime.")
|
||||
"This lets Pi use Claude immediately. Credentials are stored at " +
|
||||
"`~/.pi/agent/oauth.json` (owner-only). You can redo this anytime.")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
@@ -993,7 +992,8 @@ struct OnboardingView: View {
|
||||
} else {
|
||||
Text(
|
||||
"Tip: edit AGENTS.md in this folder to shape the assistant’s behavior. " +
|
||||
"For backup, make the workspace a private git repo so your agent’s “memory” is versioned.")
|
||||
"For backup, make the workspace a private git repo so your agent’s " +
|
||||
"“memory” is versioned.")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(2)
|
||||
|
||||
@@ -138,17 +138,27 @@ enum RuntimeLocator {
|
||||
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||
if elapsedMs > 500 {
|
||||
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 {
|
||||
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()
|
||||
return String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
} catch {
|
||||
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import ClawdisIPC
|
||||
import Darwin
|
||||
import Foundation
|
||||
|
||||
// swiftlint:disable type_body_length
|
||||
@main
|
||||
struct ClawdisCLI {
|
||||
static func main() async {
|
||||
@@ -535,6 +536,7 @@ struct ClawdisCLI {
|
||||
return CanvasPlacement(x: x, y: y, width: width, height: height)
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
private static func printText(parsed: ParsedCLIRequest, response: Response) throws {
|
||||
guard response.ok else {
|
||||
let msg = response.message ?? "failed"
|
||||
@@ -1056,6 +1058,7 @@ struct ClawdisCLI {
|
||||
try? await Task.sleep(nanoseconds: 100_000_000)
|
||||
}
|
||||
}
|
||||
// swiftlint:enable type_body_length
|
||||
|
||||
enum CLIError: Error { case help, version }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user