Skip to content

Open source CapCut alternative.

TypeScript

Make local-app skills discoverable via file-based lexical retrieval

David Le097e1b646780
diff --git a/apps/Donkey/Sources/DonkeyAI/TaskIntentParsingAdapter.swift b/apps/Donkey/Sources/DonkeyAI/TaskIntentParsingAdapter.swift
index 3dc676d6..5d8f8657 100644
--- a/apps/Donkey/Sources/DonkeyAI/TaskIntentParsingAdapter.swift
+++ b/apps/Donkey/Sources/DonkeyAI/TaskIntentParsingAdapter.swift
@@ -31,12 +31,15 @@ public struct TaskIntentAdapterRequest: Equatable, Sendable {
self.contextSnippets = TaskIntentModelContextCompactor.compact(contextSnippets)
self.appFinderCatalog = appFinderCatalog
self.availableToolNames = availableToolNames
+ // Budget allows a compact discovery catalog plus ONE full skill body (the top match), so the
+ // chosen skill's concrete execution steps are not truncated. See LocalAppTaskSkillContext.
self.skillSnippets = TaskIntentModelContextCompactor(
maxSnippets: 8,
- maxSnippetCharacters: 1_200,
- maxTotalCharacters: 6_400
+ maxSnippetCharacters: 4_200,
+ maxTotalCharacters: 9_000
).compact(
skillSnippets ?? LocalAppTaskSkillContext.defaultContext(
+ command: command,
taskDefinitions: taskDefinitions,
appFinderCatalog: appFinderCatalog
).snippets
diff --git a/apps/Donkey/Sources/DonkeyHarness/GenericHarnessBuiltInToolExecutors.swift b/apps/Donkey/Sources/DonkeyHarness/GenericHarnessBuiltInToolExecutors.swift
index 64f41ba6..9a24e633 100644
--- a/apps/Donkey/Sources/DonkeyHarness/GenericHarnessBuiltInToolExecutors.swift
+++ b/apps/Donkey/Sources/DonkeyHarness/GenericHarnessBuiltInToolExecutors.swift
@@ -443,6 +443,9 @@ public enum BuiltInHarnessToolExecutors {
return failed(context, "Skill was not found: \(skillID)", reason: "skillNotFound")
}
+ let scriptCatalog = skill.scripts
+ .map { "\($0.id) [\($0.language.rawValue)]: \($0.purpose)" }
+ .joined(separator: "; ")
return success(
context,
summary: "Loaded skill \(skill.name).",
@@ -455,7 +458,11 @@ public enum BuiltInHarnessToolExecutors {
metadata: [
"skillID": skill.id,
"instructionPath": skill.instructionPath ?? "",
- "scriptIDs": skill.scripts.map(\.id).joined(separator: ",")
+ "scriptIDs": skill.scripts.map(\.id).joined(separator: ","),
+ "scriptCatalog": scriptCatalog,
+ // Progressive disclosure: surface the chosen skill's full instructions on load, so a
+ // skill discovered from the compact catalog gets its concrete execution detail here.
+ "skillInstructions": skill.description
]
)
}
diff --git a/apps/Donkey/Sources/DonkeyHarness/GenericHarnessSkillRegistry.swift b/apps/Donkey/Sources/DonkeyHarness/GenericHarnessSkillRegistry.swift
index e74bba89..89f8ee54 100644
--- a/apps/Donkey/Sources/DonkeyHarness/GenericHarnessSkillRegistry.swift
+++ b/apps/Donkey/Sources/DonkeyHarness/GenericHarnessSkillRegistry.swift
@@ -328,7 +328,10 @@ public struct HarnessSkillFileSystemSource: Sendable {
scripts: scriptDescriptors(in: directory),
metadata: [
"source": sourceKind == .builtIn ? "builtInFilesystem" : "filesystem",
- "directory": directory.path
+ "directory": directory.path,
+ // File-based discovery signal: natural trigger words for lexical skill matching
+ // (no embeddings). Comma-separated `keywords:` line in the SKILL.md frontmatter.
+ "keywords": metadataList(named: "keywords", in: contents).joined(separator: " ")
]
)
}
@@ -400,8 +403,12 @@ public struct HarnessSkillFileSystemSource: Sendable {
let relativePath = relativePath(of: url, from: skillDirectory)
let basename = url.deletingPathExtension().lastPathComponent
+ // Derive the script ID from the path WITHOUT the file extension so it matches the
+ // `scripts:` IDs declared in SKILL.md (e.g. `scripts-play-media-by-search`, not
+ // `scripts-play-media-by-search-applescript`).
+ let relativePathWithoutExtension = (relativePath as NSString).deletingPathExtension
return HarnessSkillScriptDescriptor(
- id: slug(relativePath),
+ id: slug(relativePathWithoutExtension),
language: language,
purpose: titleCased(basename),
relativePath: relativePath,
diff --git a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskSkillContext.swift b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskSkillContext.swift
index 2de3addf..c54ff858 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskSkillContext.swift
+++ b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskSkillContext.swift
@@ -65,6 +65,7 @@ public enum BuiltInLocalAppSkillPacks {
return !lowered.hasPrefix("id:")
&& !lowered.hasPrefix("description:")
&& !lowered.hasPrefix("tags:")
+ && !lowered.hasPrefix("keywords:")
&& !lowered.hasPrefix("tools:")
}
.joined(separator: "\n")
@@ -84,28 +85,52 @@ public struct LocalAppTaskSkillContext: Equatable, Sendable {
self.snippets = snippets
}
+ /// Builds skill guidance that scales to many skills via progressive disclosure (no embeddings):
+ /// 1. A compact discovery catalog — one line per skill (id + summary + tags) for the top-K
+ /// lexically-relevant skills — so the planner can SEE what is available and pick one.
+ /// 2. The FULL instruction body of the single best-matched skill, so its concrete execution
+ /// steps (e.g. skill.load → skill.script.execute) are never truncated.
+ /// Context stays bounded regardless of the total number of skills: K one-liners + 1 full body.
+ /// The planner can `skill.load` any other catalog entry to get that skill's full body on demand.
public static func defaultContext(
+ command: String = "",
taskDefinitions: [LocalAppTaskDefinition],
appFinderCatalog: [LocalAppFinderCatalogEntry],
- maxSkills: Int = 8
+ maxSkills: Int = 24,
+ detailCharacters: Int = 4_000
) -> LocalAppTaskSkillContext {
- let descriptors = selectedBuiltInSkillDescriptors(
+ let ranked = rankedBuiltInSkillDescriptors(
+ command: command,
taskDefinitions: taskDefinitions,
- appFinderCatalog: appFinderCatalog,
- maxSkills: maxSkills
- )
- return LocalAppTaskSkillContext(
- snippets: descriptors.map {
- BuiltInLocalAppSkillPacks.instructionSnippet(for: $0)
- }
+ appFinderCatalog: appFinderCatalog
)
+ guard !ranked.isEmpty else {
+ return LocalAppTaskSkillContext(snippets: [])
+ }
+
+ let catalogEntries = ranked.prefix(max(1, maxSkills)).map(\.descriptor)
+ let catalog = (["Available skills (pick the most relevant for the request; load it with skill.load to get its full steps):"]
+ + catalogEntries.map(discoveryLine(for:)))
+ .joined(separator: "\n")
+
+ var snippets = [catalog]
+ if let top = ranked.first, top.score > 0 {
+ snippets.append(BuiltInLocalAppSkillPacks.instructionSnippet(for: top.descriptor, maxCharacters: detailCharacters))
+ }
+ return LocalAppTaskSkillContext(snippets: snippets)
}
- private static func selectedBuiltInSkillDescriptors(
+ /// One compact catalog line for discovery: `- <id>: <summary> (tags: a, b)`.
+ private static func discoveryLine(for descriptor: HarnessSkillDescriptor) -> String {
+ let tags = descriptor.tags.isEmpty ? "" : " (tags: \(descriptor.tags.joined(separator: ", ")))"
+ return "- \(descriptor.id): \(descriptor.summary)\(tags)"
+ }
+
+ private static func rankedBuiltInSkillDescriptors(
+ command: String,
taskDefinitions: [LocalAppTaskDefinition],
- appFinderCatalog: [LocalAppFinderCatalogEntry],
- maxSkills: Int
- ) -> [HarnessSkillDescriptor] {
+ appFinderCatalog: [LocalAppFinderCatalogEntry]
+ ) -> [(descriptor: HarnessSkillDescriptor, score: Int)] {
let descriptors = BuiltInLocalAppSkillPacks.descriptors()
guard !descriptors.isEmpty else { return [] }
@@ -130,13 +155,20 @@ public struct LocalAppTaskSkillContext: Equatable, Sendable {
}
}
let catalogTokens = tokens(in: catalogValues.joined(separator: " "))
- let availableTokens = taskTokens.union(catalogTokens)
- let scored: [(descriptor: HarnessSkillDescriptor, score: Int)] = descriptors.map { descriptor in
+ // The user's actual request is the strongest signal for which skills the task needs, so
+ // weight command matches heavily. Without this, selection only reflects installed apps and
+ // static task definitions, which can miss (or arbitrarily pick) the skill the task requires.
+ let commandTokens = tokens(in: command)
+ let availableTokens = taskTokens.union(catalogTokens).union(commandTokens)
+ return descriptors.map { descriptor in
+ // Score over id, name, summary, tags, and the file-based `keywords:` trigger words.
let descriptorTokens = tokens(
- in: ([descriptor.id, descriptor.name, descriptor.summary] + descriptor.tags)
+ in: ([descriptor.id, descriptor.name, descriptor.summary, descriptor.metadata["keywords"] ?? ""]
+ + descriptor.tags)
.joined(separator: " ")
)
let score = descriptorTokens.intersection(availableTokens).count
+ + 3 * descriptorTokens.intersection(commandTokens).count
return (descriptor: descriptor, score: score)
}
.sorted {
@@ -145,13 +177,6 @@ public struct LocalAppTaskSkillContext: Equatable, Sendable {
}
return $0.score > $1.score
}
-
- let matching = scored.filter { $0.score > 0 }.map { $0.descriptor }
- if !matching.isEmpty {
- return Array(matching.prefix(max(0, maxSkills)))
- }
-
- return Array(descriptors.prefix(max(0, maxSkills)))
}
private static func tokens(in value: String) -> Set<String> {