Open source CapCut alternative.
TypeScript
feat(app): preload relevant skill guides into the planner
David Lede4304195242
diff --git a/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift b/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swiftindex 8e268eee..dd96d9d0 100644--- a/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift+++ b/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift@@ -93,8 +93,17 @@ public enum DonkeyPrompts {// MARK: - Request understanding (once per turn, before the loop)- public static func requestUnderstanding(command: String, frontmostAppName: String) -> String {- """+ public static func requestUnderstanding(+ command: String,+ frontmostAppName: String,+ skillCatalog: String? = nil+ ) -> String {+ let trimmedCatalog = skillCatalog?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""+ let skillsBlock = trimmedCatalog.isEmpty+ ? ""+ : "\nSKILLS (each is an authoritative playbook for its domain; the one(s) you name in "+ + "relevantSkillIDs get loaded for the planner):\n\(trimmedCatalog)\n"+ return """You are the first step of a macOS agent. Read the user's request and return a precise, structuredunderstanding of EXACTLY what they want. You do not act or choose tools here — a separate plannerdoes that. Be broad in what you accept and specific in what you capture.@@ -102,7 +111,7 @@ public enum DonkeyPrompts {The app currently in front of the user is "\(frontmostAppName)".USER REQUEST: \(command)-+ \(skillsBlock)Fill the fields:- turnKind: what this turn fundamentally is. Decide this FIRST and let it govern everything else:- "converse": a greeting ("hi", "hey", "yo"), thanks, acknowledgement, small talk, or a@@ -143,6 +152,10 @@ public enum DonkeyPrompts {"show me…", "open … so I can see it", "walk me through…", "how do I…", or any turn whosevalue is the user looking at the app. Choose "background" for everything else: the user wantsthe work done, not to watch it happen. When unsure, prefer "background".+ - relevantSkillIDs: from the SKILLS list above, the ids of any skill whose playbook this task falls+ under (0, 1, or a few — match on each skill's description and keywords). Its full guide is loaded+ for the planner, so the right pick makes the work reliable and a wrong one wastes attention. Empty+ for conversation, a task no skill covers, or when no SKILLS list is shown.Return JSON only."""@@ -235,6 +248,7 @@ public enum DonkeyPrompts {appGuidance: String?,understanding: HarnessRequestUnderstanding?,skillCatalog: String? = nil,+ preloadedSkillGuides: [String] = [],lessons: String? = nil,rollingContext: String? = nil,retryNote: String? = nil,@@ -290,12 +304,25 @@ public enum DonkeyPrompts {guidanceBlock = ""}- // The full installed-skill catalog, so the planner can route to an authoritative playbook even- // when the task has no GUI target app (e.g. playing music or saving a note by script): those- // skills are not preloaded above because no specific app window is being driven.+ // The full guides for the skills the understanding boundary judged relevant to THIS task, preloaded+ // so the planner has the authoritative playbook from step one — the capability-skill analogue of the+ // app guide above. These are the skills to FOLLOW; do not improvise their domain by hand.+ let preloadedGuides = preloadedSkillGuides+ .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }+ .filter { !$0.isEmpty }+ let preloadedSkillsBlock = preloadedGuides.isEmpty+ ? ""+ : "\nRELEVANT SKILL GUIDES for this task (authoritative — follow these step by step instead of "+ + "improvising; they are the reason the task is reliable):\n"+ + preloadedGuides.joined(separator: "\n\n") + "\n"++ // The compact catalog of every other available skill, so the planner can reach one whose relevance+ // only becomes clear after it starts working (the task had no GUI target and was not preselected+ // above). Load a capability skill's full guide with skill.load (or app_skill for an app skill), and+ // run a validated workflow with skill_run, instead of improvising raw commands.let skillCatalogBlock: Stringif let skillCatalog, !skillCatalog.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {- skillCatalogBlock = "\nINSTALLED APP SKILLS (authoritative playbooks for these apps/domains — when the task maps to one, get its full guide with app_skill and run its validated scripts with skill_run instead of improvising raw commands):\n\(skillCatalog)\n"+ skillCatalogBlock = "\nOTHER AVAILABLE SKILLS (authoritative playbooks; if the task maps to one that is NOT already preloaded above, load its full guide with skill.load before improvising):\n\(skillCatalog)\n"} else {skillCatalogBlock = ""}@@ -329,7 +356,7 @@ public enum DonkeyPrompts {GOAL: \(goalText)\(followUpBlock)\(understandingBlock)\(lessonsBlock)\(rollingContextBlock)\(historyBlock)- \(factsBlock)\(guidanceBlock)\(skillCatalogBlock)\(windowsBlock)+ \(factsBlock)\(guidanceBlock)\(preloadedSkillsBlock)\(skillCatalogBlock)\(windowsBlock)\(elementsBlock)AVAILABLE TOOLS:diff --git a/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift b/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swiftindex 43334341..5312e65a 100644--- a/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift+++ b/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift@@ -35,6 +35,12 @@ public struct HarnessRequestUnderstanding: Sendable, Equatable {/// 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: ExecutionPreference+ /// Ids the model picked from the skill catalog whose playbook this task should follow (0, 1, or a+ /// few). The harness preloads each one's full guide into the planner — the capability-skill analogue+ /// of `targetAppName` driving the app skill's preload — so a task in a skill's domain gets that+ /// skill's instructions from step one. Empty when no skill applies. Selected by the model against a+ /// typed catalog, never matched from raw text.+ public var relevantSkillIDs: [String]public init(turnKind: HarnessTurnKind = .act,@@ -44,7 +50,8 @@ public struct HarnessRequestUnderstanding: Sendable, Equatable {successCriteria: String? = nil,needsClarification: Bool = false,clarifyingQuestion: String? = nil,- executionPreference: ExecutionPreference = .background+ executionPreference: ExecutionPreference = .background,+ relevantSkillIDs: [String] = []) {self.turnKind = turnKindself.restatedGoal = restatedGoal@@ -54,6 +61,7 @@ public struct HarnessRequestUnderstanding: Sendable, Equatable {self.needsClarification = needsClarificationself.clarifyingQuestion = clarifyingQuestionself.executionPreference = executionPreference+ self.relevantSkillIDs = relevantSkillIDs}}@@ -75,11 +83,21 @@ public final class HostedHarnessRequestUnderstanding {/// Returns the parsed understanding, or `nil` on any provider/decode failure so the caller can/// degrade to driving the raw command directly rather than dead-ending.- public func understand(command: String, frontmostAppName: String) async -> HarnessRequestUnderstanding? {- let prompt = DonkeyPrompts.requestUnderstanding(command: command, frontmostAppName: frontmostAppName)+ public func understand(+ command: String,+ frontmostAppName: String,+ skillCatalog: String? = nil+ ) async -> HarnessRequestUnderstanding? {+ let prompt = DonkeyPrompts.requestUnderstanding(+ command: command,+ frontmostAppName: frontmostAppName,+ skillCatalog: skillCatalog+ )let startedAt = RunTraceTimestamp.now()do {- let response = try await backend.createResponse(responseRequest(command: command, frontmostAppName: frontmostAppName))+ let response = try await backend.createResponse(+ responseRequest(command: command, frontmostAppName: frontmostAppName, skillCatalog: skillCatalog)+ )let endedAt = RunTraceTimestamp.now()guard let text = RemoteInferenceResponseHelpers.outputText(from: response), !text.isEmpty else {recordCall(prompt: prompt, response: "<no output text>",@@ -103,7 +121,10 @@ public final class HostedHarnessRequestUnderstanding {needsClarification: wire.needsClarification ?? false,clarifyingQuestion: wire.clarifyingQuestion.flatMap { $0.isEmpty ? nil : $0 },executionPreference: wire.executionPreference- .flatMap { ExecutionPreference(rawValue: $0) } ?? .background+ .flatMap { ExecutionPreference(rawValue: $0) } ?? .background,+ relevantSkillIDs: (wire.relevantSkillIDs ?? [])+ .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }+ .filter { !$0.isEmpty })} catch {recordCall(prompt: prompt, response: String(String(describing: error).prefix(500)),@@ -142,10 +163,11 @@ public final class HostedHarnessRequestUnderstanding {var needsClarification: Bool?var clarifyingQuestion: String?var executionPreference: String?+ var relevantSkillIDs: [String]?private enum CodingKeys: String, CodingKey {case turnKind, restatedGoal, targetAppName, parameters, successCriteria, needsClarification, clarifyingQuestion- case executionPreference+ case executionPreference, relevantSkillIDs}init(from decoder: Decoder) throws {@@ -157,6 +179,7 @@ public final class HostedHarnessRequestUnderstanding {clarifyingQuestion = try container.decodeIfPresent(String.self, forKey: .clarifyingQuestion)needsClarification = try container.decodeIfPresent(Bool.self, forKey: .needsClarification)executionPreference = try container.decodeIfPresent(String.self, forKey: .executionPreference)+ relevantSkillIDs = try container.decodeIfPresent([String].self, forKey: .relevantSkillIDs)// 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)?@@ -189,7 +212,11 @@ public final class HostedHarnessRequestUnderstanding {}}- private func responseRequest(command: String, frontmostAppName: String) -> RemoteInferenceResponseCreateRequest {+ private func responseRequest(+ command: String,+ frontmostAppName: String,+ skillCatalog: String?+ ) -> RemoteInferenceResponseCreateRequest {RemoteInferenceResponseCreateRequest(input: .array([.object([@@ -199,7 +226,8 @@ public final class HostedHarnessRequestUnderstanding {"type": .string("input_text"),"text": .string(DonkeyPrompts.requestUnderstanding(command: command,- frontmostAppName: frontmostAppName+ frontmostAppName: frontmostAppName,+ skillCatalog: skillCatalog))])])@@ -214,7 +242,7 @@ public final class HostedHarnessRequestUnderstanding {"schema": .object(["type": .string("object"),"additionalProperties": .bool(false),- "required": .array([.string("turnKind"), .string("restatedGoal"), .string("needsClarification")]),+ "required": .array([.string("turnKind"), .string("restatedGoal"), .string("needsClarification"), .string("relevantSkillIDs")]),"properties": .object(["turnKind": .object(["type": .string("string"),@@ -232,6 +260,10 @@ public final class HostedHarnessRequestUnderstanding {"executionPreference": .object(["type": .string("string"),"enum": .array([.string("foreground"), .string("background")])+ ]),+ "relevantSkillIDs": .object([+ "type": .string("array"),+ "items": .object(["type": .string("string")])])])])diff --git a/apps/Donkey/Sources/DonkeyAI/HostedHarnessStepPlanner.swift b/apps/Donkey/Sources/DonkeyAI/HostedHarnessStepPlanner.swiftindex 586a6f98..5bb68b95 100644--- a/apps/Donkey/Sources/DonkeyAI/HostedHarnessStepPlanner.swift+++ b/apps/Donkey/Sources/DonkeyAI/HostedHarnessStepPlanner.swift@@ -25,6 +25,9 @@ public final class HostedHarnessStepPlanner: HarnessNextStepPlanning {/// so the planner can route to an authoritative playbook even when no GUI app is the drive target —/// e.g. playing music or saving a note by script. nil when no skills are installed.private let skillCatalog: String?+ /// Full guides for the skills the understanding boundary preselected for this task, rendered into every+ /// step's prompt as authoritative playbooks (the capability-skill analogue of `appGuidance`).+ private let preloadedSkillGuides: [String]/// Durable operating lessons recalled from past runs whose goal resembled this one, pre-formatted as a/// bounded bullet block and rendered into every step's prompt. Computed once at run start (the goal/// doesn't change mid-run), so it's a constant here. nil when nothing relevant was learned before.@@ -81,6 +84,7 @@ public final class HostedHarnessStepPlanner: HarnessNextStepPlanning {appGuidance: String?,understanding: HarnessRequestUnderstanding? = nil,skillCatalog: String? = nil,+ preloadedSkillGuides: [String] = [],recalledLessons: String? = nil,trace: (any HarnessTurnTracing)? = nil,openWindows: @escaping @Sendable () -> [MacWindowTargetCandidate] = { [] },@@ -93,6 +97,7 @@ public final class HostedHarnessStepPlanner: HarnessNextStepPlanning {self.appGuidance = appGuidanceself.understanding = understandingself.skillCatalog = skillCatalog+ self.preloadedSkillGuides = preloadedSkillGuidesself.recalledLessons = recalledLessonsself.trace = traceself.openWindows = openWindows@@ -385,6 +390,7 @@ public final class HostedHarnessStepPlanner: HarnessNextStepPlanning {appGuidance: appGuidance,understanding: understanding,skillCatalog: skillCatalog,+ preloadedSkillGuides: preloadedSkillGuides,lessons: recalledLessons,rollingContext: rollingContext,retryNote: retryNote,diff --git a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskSkillContext.swift b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskSkillContext.swiftindex 1a4dfde7..88c3e075 100644--- a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskSkillContext.swift+++ b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskSkillContext.swift@@ -156,6 +156,35 @@ public enum BuiltInLocalAppSkillPacks {}}+ /// A compact, one-line-per-skill catalog of every available skill (built-in + installed + learned) for+ /// the understanding boundary to choose from: `id`, the one-line description, and the trigger keywords.+ /// The model returns the ids of the skills a task should follow (`relevantSkillIDs`) and the harness+ /// preloads those guides — so no intent is matched in Swift; the model routes against this list.+ public static func skillSelectionCatalog() -> String? {+ let skills = descriptors().sorted { $0.id < $1.id }+ guard !skills.isEmpty else { return nil }+ let lines = skills.map { skill -> String in+ let keywords = (skill.metadata["keywords"] ?? "").trimmingCharacters(in: .whitespacesAndNewlines)+ let keywordsText = keywords.isEmpty ? "" : " [keywords: \(keywords)]"+ return " - \(skill.id): \(skill.summary)\(keywordsText)"+ }+ return lines.joined(separator: "\n")+ }++ /// The full operating guide for a skill selected by id (built-in, installed, or learned) — a labeled+ /// header plus the SKILL.md body with frontmatter stripped, bounded for the prompt. This is the+ /// capability-skill analogue of `appOperatingGuidance(forApp:)`: the understanding boundary names the+ /// `relevantSkillIDs` a task needs and the harness preloads each one's guide into the planner, so a task+ /// in a skill's domain gets that skill's playbook from step one without the model having to find it.+ public static func skillGuidance(forID id: String, maxCharacters: Int = 3_500) -> String? {+ let wanted = id.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()+ guard !wanted.isEmpty,+ let match = descriptors().first(where: { $0.id.lowercased() == wanted })+ else { return nil }+ let snippet = instructionSnippet(for: match, maxCharacters: maxCharacters)+ return snippet.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? nil : snippet+ }+public static func scriptSource(skillID: String,relativePath: String