Open source CapCut alternative.
TypeScript
Wire the guidance route: "show me where X is" → pointer overlay
David Le34c9aa3a2b5f
diff --git a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swiftindex c04432be..b89f4d31 100644--- a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift@@ -261,6 +261,13 @@ struct LocalAppUserQueryCommandHandler: UserQueryCommandHandling {])+ if taskIntentResult.trace.metadata["genericHarness.intent.route"] == "guidance" {+ return await handleGuidance(+ trace: taskIntentResult.trace, traceID: traceID, taskID: taskID,+ modelMetadata: modelMetadata+ )+ }+if Self.shouldFailSafelyWithoutLocalTask(resolution) {return await handleFailSafe(resolution: resolution, traceID: traceID, taskID: taskID,@@ -544,6 +551,84 @@ struct LocalAppUserQueryCommandHandler: UserQueryCommandHandling {return result}+ /// Guidance route: show the user where something is by grounding the requested controls in the+ /// target app's accessibility tree and presenting a cursor overlay. Visualization only — no+ /// input, no app state change. Works for any app with an accessibility tree (native or Electron).+ private func handleGuidance(+ trace: AIModelCallTrace,+ traceID: String,+ taskID: String,+ modelMetadata: [String: String]+ ) async -> UserQueryCommandHandlingResult {+ let appName = trace.metadata["genericHarness.intent.targetApp"].flatMap { $0.isEmpty ? nil : $0 }+ let targets = Self.guidanceTargets(from: trace.metadata["guidanceTargets"] ?? "")+ let title = trace.metadata["genericHarness.intent.goal"].flatMap { $0.isEmpty ? nil : $0 } ?? "Here you go"+ let outcome = await MainActor.run {+ GuidanceOverlayFlow.cursorGuide(+ appName: appName,+ bundleIdentifier: nil,+ targets: targets,+ title: title,+ traceID: traceID+ )+ }+ let located = outcome.request != nil+ // Prefer the model's own narration; fall back only when it didn't provide one (or when we+ // couldn't actually ground the control at runtime, which the planner can't know up front).+ let modelResponse = trace.metadata["assistantResponse"].flatMap { $0.isEmpty ? nil : $0 }+ let response = located+ ? (modelResponse ?? "Here it is — follow the pointer.")+ : "I couldn't locate that on screen right now."+ let decision = AppHarnessDecision(+ kind: .respond,+ message: response,+ traceID: traceID,+ metadata: [+ "structuredDecision": "true",+ "router": "modelGuidance",+ "guidance.reason": outcome.reason+ ]+ )+ let result = UserQueryCommandHandlingResult(+ status: .completed,+ threadStatus: .chatting,+ decision: decision,+ summary: response,+ traceID: traceID,+ metadata: modelMetadata.merging([+ "appHarness.decision": AppHarnessDecisionKind.respond.rawValue,+ "router": "modelGuidance",+ "guidance.reason": outcome.reason,+ "guidance.targetCount": String(targets.count),+ "guidance.resolvedApp": outcome.resolvedAppName ?? ""+ ]) { _, new in new },+ cursorOverlayRequest: outcome.request+ )+ _ = await genericHarnessLifecycle.coordinator.complete(+ taskID: taskID,+ reason: "User query guidance overlay"+ )+ await coordinatorRegistry.finish(taskID: taskID)+ logHandlingResult(+ result,+ stage: "guidance",+ hint: located ? "Guided with a pointer overlay." : "No grounded control to point at."+ )+ return result+ }++ /// Parses planner `guidanceTargets` ("Label::query; Label::query") into ordered path targets.+ private static func guidanceTargets(from raw: String) -> [AccessibilityCursorPathTarget] {+ raw.components(separatedBy: ";").compactMap { entry in+ let parts = entry.components(separatedBy: "::")+ .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }+ let query = (parts.count > 1 ? parts[1] : parts.first ?? "")+ guard !query.isEmpty else { return nil }+ let label = (parts.count > 1 && !parts[0].isEmpty) ? parts[0] : query+ return AccessibilityCursorPathTarget(query: query, label: label, kind: .targetControl)+ }+ }+// MARK: - Generic Harness Task Executionprivate func finalizeGenericHarnessTask(diff --git a/apps/Donkey/Sources/DonkeyAI/HostedTaskIntentParsingAdapter.swift b/apps/Donkey/Sources/DonkeyAI/HostedTaskIntentParsingAdapter.swiftindex dd833f66..b67970f5 100644--- a/apps/Donkey/Sources/DonkeyAI/HostedTaskIntentParsingAdapter.swift+++ b/apps/Donkey/Sources/DonkeyAI/HostedTaskIntentParsingAdapter.swift@@ -398,6 +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 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/DonkeyAI/TaskIntentWireCodec.swift b/apps/Donkey/Sources/DonkeyAI/TaskIntentWireCodec.swiftindex c085b333..af657c35 100644--- a/apps/Donkey/Sources/DonkeyAI/TaskIntentWireCodec.swift+++ b/apps/Donkey/Sources/DonkeyAI/TaskIntentWireCodec.swift@@ -188,7 +188,7 @@ enum TaskIntentWireCodec {"properties": ["route": ["type": "string",- "enum": ["localAppTask", "conversation", "clarification"]+ "enum": ["localAppTask", "conversation", "clarification", "guidance"]],"goal": ["type": "string"],"taskType": ["type": "string", "enum": taskTypes],@@ -623,6 +623,7 @@ enum TaskIntentWireCodec {metadata["genericHarness.schemaVersion"] = wire.schemaVersionmetadata["genericHarness.intent.route"] = wire.structuredIntent.routemetadata["genericHarness.intent.goal"] = wire.structuredIntent.goal+ metadata["genericHarness.intent.targetApp"] = wire.structuredIntent.targetAppNamemetadata["genericHarness.ambiguity.class"] = wire.ambiguityRisk.ambiguityClassmetadata["genericHarness.risk.level"] = wire.ambiguityRisk.riskLevelmetadata["genericHarness.shouldAskBeforeActing"] = String(wire.ambiguityRisk.shouldAskBeforeActing)diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/GuidanceRouteLiveSmokeTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/GuidanceRouteLiveSmokeTests.swiftnew file mode 100644index 00000000..73904abd--- /dev/null+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/GuidanceRouteLiveSmokeTests.swift@@ -0,0 +1,57 @@+import AppKit+@testable import Donkey+import DonkeyContracts+import DonkeyUI+import Foundation+import Testing++/// Live, env-gated end-to-end test for the guidance route (plan phase 2): a natural-language+/// "show me where X is" goes through the real handler → hosted planner classifies `guidance` →+/// GuidanceOverlayFlow grounds the control → a cursor overlay is produced and presented.+///+/// env DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer DONKEY_LIVE_SMOKE=1 \+/// DONKEY_WEB_BASE_URL=http://localhost:3000 DONKEY_DEV_AUTH_BYPASS=1 \+/// swift test --filter GuidanceRouteLiveSmokeTests+@Suite+struct GuidanceRouteLiveSmokeTests {+ @Test+ @MainActor+ func showMeWhereRoutesToGuidanceAndOverlays() async {+ let env = ProcessInfo.processInfo.environment+ guard env["DONKEY_LIVE_SMOKE"] == "1" else { return }+ if env["DONKEY_WEB_BASE_URL"]?.isEmpty != false {+ Issue.record("DONKEY_WEB_BASE_URL not set")+ return+ }++ let appName = env["DONKEY_GUIDE_APP"] ?? "Music"+ NSWorkspace.shared.launchApplication(appName)+ try? await Task.sleep(nanoseconds: 800_000_000)++ let handler = LocalAppUserQueryCommandHandler()+ let result = await handler.handleSubmittedCommand("show me where the search field is in \(appName)")++ // The planner should have classified this as the guidance route.+ #expect(result.metadata["router"] == "modelGuidance")+ if result.cursorOverlayRequest == nil {+ Issue.record("Guidance produced no overlay: reason=\(result.metadata["guidance.reason"] ?? "?") app=\(result.metadata["guidance.resolvedApp"] ?? "?") targets=\(result.metadata["guidance.targetCount"] ?? "?")")+ return+ }++ let request = result.cursorOverlayRequest!+ #expect(!request.steps.isEmpty)++ if NSApplication.shared.activationPolicy() == .prohibited {+ NSApplication.shared.setActivationPolicy(.accessory)+ }+ let overlay = PointerCoachCursorOverlayController()+ overlay.show(request: request)+ let duration = request.steps.reduce(1.5) { $0 + $1.travelDuration + $1.holdDuration }+ Self.pump(forSeconds: duration)+ }++ @MainActor+ private static func pump(forSeconds seconds: TimeInterval) {+ RunLoop.main.run(until: Date().addingTimeInterval(seconds))+ }+}