Open source CapCut alternative.
TypeScript
feat(app): add typed execution preference to request understanding
David Leae837ae70dc0
diff --git a/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift b/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swiftindex 2ff19122..44b12b9e 100644--- a/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift+++ b/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift@@ -113,6 +113,11 @@ public enum DonkeyPrompts {that you cannot reasonably resolve, or when it is destructive without a clear target. For anunder-specified but low-risk, reversible request, pick sensible specifics and set this false.- clarifyingQuestion: the single question to ask when needsClarification is true; otherwise empty.+ - executionPreference: "background" or "foreground". Choose "foreground" ONLY when the point of+ the request is for the user to watch or be shown the result on screen — e.g. "pull up…",+ "show me…", "open … so I can see it", "walk me through…", "how do I…", or any turn whose+ value is the user looking at the app. Choose "background" for everything else: the user wants+ the work done, not to watch it happen. When unsure, prefer "background".Return JSON only."""diff --git a/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift b/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swiftindex 19532676..7a17e31c 100644--- a/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift+++ b/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift@@ -25,6 +25,10 @@ public struct HarnessRequestUnderstanding: Sendable, Equatable {public var needsClarification: Bool/// The question to ask when `needsClarification` is true.public var clarifyingQuestion: String?+ /// Whether the turn's work should run in the background (the agent acts without stealing the+ /// cursor or raising the app) or in the foreground (the user is meant to watch). Set by this+ /// boundary from the request's intent — never matched from raw text. Defaults to background.+ public var executionPreference: ExecutionPreferencepublic init(restatedGoal: String,@@ -32,7 +36,8 @@ public struct HarnessRequestUnderstanding: Sendable, Equatable {parameters: [String: String] = [:],successCriteria: String? = nil,needsClarification: Bool = false,- clarifyingQuestion: String? = nil+ clarifyingQuestion: String? = nil,+ executionPreference: ExecutionPreference = .background) {self.restatedGoal = restatedGoalself.targetAppName = targetAppName@@ -40,6 +45,7 @@ public struct HarnessRequestUnderstanding: Sendable, Equatable {self.successCriteria = successCriteriaself.needsClarification = needsClarificationself.clarifyingQuestion = clarifyingQuestion+ self.executionPreference = executionPreference}}@@ -86,7 +92,9 @@ public final class HostedHarnessRequestUnderstanding {parameters: wire.parameters ?? [:],successCriteria: wire.successCriteria.flatMap { $0.isEmpty ? nil : $0 },needsClarification: wire.needsClarification ?? false,- clarifyingQuestion: wire.clarifyingQuestion.flatMap { $0.isEmpty ? nil : $0 }+ clarifyingQuestion: wire.clarifyingQuestion.flatMap { $0.isEmpty ? nil : $0 },+ executionPreference: wire.executionPreference+ .flatMap { ExecutionPreference(rawValue: $0) } ?? .background)} catch {recordCall(prompt: prompt, response: String(String(describing: error).prefix(500)),@@ -123,9 +131,11 @@ public final class HostedHarnessRequestUnderstanding {var successCriteria: String?var needsClarification: Bool?var clarifyingQuestion: String?+ var executionPreference: String?private enum CodingKeys: String, CodingKey {case restatedGoal, targetAppName, parameters, successCriteria, needsClarification, clarifyingQuestion+ case executionPreference}init(from decoder: Decoder) throws {@@ -135,6 +145,7 @@ public final class HostedHarnessRequestUnderstanding {successCriteria = try container.decodeIfPresent(String.self, forKey: .successCriteria)clarifyingQuestion = try container.decodeIfPresent(String.self, forKey: .clarifyingQuestion)needsClarification = try container.decodeIfPresent(Bool.self, forKey: .needsClarification)+ executionPreference = try container.decodeIfPresent(String.self, forKey: .executionPreference)// The schema is non-strict, so a parameter value may arrive as a number or boolean. Coerce// scalars to strings instead of failing the whole decode.parameters = try container.decodeIfPresent([String: ScalarString].self, forKey: .parameters)?@@ -202,7 +213,11 @@ public final class HostedHarnessRequestUnderstanding {]),"successCriteria": .object(["type": .string("string")]),"needsClarification": .object(["type": .string("boolean")]),- "clarifyingQuestion": .object(["type": .string("string")])+ "clarifyingQuestion": .object(["type": .string("string")]),+ "executionPreference": .object([+ "type": .string("string"),+ "enum": .array([.string("foreground"), .string("background")])+ ])])])])diff --git a/apps/Donkey/Sources/DonkeyContracts/ExecutionPreference.swift b/apps/Donkey/Sources/DonkeyContracts/ExecutionPreference.swiftnew file mode 100644index 00000000..e78a0bea--- /dev/null+++ b/apps/Donkey/Sources/DonkeyContracts/ExecutionPreference.swift@@ -0,0 +1,13 @@+import Foundation++/// Whether a turn's work should run in the background (the agent acts without taking over the user's+/// cursor or raising the target app) or in the foreground (the user is meant to watch it happen).+///+/// This is a typed field set once by the request-understanding boundary — never inferred by matching+/// raw user text. Deterministic code reads only this enum, never the original phrasing. Background is+/// the default operating mode; foreground is chosen only when the point of the turn is for the user to+/// see the result on screen (pulling something up, "show me", "how do I…", a walkthrough).+public enum ExecutionPreference: String, Codable, Equatable, Sendable {+ case foreground+ case background+}