Skip to content

Open source CapCut alternative.

TypeScript

feat(app): suggest workspace folder name from request understanding

David Le79b8ce41919a
diff --git a/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift b/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift
index 783308ec..bcb225e6 100644
--- a/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift
+++ b/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift
@@ -178,6 +178,7 @@ public enum DonkeyPrompts {
in a sentence or three. This is what they will read, so make it complete on its own. When the turn
is "converse", output this field FIRST in the JSON so it can stream to the user immediately. Leave
it empty for "act" and "clarify" — those are handled elsewhere.
+ - suggestedFolderName: for "act" turns, suggest a beautiful, spelling-corrected, and user-friendly root folder name for this task by strictly following the authoritative naming rules in the "Creating and Naming Folders and Files" section of the "finder" skill (e.g. spelling corrected, space-separated words, and ending with a capitalized friendly word hash like "Cozy"). Empty/nil for "converse" and "clarify" turns.
Return JSON only.
"""
diff --git a/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift b/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift
index e64c23da..2b3851c1 100644
--- a/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift
+++ b/apps/Donkey/Sources/DonkeyAI/HostedHarnessRequestUnderstanding.swift
@@ -1,4 +1,5 @@
import DonkeyContracts
+import DonkeyRuntime
import Foundation
/// A focused, one-shot "understand the request" boundary that runs ONCE before the harness loop.
@@ -58,6 +59,8 @@ public struct HarnessRequestUnderstanding: Sendable, Equatable, Codable {
/// fresh turn and still routes a multi-turn follow-up through the context-aware responder. Empty/nil for
/// `.act` and `.clarify`.
public var conversationReply: String?
+ /// A custom suggested root folder name for this task, generated strictly following the finder skill's rules.
+ public var suggestedFolderName: String?
public init(
turnKind: HarnessTurnKind = .act,
@@ -71,7 +74,8 @@ public struct HarnessRequestUnderstanding: Sendable, Equatable, Codable {
clarifyingQuestion: String? = nil,
executionPreference: ExecutionPreference = .background,
relevantSkillIDs: [String] = [],
- conversationReply: String? = nil
+ conversationReply: String? = nil,
+ suggestedFolderName: String? = nil
) {
self.turnKind = turnKind
self.restatedGoal = restatedGoal
@@ -85,6 +89,7 @@ public struct HarnessRequestUnderstanding: Sendable, Equatable, Codable {
self.executionPreference = executionPreference
self.relevantSkillIDs = relevantSkillIDs
self.conversationReply = conversationReply
+ self.suggestedFolderName = suggestedFolderName
}
/// Serialize to a compact JSON string for persistence (e.g. the root agent's metadata), so a later
@@ -133,10 +138,15 @@ public final class HostedHarnessRequestUnderstanding {
skillCatalog: String? = nil,
attachments: [HarnessAttachmentInfo] = []
) async -> HarnessRequestUnderstanding? {
+ var augmentedCatalog = skillCatalog ?? ""
+ if let finderGuidance = BuiltInLocalAppSkillPacks.skillGuidance(forID: "finder") {
+ let guidanceBlock = "\n\nAUTHORITATIVE WORKSPACE FILE/FOLDER NAMING PLAYBOOK (from Finder skill):\n\(finderGuidance)\n"
+ augmentedCatalog += guidanceBlock
+ }
let prompt = DonkeyPrompts.requestUnderstanding(
command: command,
frontmostAppName: frontmostAppName,
- skillCatalog: skillCatalog,
+ skillCatalog: augmentedCatalog.isEmpty ? nil : augmentedCatalog,
attachments: attachments
)
for _ in 0..<Self.maxAttempts {
@@ -146,7 +156,7 @@ public final class HostedHarnessRequestUnderstanding {
responseRequest(
command: command,
frontmostAppName: frontmostAppName,
- skillCatalog: skillCatalog,
+ skillCatalog: augmentedCatalog.isEmpty ? nil : augmentedCatalog,
attachments: attachments
)
)
@@ -200,10 +210,15 @@ public final class HostedHarnessRequestUnderstanding {
attachments: [HarnessAttachmentInfo] = [],
onReplyDelta: @escaping @MainActor @Sendable (String) -> Void
) async -> HarnessRequestUnderstanding? {
+ var augmentedCatalog = skillCatalog ?? ""
+ if let finderGuidance = BuiltInLocalAppSkillPacks.skillGuidance(forID: "finder") {
+ let guidanceBlock = "\n\nAUTHORITATIVE WORKSPACE FILE/FOLDER NAMING PLAYBOOK (from Finder skill):\n\(finderGuidance)\n"
+ augmentedCatalog += guidanceBlock
+ }
let prompt = DonkeyPrompts.requestUnderstanding(
command: command,
frontmostAppName: frontmostAppName,
- skillCatalog: skillCatalog,
+ skillCatalog: augmentedCatalog.isEmpty ? nil : augmentedCatalog,
attachments: attachments
)
let startedAt = RunTraceTimestamp.now()
@@ -269,6 +284,9 @@ public final class HostedHarnessRequestUnderstanding {
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
.filter { !$0.isEmpty },
conversationReply: wire.conversationReply
+ .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
+ .flatMap { $0.isEmpty ? nil : $0 },
+ suggestedFolderName: wire.suggestedFolderName
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
.flatMap { $0.isEmpty ? nil : $0 }
)
@@ -308,10 +326,11 @@ public final class HostedHarnessRequestUnderstanding {
var executionPreference: String?
var relevantSkillIDs: [String]?
var conversationReply: String?
+ var suggestedFolderName: String?
private enum CodingKeys: String, CodingKey {
case turnKind, restatedGoal, targetAppName, actionSurface, parameters, successCriteria, plan, needsClarification, clarifyingQuestion
- case executionPreference, relevantSkillIDs, conversationReply
+ case executionPreference, relevantSkillIDs, conversationReply, suggestedFolderName
}
init(from decoder: Decoder) throws {
@@ -327,6 +346,7 @@ public final class HostedHarnessRequestUnderstanding {
executionPreference = try container.decodeIfPresent(String.self, forKey: .executionPreference)
relevantSkillIDs = try container.decodeIfPresent([String].self, forKey: .relevantSkillIDs)
conversationReply = try container.decodeIfPresent(String.self, forKey: .conversationReply)
+ suggestedFolderName = try container.decodeIfPresent(String.self, forKey: .suggestedFolderName)
// 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)?
@@ -422,7 +442,8 @@ public final class HostedHarnessRequestUnderstanding {
"type": .string("array"),
"items": .object(["type": .string("string")])
]),
- "conversationReply": .object(["type": .string("string")])
+ "conversationReply": .object(["type": .string("string")]),
+ "suggestedFolderName": .object(["type": .string("string")])
])
])
])
diff --git a/apps/Donkey/Sources/DonkeyHarness/ConversationWorkspace.swift b/apps/Donkey/Sources/DonkeyHarness/ConversationWorkspace.swift
index 24900c81..541f893e 100644
--- a/apps/Donkey/Sources/DonkeyHarness/ConversationWorkspace.swift
+++ b/apps/Donkey/Sources/DonkeyHarness/ConversationWorkspace.swift
@@ -320,13 +320,22 @@ public struct ConversationWorkspace: Codable, Equatable, Sendable {
/// `<parent>` is the user's chosen output location (Downloads by default). The goal slug makes the
/// folder recognizable; the short conversation id keeps two similar goals apart. Pure (string math on
/// the parent path); the caller creates the directory on disk.
- public static func defaultRootPath(goal: String, conversationID: String) -> String {
- let slug = self.slug(goal)
- let shortID = conversationID
- .lowercased()
- .filter { $0.isLetter || $0.isNumber }
- .prefix(8)
- let name = slug.isEmpty ? "task-\(shortID)" : "\(slug)-\(shortID)"
+ public static func defaultRootPath(goal: String, conversationID: String, suggestedFolderName: String? = nil) -> String {
+ let name: String
+ if let suggestedFolderName = suggestedFolderName, !suggestedFolderName.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
+ name = suggestedFolderName
+ .replacingOccurrences(of: "/", with: "-")
+ .replacingOccurrences(of: ":", with: "-")
+ .replacingOccurrences(of: "\0", with: "")
+ .trimmingCharacters(in: .whitespacesAndNewlines)
+ } else {
+ let slug = self.slug(goal)
+ let shortID = conversationID
+ .lowercased()
+ .filter { $0.isLetter || $0.isNumber }
+ .prefix(8)
+ name = slug.isEmpty ? "task-\(shortID)" : "\(slug)-\(shortID)"
+ }
return workspaceParentDirectory().appendingPathComponent(name, isDirectory: true).path
}
diff --git a/apps/Donkey/Sources/DonkeyHarness/GenericHarnessCoordinator.swift b/apps/Donkey/Sources/DonkeyHarness/GenericHarnessCoordinator.swift
index 02d9e978..6a193178 100644
--- a/apps/Donkey/Sources/DonkeyHarness/GenericHarnessCoordinator.swift
+++ b/apps/Donkey/Sources/DonkeyHarness/GenericHarnessCoordinator.swift
@@ -682,7 +682,21 @@ public actor HarnessAgentCoordinator {
if let root = workspace.root, !root.isEmpty, FileManager.default.fileExists(atPath: root) {
return
}
- let path = ConversationWorkspace.defaultRootPath(goal: task.goal, conversationID: conversationID)
+ var suggestedFolderName: String? = nil
+ if let jsonStr = task.metadata["harness.understandingJSON"],
+ let jsonData = jsonStr.data(using: .utf8) {
+ struct MiniUnderstanding: Decodable {
+ var suggestedFolderName: String?
+ }
+ if let mini = try? JSONDecoder().decode(MiniUnderstanding.self, from: jsonData) {
+ suggestedFolderName = mini.suggestedFolderName
+ }
+ }
+ let path = ConversationWorkspace.defaultRootPath(
+ goal: task.goal,
+ conversationID: conversationID,
+ suggestedFolderName: suggestedFolderName
+ )
// Mark attempted before the syscall so a failure isn't retried every step (see the guard above).
workspaceRootAttempted.insert(agentID)
do {
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/ConversationWorkspaceTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/ConversationWorkspaceTests.swift
index 74abf025..a325e718 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/ConversationWorkspaceTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/ConversationWorkspaceTests.swift
@@ -127,6 +127,30 @@ struct ConversationWorkspaceStructTests {
#expect(name == "fill-out-the-f1120-pdf-form-ab12cd34")
}
+ @Test
+ func defaultRootPathHonorsSuggestedFolderName() {
+ let path = ConversationWorkspace.defaultRootPath(
+ goal: "Fill out the f1120.pdf form!",
+ conversationID: "AB12CD34-9999",
+ suggestedFolderName: "Fill out f1120 Cozy"
+ )
+ let parent = ConversationWorkspace.workspaceParentDirectory().path
+ #expect(path.hasPrefix(parent + "/"))
+ let name = (path as NSString).lastPathComponent
+ #expect(name == "Fill out f1120 Cozy")
+ }
+
+ @Test
+ func defaultRootPathSanitizesSuggestedFolderName() {
+ let path = ConversationWorkspace.defaultRootPath(
+ goal: "Fill out the f1120.pdf form!",
+ conversationID: "AB12CD34-9999",
+ suggestedFolderName: "Fill / out: f1120\0 Cozy"
+ )
+ let name = (path as NSString).lastPathComponent
+ #expect(name == "Fill - out- f1120 Cozy")
+ }
+
@Test
func slugSanitizesAndBounds() {
#expect(ConversationWorkspace.slug("Hello, World! 2025") == "hello-world-2025")
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HostedHarnessRequestUnderstandingTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HostedHarnessRequestUnderstandingTests.swift
index 4691d03e..11e6d2f8 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/HostedHarnessRequestUnderstandingTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HostedHarnessRequestUnderstandingTests.swift
@@ -63,6 +63,14 @@ struct HostedHarnessRequestUnderstandingTests {
#expect(result?.actionSurface == .appless)
}
+ @Test
+ func decodesSuggestedFolderName() async {
+ let result = await understanding(forResponseJSON: #"""
+ {"turnKind":"act","restatedGoal":"Fill out f1120 pdf.","needsClarification":false,"suggestedFolderName":"Fill out f1120 Cozy"}
+ """#)
+ #expect(result?.suggestedFolderName == "Fill out f1120 Cozy")
+ }
+
@Test
func aMissingActionSurfaceDefaultsToGuiApp() async {
// An older model or partial output omits the field; the conservative default is the GUI path, so a
@@ -88,12 +96,14 @@ struct HostedHarnessRequestUnderstandingTests {
plan: ["read the data", "list the form's fields", "map and compute", "write", "verify"],
needsClarification: false,
executionPreference: .background,
- relevantSkillIDs: ["pdf", "data"]
+ relevantSkillIDs: ["pdf", "data"],
+ suggestedFolderName: "Fill out f1120 Cozy"
)
let decoded = HarnessRequestUnderstanding.decode(original.encodedJSON())
#expect(decoded == original)
+ #expect(decoded?.suggestedFolderName == "Fill out f1120 Cozy")
// The exact failure the reuse prevents: a resume that recomputed re-typed `pdf_path` as `pdf_form`.
#expect(decoded?.parameters["pdf_path"] == "f1120.pdf")
#expect(decoded?.parameters["pdf_form"] == nil)