Open source CapCut alternative.
TypeScript
refactor(app): reduce dev-overlay config to a single enabled flag
David Lefabe94d15318
diff --git a/apps/Donkey/Sources/Donkey/DonkeyAppDelegate.swift b/apps/Donkey/Sources/Donkey/DonkeyAppDelegate.swiftindex cb79dfb4..c8e77796 100644--- a/apps/Donkey/Sources/Donkey/DonkeyAppDelegate.swift+++ b/apps/Donkey/Sources/Donkey/DonkeyAppDelegate.swift@@ -132,7 +132,7 @@ final class DonkeyAppDelegate: NSObject, NSApplicationDelegate {#elselet uiUnderstandingCoordinator = UIUnderstandingCoordinator(rendersOverlay: false,- defaultConfiguration: DebugUIOverlayConfiguration(enabled: true, activeWindowOnly: true)+ defaultConfiguration: DebugUIOverlayConfiguration(enabled: true))#endifself.uiUnderstandingCoordinator = uiUnderstandingCoordinatordiff --git a/apps/Donkey/Sources/Donkey/LocalUIElementDetection/UIUnderstandingCoordinator.swift b/apps/Donkey/Sources/Donkey/LocalUIElementDetection/UIUnderstandingCoordinator.swiftindex 728d49a1..f52f8e56 100644--- a/apps/Donkey/Sources/Donkey/LocalUIElementDetection/UIUnderstandingCoordinator.swift+++ b/apps/Donkey/Sources/Donkey/LocalUIElementDetection/UIUnderstandingCoordinator.swift@@ -168,28 +168,21 @@ final class UIUnderstandingCoordinator {}private func reloadConfigAndReschedule(force: Bool = false) {- // The dev-overlay config file turns the visible overlay on and tunes it. When it does not+ // The dev-overlay config file only flips the visible overlay on or off. When it does not// enable the engine, fall back to `defaultConfiguration` — production passes an enabled// configuration there so AX + AI parsing runs even though nothing is rendered.let loaded = DebugUIOverlayConfiguration.load(fileURL: configURL)let newConfig = loaded.enabled ? loaded : defaultConfiguration- let cadenceChanged = newConfig.cadenceSeconds != currentConfig.cadenceSecondslet enablementChanged = newConfig.enabled != currentConfig.enabled- let scopeChanged = newConfig.screenScope != currentConfig.screenScope- let modeChanged = newConfig.mode != currentConfig.mode- let confidenceChanged = newConfig.minConfidence != currentConfig.minConfidence- let activeWindowChanged = newConfig.activeWindowOnly != currentConfig.activeWindowOnly- let targetFilterChanged = newConfig.targetBundleIdentifiers != currentConfig.targetBundleIdentifiers- || newConfig.targetAppNames != currentConfig.targetAppNamescurrentConfig = newConfig- if force || enablementChanged || scopeChanged || modeChanged || confidenceChanged || activeWindowChanged || targetFilterChanged {+ if force || enablementChanged {UIUnderstandingLog.overlay.info(- "debug inspection config enabled=\(String(newConfig.enabled), privacy: .public) mode=\(newConfig.mode, privacy: .public) cadence=\(newConfig.cadenceSeconds, privacy: .public) scope=\(newConfig.screenScope.rawValue, privacy: .public) minConfidence=\(newConfig.minConfidence, privacy: .public) activeWindowOnly=\(String(newConfig.activeWindowOnly), privacy: .public) targetBundles=\(newConfig.targetBundleIdentifiers.joined(separator: ","), privacy: .public) targetApps=\(newConfig.targetAppNames.joined(separator: ","), privacy: .public)"+ "debug inspection config enabled=\(String(newConfig.enabled), privacy: .public)")}- if cadenceChanged || timer == nil || force {+ if timer == nil || force {timer?.invalidate()let newTimer = Timer(timeInterval: newConfig.cadenceSeconds, repeats: true) { [weak self] _ inTask { @MainActor in@@ -219,7 +212,7 @@ final class UIUnderstandingCoordinator {activeAccessibilityTimer = nil}- if enablementChanged || scopeChanged || modeChanged || confidenceChanged || activeWindowChanged || targetFilterChanged {+ if enablementChanged {lastFingerprints.removeAll()trackers.removeAll()lastRenderedFrames.removeAll()diff --git a/apps/Donkey/Sources/DonkeyRuntime/LocalUIElementDetection/DebugUIInspectionRuntime.swift b/apps/Donkey/Sources/DonkeyRuntime/LocalUIElementDetection/DebugUIInspectionRuntime.swiftindex eaecd872..b3b9008a 100644--- a/apps/Donkey/Sources/DonkeyRuntime/LocalUIElementDetection/DebugUIInspectionRuntime.swift+++ b/apps/Donkey/Sources/DonkeyRuntime/LocalUIElementDetection/DebugUIInspectionRuntime.swift@@ -7,33 +7,20 @@ import ImageIOimport UniformTypeIdentifierspublic struct DebugUIOverlayConfiguration: Equatable, Sendable {+ /// The only knob the dev-overlay JSON file controls: flip the debug overlay on or off.+ /// Everything else below is a fixed, sensible default — the old tuning fields were never used.public var enabled: Bool- public var mode: String- public var cadenceSeconds: TimeInterval- public var screenScope: DebugUIInspectionScreenScope- public var minConfidence: Double- public var activeWindowOnly: Bool- public var targetBundleIdentifiers: [String]- public var targetAppNames: [String]- public init(- enabled: Bool = false,- mode: String = "donkeyVision",- cadenceSeconds: TimeInterval = 1.0,- screenScope: DebugUIInspectionScreenScope = .main,- minConfidence: Double = 0.25,- activeWindowOnly: Bool = false,- targetBundleIdentifiers: [String] = [],- targetAppNames: [String] = []- ) {+ public var mode: String { "donkeyVision" }+ public var cadenceSeconds: TimeInterval { 1.0 }+ public var screenScope: DebugUIInspectionScreenScope { .main }+ public var minConfidence: Double { 0.25 }+ public var activeWindowOnly: Bool { true }+ public var targetBundleIdentifiers: [String] { [] }+ public var targetAppNames: [String] { [] }++ public init(enabled: Bool = false) {self.enabled = enabled- self.mode = mode.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? "donkeyVision" : mode- self.cadenceSeconds = min(max(cadenceSeconds, 0.25), 10.0)- self.screenScope = screenScope- self.minConfidence = min(max(minConfidence, 0), 1)- self.activeWindowOnly = activeWindowOnly- self.targetBundleIdentifiers = Self.normalizedList(targetBundleIdentifiers)- self.targetAppNames = Self.normalizedList(targetAppNames)}public static let disabled = DebugUIOverlayConfiguration(enabled: false)@@ -64,39 +51,17 @@ public struct DebugUIOverlayConfiguration: Equatable, Sendable {urls = candidateConfigURLs(fileManager: fileManager)}- guard let raw = urls.lazy.compactMap({ url -> RawDebugUIOverlayConfiguration? in+ let enabled = urls.lazy.compactMap { url -> Bool? inguard fileManager.fileExists(atPath: url.path),- let data = try? Data(contentsOf: url)+ let data = try? Data(contentsOf: url),+ let raw = try? JSONDecoder().decode(RawDebugUIOverlayConfiguration.self, from: data)else {return nil}- return try? JSONDecoder().decode(RawDebugUIOverlayConfiguration.self, from: data)- }).first else {- return .disabled- }-- let mode = raw.mode?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""- return DebugUIOverlayConfiguration(- enabled: raw.enabled ?? false,- mode: mode.isEmpty ? "donkeyVision" : mode,- cadenceSeconds: raw.cadenceSeconds ?? 1.0,- screenScope: raw.screenScope.flatMap(DebugUIInspectionScreenScope.init(rawValue:)) ?? .main,- minConfidence: raw.minConfidence ?? 0.25,- activeWindowOnly: raw.activeWindowOnly ?? false,- targetBundleIdentifiers: raw.targetBundleIdentifiers ?? [],- targetAppNames: raw.targetAppNames ?? []- )- }+ return raw.enabled ?? false+ }.first ?? false- private static func normalizedList(_ values: [String]) -> [String] {- var seen = Set<String>()- return values.compactMap { value in- let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)- guard !trimmed.isEmpty else { return nil }- let key = trimmed.lowercased()- guard seen.insert(key).inserted else { return nil }- return trimmed- }+ return DebugUIOverlayConfiguration(enabled: enabled)}public static func candidateConfigURLs(@@ -153,13 +118,6 @@ public struct DebugUIOverlayConfiguration: Equatable, Sendable {private struct RawDebugUIOverlayConfiguration: Codable {var enabled: Bool?- var mode: String?- var cadenceSeconds: TimeInterval?- var screenScope: String?- var minConfidence: Double?- var activeWindowOnly: Bool?- var targetBundleIdentifiers: [String]?- var targetAppNames: [String]?}public struct DebugUIElementTracker: Equatable, Sendable {diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/DebugUIInspectionTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/DebugUIInspectionTests.swiftindex 5e151757..c01e4d09 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/DebugUIInspectionTests.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/DebugUIInspectionTests.swift@@ -32,7 +32,7 @@ struct DebugUIInspectionTests {}@Test- func enabledConfigUsesSafeDefaults() throws {+ func enabledConfigUsesFixedDefaults() throws {let url = temporaryDirectory().appendingPathComponent("enabled-dev-overlay.json", isDirectory: false)try Data(#"{"enabled":true}"#.utf8).write(to: url, options: .atomic)@@ -45,45 +45,26 @@ struct DebugUIInspectionTests {#expect(config.cadenceSeconds == 1.0)#expect(config.screenScope == .main)#expect(config.minConfidence == 0.25)- #expect(config.activeWindowOnly == false)+ #expect(config.activeWindowOnly == true)#expect(config.targetBundleIdentifiers.isEmpty)#expect(config.targetAppNames.isEmpty)}@Test- func configLoadsTargetFilters() throws {- let url = temporaryDirectory()- .appendingPathComponent("targeted-dev-overlay.json", isDirectory: false)- try Data(- """- {- "enabled": true,- "activeWindowOnly": true,- "targetBundleIdentifiers": ["com.apple.Music", " com.apple.Music "],- "targetAppNames": ["Music"]- }- """.utf8- ).write(to: url, options: .atomic)- defer { try? FileManager.default.removeItem(at: url) }-- let config = DebugUIOverlayConfiguration.load(fileURL: url)-- #expect(config.targetBundleIdentifiers == ["com.apple.Music"])- #expect(config.targetAppNames == ["Music"])- #expect(config.activeWindowOnly == true)- }-- @Test- func disabledRepoStyleConfigKeepsOverlayOff() throws {+ func configIgnoresEverythingExceptEnabled() throws {+ // `enabled` is the only knob the file controls; any other tuning fields are ignored and the+ // fixed defaults stand.let url = temporaryDirectory()- .appendingPathComponent("disabled-dev-overlay.json", isDirectory: false)+ .appendingPathComponent("noisy-dev-overlay.json", isDirectory: false)try Data("""{"enabled": false,"cadenceSeconds": 0.05,"screenScope": "all",- "minConfidence": 2+ "minConfidence": 2,+ "activeWindowOnly": false,+ "targetAppNames": ["Music"]}""".utf8).write(to: url, options: .atomic)@@ -92,10 +73,11 @@ struct DebugUIInspectionTests {let config = DebugUIOverlayConfiguration.load(fileURL: url)#expect(config.enabled == false)- #expect(config.mode == "donkeyVision")- #expect(config.cadenceSeconds == 0.25)- #expect(config.screenScope == .all)- #expect(config.minConfidence == 1)+ #expect(config.cadenceSeconds == 1.0)+ #expect(config.screenScope == .main)+ #expect(config.minConfidence == 0.25)+ #expect(config.activeWindowOnly == true)+ #expect(config.targetAppNames.isEmpty)}@Testdiff --git a/apps/Donkey/dev-overlay.json b/apps/Donkey/dev-overlay.jsonindex fd29248d..010732bf 100644--- a/apps/Donkey/dev-overlay.json+++ b/apps/Donkey/dev-overlay.json@@ -1,8 +1,3 @@{- "enabled": false,- "mode": "donkeyVision",- "cadenceSeconds": 1.0,- "screenScope": "main",- "minConfidence": 0.25,- "activeWindowOnly": true+ "enabled": false}diff --git a/docs/guides/donkey-vision.md b/docs/guides/donkey-vision.mdindex 6d4bdba2..95b53136 100644--- a/docs/guides/donkey-vision.md+++ b/docs/guides/donkey-vision.md@@ -87,19 +87,14 @@ The overlay is enabled through `dev-overlay.json` (see```json{- "enabled": true,- "mode": "donkeyVision",- "cadenceSeconds": 1.0,- "screenScope": "main",- "minConfidence": 0.25,- "activeWindowOnly": true+ "enabled": true}```-Optional `targetBundleIdentifiers` / `targetAppNames` fields narrow the-overlay to specific apps. Do not add a provider field to this config. Donkey-Vision is always local evidence plus hosted AI enrichment; the config controls-cadence, scope, and filters, not which evidence source runs.+`enabled` is the only knob: it flips the visible overlay on or off. Cadence,+scope, confidence, and app filters are fixed sensible defaults in code, not+config. Do not add a provider field either — Donkey Vision is always local+evidence plus hosted AI enrichment.## Source Map