Open source CapCut alternative.
TypeScript
refactor(app): remove orphaned intent/action-plan contracts
David Leaba1d4f3654d
diff --git a/apps/Donkey/Sources/DonkeyContracts/TaskIntentContracts.swift b/apps/Donkey/Sources/DonkeyContracts/TaskIntentContracts.swiftindex e832f6d3..759576ad 100644--- a/apps/Donkey/Sources/DonkeyContracts/TaskIntentContracts.swift+++ b/apps/Donkey/Sources/DonkeyContracts/TaskIntentContracts.swift@@ -1,10 +1,5 @@import Foundation-public enum TaskIntentParserSource: String, Codable, Equatable, Sendable {- case localModel = "local_model"- case onlineModel = "online_model"-}-public struct LocalAppTarget: Codable, Equatable, Sendable {public var appName: Stringpublic var bundleIdentifier: String?@@ -81,146 +76,6 @@ public struct LocalAppFinderCatalogEntry: Codable, Equatable, Sendable {}}-public enum LocalAppActionPlanTool: String, Codable, CaseIterable, Equatable, Sendable {- case openOrFocusApp = "app.openOrFocus"- case observeApp = "app.observe"- case newDocument = "ui.newDocument"- case focusSearch = "ui.focusSearch"- case focusAddressBar = "ui.focusAddressBar"- case focusTextEntry = "ui.focusTextEntry"- case setText = "ui.setText"- case clickTarget = "ui.clickTarget"- case pressReturn = "ui.pressReturn"- case verifyCommand = "app.verifyCommand"- case verifyVisibleText = "app.verifyVisibleText"-}--public struct LocalAppActionPlan: Codable, Equatable, Sendable {- public var tools: [LocalAppActionPlanTool]- public var inputEntity: String- public var controlID: String- public var focusKey: String- public var verificationTools: [LocalAppActionPlanTool]-- public init(- tools: [LocalAppActionPlanTool],- inputEntity: String = "query",- controlID: String = "search",- focusKey: String = "Command+F",- verificationTools: [LocalAppActionPlanTool] = [.verifyCommand]- ) {- self.tools = tools- self.inputEntity = inputEntity- self.controlID = controlID- self.focusKey = focusKey- let normalizedVerificationTools = verificationTools.filter(Self.isVerificationTool)- self.verificationTools = normalizedVerificationTools.isEmpty- ? tools.filter(Self.isVerificationTool)- : normalizedVerificationTools- }-- public static var defaultSearchSubmitPlan: LocalAppActionPlan {- LocalAppActionPlan(- tools: [- .openOrFocusApp,- .observeApp,- .focusSearch,- .setText,- .pressReturn,- .verifyCommand- ]- )- }-- public var isExecutable: Bool {- tools.isEmpty == false- && tools.contains(where: { $0 == .setText || $0 == .pressReturn })- }-- public var requiresTextInput: Bool {- tools.contains(.setText)- }-- public var requiresVisibleTextVerification: Bool {- verificationTools.contains(.verifyVisibleText)- }-- public static func isVerificationTool(_ tool: LocalAppActionPlanTool) -> Bool {- tool == .verifyCommand || tool == .verifyVisibleText- }-- private enum CodingKeys: String, CodingKey {- case tools- case inputEntity- case controlID- case focusKey- case verificationTools- }-- public init(from decoder: Decoder) throws {- let container = try decoder.container(keyedBy: CodingKeys.self)- let tools = try container.decode([LocalAppActionPlanTool].self, forKey: .tools)- let verificationTools = try container.decodeIfPresent([LocalAppActionPlanTool].self, forKey: .verificationTools)- ?? tools.filter(Self.isVerificationTool)- self.init(- tools: tools,- inputEntity: try container.decode(String.self, forKey: .inputEntity),- controlID: try container.decode(String.self, forKey: .controlID),- focusKey: try container.decode(String.self, forKey: .focusKey),- verificationTools: verificationTools- )- }-- public func encode(to encoder: Encoder) throws {- var container = encoder.container(keyedBy: CodingKeys.self)- try container.encode(tools, forKey: .tools)- try container.encode(inputEntity, forKey: .inputEntity)- try container.encode(controlID, forKey: .controlID)- try container.encode(focusKey, forKey: .focusKey)- try container.encode(verificationTools, forKey: .verificationTools)- }-}--public struct TaskIntent: Codable, Equatable, Sendable {- public var intentID: String- public var taskType: String- public var targetApp: LocalAppTarget- public var entities: [String: String]- public var normalizedEntities: [String: String]- public var confidence: Double- public var parserSource: TaskIntentParserSource- public var needsConfirmation: Bool- public var sourceModelCallID: String?- public var actionPlan: LocalAppActionPlan?- public var metadata: [String: String]-- public init(- intentID: String,- taskType: String,- targetApp: LocalAppTarget,- entities: [String: String] = [:],- normalizedEntities: [String: String] = [:],- confidence: Double,- parserSource: TaskIntentParserSource,- needsConfirmation: Bool = false,- sourceModelCallID: String? = nil,- actionPlan: LocalAppActionPlan? = nil,- metadata: [String: String] = [:]- ) {- self.intentID = intentID- self.taskType = taskType- self.targetApp = targetApp- self.entities = entities- self.normalizedEntities = normalizedEntities- self.confidence = min(max(confidence, 0), 1)- self.parserSource = parserSource- self.needsConfirmation = needsConfirmation- self.sourceModelCallID = sourceModelCallID- self.actionPlan = actionPlan- self.metadata = metadata- }-}-public struct LocalAppTaskEntityRule: Codable, Equatable, Sendable {public var name: Stringpublic var markers: [String]@@ -367,19 +222,6 @@ public struct LocalAppTaskDefinition: Codable, Equatable, Sendable {}}-public enum LocalAppTaskStepStatus: String, Codable, Equatable, Sendable {- case needsEvidence = "needs-evidence"- case blocked- case verified-}--public enum LocalAppTaskTerminalState: String, Codable, Equatable, Sendable {- case completed- case needsUserReview = "needs-user-review"- case failedSafe = "failed-safe"- case timedOut = "timed-out"-}-public struct LocalAppTaskObservation: Codable, Equatable, Sendable {public var appIsRunning: Boolpublic var appIsFocused: Bool@@ -405,52 +247,3 @@ public struct LocalAppTaskObservation: Codable, Equatable, Sendable {}}-public struct LocalAppEvidenceBackedActionStep: Codable, Equatable, Sendable {- public var id: String- public var role: LocalAppTaskStepRole- public var status: LocalAppTaskStepStatus- public var summary: String- public var metadata: [String: String]-- public init(- id: String,- role: LocalAppTaskStepRole,- status: LocalAppTaskStepStatus,- summary: String,- metadata: [String: String] = [:]- ) {- self.id = id- self.role = role- self.status = status- self.summary = summary- self.metadata = metadata- }-}--public struct LocalAppEvidenceBackedActionPlan: Codable, Equatable, Sendable {- public var intent: TaskIntent- public var targetApp: LocalAppTarget- public var steps: [LocalAppEvidenceBackedActionStep]- public var terminalState: LocalAppTaskTerminalState- public var canExecuteGuardedActions: Bool- public var verificationConfidence: Double- public var metadata: [String: String]-- public init(- intent: TaskIntent,- targetApp: LocalAppTarget,- steps: [LocalAppEvidenceBackedActionStep],- terminalState: LocalAppTaskTerminalState,- canExecuteGuardedActions: Bool,- verificationConfidence: Double,- metadata: [String: String] = [:]- ) {- self.intent = intent- self.targetApp = targetApp- self.steps = steps- self.terminalState = terminalState- self.canExecuteGuardedActions = canExecuteGuardedActions- self.verificationConfidence = min(max(verificationConfidence, 0), 1)- self.metadata = metadata- }-}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/GenericHarnessTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/GenericHarnessTests.swiftindex c020cbf9..27d45823 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/GenericHarnessTests.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/GenericHarnessTests.swift@@ -1414,7 +1414,7 @@ struct GenericHarnessTests {question: "What should I send?",pendingToolCall: HarnessToolCall(id: "pending-run",- name: LocalAppActionPlanTool.setText.rawValue+ name: "ui.setText"))let pointerTask = UserQueryNotchTask(diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/LocalAppTaskTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/LocalAppTaskTests.swiftindex 7a59c293..97e70f05 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/LocalAppTaskTests.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/LocalAppTaskTests.swift@@ -6,31 +6,6 @@ import Testing@Suitestruct LocalAppTaskTests {- @Test- func structuredWeatherIntentCarriesModelSelectedEntities() throws {- let intent = weatherIntent(rawCity: "SF", city: "San Francisco")-- #expect(intent.taskType == "weather_lookup")- #expect(intent.targetApp.appName == "Weather")- #expect(intent.targetApp.bundleIdentifier == "com.apple.weather")- #expect(intent.entities["city"] == "SF")- #expect(intent.normalizedEntities["city"] == "San Francisco")- #expect(intent.confidence == 0.93)- #expect(intent.parserSource == .localModel)- #expect(intent.needsConfirmation == false)- #expect(intent.metadata["catalogEntry"] == "built-in-weather-lookup")- }-- @Test- func modelIntentCanRequestConfirmationForMissingRequiredEntity() throws {- let intent = weatherIntent(rawCity: "", city: "", needsConfirmation: true)-- #expect(intent.taskType == "weather_lookup")- #expect(intent.intentID == "weather_lookup-needs-city")- #expect(intent.needsConfirmation == true)- #expect(intent.metadata["missingEntity"] == "city")- }-@Testfunc staticProviderBuildsAppFinderCatalogWithSupportAndDenyMetadata() throws {let provider = StaticLocalAppAvailabilityProvider(@@ -351,34 +326,6 @@ struct LocalAppTaskTests {#expect(groundedMetadata["control.bounds.space"] == HotLoopCoordinateSpace.normalizedTarget.rawValue)}- private func weatherIntent(- rawCity: String,- city: String,- confidence: Double = 0.93,- needsConfirmation: Bool = false- ) -> TaskIntent {- let definition = BuiltInLocalAppTaskDefinitions.weatherLookup- return TaskIntent(- intentID: needsConfirmation ? "weather_lookup-needs-city" : "weather_lookup-\(slug(city))",- taskType: definition.taskType,- targetApp: definition.targetApp,- entities: rawCity.isEmpty ? [:] : ["city": rawCity],- normalizedEntities: city.isEmpty ? [:] : ["city": city],- confidence: confidence,- parserSource: .localModel,- needsConfirmation: needsConfirmation,- metadata: definition.metadata.merging(- needsConfirmation ? ["missingEntity": "city"] : [:]- ) { current, _ in current }- )- }-- private func slug(_ value: String) -> String {- LocalAppTextNormalizer.normalizedPhrase(value)- .split(separator: " ")- .joined(separator: "-")- }-}private final class RecordingApplicationCatalogScanner: LocalApplicationCatalogScanning, @unchecked Sendable {@@ -442,32 +389,3 @@ private actor RecordingCatalogProfileGenerator: LocalAppCatalogProfileGeneratingbatches}}---private actor RecordingLocalAppTaskInputBackend: ActionEngineInputBackend {- private var keys: [String] = []- private var commands: [ActionEngineCommand] = []-- func execute(_ command: ActionEngineCommand) async -> ActionEngineInputBackendResult {- commands.append(command)- keys.append(command.key ?? "")- return ActionEngineInputBackendResult(- executed: true,- completedAt: command.issuedAt,- metadata: [- "liveInputBackend": "recording-local-app-task",- "inputMode": command.kind == .tap ? "coordinateClick" : "keyCommand",- "elementClick": String(command.kind == .tap),- "controlID": command.metadata["controlID"] ?? ""- ]- )- }-- func executedKeys() -> [String] {- keys- }-- func executedCommands() -> [ActionEngineCommand] {- commands- }-}