Open source CapCut alternative.
TypeScript
Tighten local app task execution defaults
David Le1830c669151a
diff --git a/apps/Donkey/Sources/DonkeyAI/HostedTaskIntentParsingAdapter.swift b/apps/Donkey/Sources/DonkeyAI/HostedTaskIntentParsingAdapter.swiftindex b67970f5..fc443d8e 100644--- a/apps/Donkey/Sources/DonkeyAI/HostedTaskIntentParsingAdapter.swift+++ b/apps/Donkey/Sources/DonkeyAI/HostedTaskIntentParsingAdapter.swift@@ -398,7 +398,7 @@ public struct HostedTaskIntentParsingAdapter: TaskIntentParsingAdapter {"Donkey is a capable Mac agent that can operate any application and item on the Mac. Default to acting: be broad in what you accept and specific in what you do. For an under-specified but low-risk, reversible request, choose reasonable, concrete specifics yourself and proceed — do not ask the user to fill in details you can sensibly decide.","First decide whether Command should be answered conversationally, should ask a clarification, or should use a supported tool path. Prefer acting via a tool path over clarification whenever the action is safe and reversible.","Choose conversation for greetings, questions, brainstorming, explanations, status requests, malformed requests, or any turn that does not require external action.",- "Choose guidance when the user wants to be SHOWN where something is or how to do something without Donkey changing any state (e.g. \"show me where X is\", \"how do I X\", \"point me to X\"). Set route guidance, targetAppName to the app, needsConfirmation false, and list the on-screen controls to point at, in order, in metadata.guidanceTargets as semicolon-separated `label::query` pairs (label is shown to the user, query is the control's on-screen text). Set metadata.assistantResponse to a brief, natural spoken narration of what you are pointing at (this is shown to the user). Do not plan any acting tools for guidance.",+ "Choose guidance when the user wants to be SHOWN where something is or how to do something without Donkey changing any state (e.g. \"show me where X is\", \"how do I X\", \"point me to X\"). Set route guidance, targetAppName to the app, needsConfirmation false, and list the on-screen controls to point at, in order, in metadata.guidanceTargets as a JSON array of objects, each {\"label\": \"...\", \"query\": \"...\"} (label is shown to the user, query is the control's on-screen text). Set metadata.assistantResponse to a brief, natural spoken narration of what you are pointing at (this is shown to the user). Do not plan any acting tools for guidance.","Choose clarification only when acting could be destructive, irreversible, costly, or sent/shared externally AND the user's intent is genuinely ambiguous, or when a required target is unknown and cannot be reasonably inferred. Never ask for clarification merely because a request is casual, broad, or under-specified (for example \"play some coldplay\", \"open my notes\", \"make it bigger\") — resolve those by picking concrete specifics and acting.","Choose localAppTask whenever the user wants Donkey to operate a local app or item and you can identify the action and a target app or item. If payload specifics are under-specified (which song, which note, which result), pick concrete, reasonable defaults and proceed rather than requiring the user to supply every detail.","Always fill structuredIntent, ambiguityRisk, contextNeeds, planSteps, verificationCriteria, fallbacks, clarificationPolicy, and metadata.",diff --git a/apps/Donkey/Sources/DonkeyHarness/GenericHarnessBuiltInToolExecutors.swift b/apps/Donkey/Sources/DonkeyHarness/GenericHarnessBuiltInToolExecutors.swiftindex 0052f0cb..c706224c 100644--- a/apps/Donkey/Sources/DonkeyHarness/GenericHarnessBuiltInToolExecutors.swift+++ b/apps/Donkey/Sources/DonkeyHarness/GenericHarnessBuiltInToolExecutors.swift@@ -1317,27 +1317,51 @@ public enum BuiltInHarnessToolExecutors {// MARK: - Verification & Lifecycle+ /// Tools that observe/plan/converse rather than change app state. A criteria-less `state.verify`+ /// must not treat one of these succeeding as evidence the task's action actually happened.+ private static let nonActionVerifyTools: Set<String> = [+ "state.verify",+ "screen.observe",+ "app.observe",+ "elements.get",+ "skill.load",+ "skill.list",+ "app.list",+ "app.lookup"+ ]+private static func stateVerify(_ context: HarnessToolExecutionContext) -> HarnessToolResult {guard let criteria = trimmed(context.call.input["criteria"]) else {- // Planners sometimes append a verify step without echoing explicit criteria. Rather than- // failing a run whose action already succeeded, verify against the most recent guarded- // action's structured outcome: pass unless that action explicitly reported failure.- let recentAction = context.worldModel.facts["script.executed.succeeded"]- let verified = recentAction != "false"+ // Planners sometimes append a verify step without echoing explicit criteria. Verify against+ // the evidence the run produced: a guarded script that explicitly reported failure fails;+ // otherwise pass when SOME prior action (script OR accessibility/UI) actually succeeded.+ // A criteria-less verify with no prior action at all (e.g. ordered before anything ran) has+ // nothing to attest to, so it does not report success vacuously.+ let scriptOutcome = context.worldModel.facts["script.executed.succeeded"]+ let hadSucceededAction = context.worldModel.attemptedToolCalls.contains { record in+ record.resultStatus == .succeeded && !Self.nonActionVerifyTools.contains(record.call.name)+ }+ let verified = scriptOutcome != "false" && (scriptOutcome == "true" || hadSucceededAction)+ let summary: String+ if !verified, scriptOutcome == "false" {+ summary = "Prior action reported failure."+ } else if !verified {+ summary = "Verification has no criteria and no prior action evidence to confirm."+ } else {+ summary = "Verification succeeded from prior action evidence (no explicit criteria)."+ }return HarnessToolResult(callID: context.call.id,toolName: context.call.name,status: verified ? .succeeded : .failed,- summary: verified- ? "Verification succeeded from prior action evidence (no explicit criteria)."- : "Prior action reported failure.",+ summary: summary,observations: HarnessObservationDelta(facts: [- "state.verify.criteria": "inferred:script.executed.succeeded",+ "state.verify.criteria": "inferred:priorActionEvidence","state.verify.verified": String(verified),"lastAcceptedTool": context.call.name],- uncertainty: verified ? [] : ["prior guarded action reported failure"]+ uncertainty: verified ? [] : ["no explicit criteria and no successful prior action to verify against"]),metadata: ["verified": String(verified), "criteria.inferred": "true"])diff --git a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskCatalog.swift b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskCatalog.swiftindex 46f7ab97..d33cb11e 100644--- a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskCatalog.swift+++ b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskCatalog.swift@@ -849,17 +849,19 @@ public struct LocalAppTaskCatalog: Sendable {}if intent.needsConfirmation {- // The planner's confirmation request is advisory for safe, reversible actions. Donkey is- // an act-first Mac agent: it only hard-stops to confirm when the planner classified the- // action as genuinely high-risk/dangerous, or when a required detail is actually missing.- // Otherwise it proceeds and relies on the per-tool permission and guardrail gates at- // execution time for real safety.+ // Donkey is an act-first Mac agent: it doesn't over-confirm safe, reversible actions.+ // But when the planner explicitly asked to confirm (needsConfirmation=true), the default+ // is to HONOR that — we only proceed without confirming when the planner ALSO explicitly+ // classified the action as low-risk and non-dangerous. Absent risk metadata (e.g. a+ // non-hosted parser), medium/high risk, dangerous ambiguity, or a missing required detail+ // all keep the confirmation hard-stop, rather than silently bypassing it.+ // riskLevel ∈ {low, medium, high}; ambiguityClass ∈ {safe, recoverable, dangerous}.+ // A non-hosted parser leaves both empty, which is (correctly) NOT low-risk → confirm.let riskLevel = intent.metadata["genericHarness.risk.level"]?.lowercased() ?? ""let ambiguityClass = intent.metadata["genericHarness.ambiguity.class"]?.lowercased() ?? ""let hasMissingEntity = !(intent.metadata["missingEntity"] ?? "").isEmpty- let mustConfirm = hasMissingEntity- || riskLevel == "high"- || ambiguityClass == "dangerous"+ let explicitlyLowRisk = riskLevel == "low" && ambiguityClass != "dangerous"+ let mustConfirm = hasMissingEntity || !explicitlyLowRiskif mustConfirm {return LocalAppTaskCatalogResolution(status: .needsConfirmation,diff --git a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/music-media/scripts/play-media-by-search.applescript b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/music-media/scripts/play-media-by-search.applescriptindex b44dd133..45d0d8e1 100644--- a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/music-media/scripts/play-media-by-search.applescript+++ b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/music-media/scripts/play-media-by-search.applescript@@ -7,15 +7,55 @@ end iftell application id "com.apple.Music"activate- -- Use the Music dictionary directly (Automation only, no UI keystrokes) so playback is reliable- -- and does not depend on Accessibility. `search` matches the query across title/artist/album.+ -- Prefer the Music dictionary directly (Automation only, no UI keystrokes) so playback of music+ -- the user OWNS is reliable and does not depend on Accessibility. `search` matches the query+ -- across title/artist/album. This only covers the local library, so if it finds nothing we fall+ -- back to the full-app search below, which reaches the Apple Music streaming catalog.set matches to (search library playlist 1 for trimmedQuery)- if (count of matches) is 0 then- return "status=not_found" & linefeed & "query=" & trimmedQuery & linefeed & "clarification.required=true" & linefeed & "clarification.question=I couldn't find " & trimmedQuery & " in the library. What would you like me to play?"+ if (count of matches) is not 0 then+ set chosen to item 1 of matches+ play chosen+ delay 0.6+ return "status=played" & linefeed & "source=local_library" & linefeed & "query=" & trimmedQuery & linefeed & "playedTitle=" & (name of chosen) & linefeed & "playedArtist=" & (artist of chosen)end if+end tell++-- Streaming fallback: the dictionary `search` only sees the local library, so for tracks the user+-- does not own we drive the Music app's own search field, which surfaces Apple Music streaming+-- results. The first Return submits the search; the second activates the top playable result.+delay 0.3++tell application "System Events"+ if not (exists process "Music") then+ return "status=failed" & linefeed & "failureReason=music_process_unavailable"+ end if++ tell process "Music"+ set frontmost to true+ end tell- set chosen to item 1 of matches- play chosen- delay 0.6- return "status=played" & linefeed & "query=" & trimmedQuery & linefeed & "playedTitle=" & (name of chosen) & linefeed & "playedArtist=" & (artist of chosen)+ keystroke "f" using command down+ delay 0.2+ keystroke trimmedQuery+ delay 0.2+ key code 36+ delay 1.0+ key code 36end tell++-- Verify something actually started playing before claiming success; the keystroke path can't tell+-- on its own whether a result was selected, so check the Music app's real player state.+delay 0.8+tell application id "com.apple.Music"+ if player state is playing then+ set playedTitle to trimmedQuery+ set playedArtist to ""+ try+ set playedTitle to name of current track+ set playedArtist to artist of current track+ end try+ return "status=played" & linefeed & "source=streaming" & linefeed & "query=" & trimmedQuery & linefeed & "playedTitle=" & playedTitle & linefeed & "playedArtist=" & playedArtist+ end if+end tell++return "status=not_found" & linefeed & "query=" & trimmedQuery & linefeed & "clarification.required=true" & linefeed & "clarification.question=I couldn't find " & trimmedQuery & " to play. What would you like me to play?"