Skip to content

Open source CapCut alternative.

TypeScript

fix(app): carry tool failure detail in the summaries the planner reads

David Le84f7a00c2cec
diff --git a/apps/Donkey/Sources/DonkeyRuntime/DonkeyCommandBackends.swift b/apps/Donkey/Sources/DonkeyRuntime/DonkeyCommandBackends.swift
index fd79bf6d..5ce6f229 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/DonkeyCommandBackends.swift
+++ b/apps/Donkey/Sources/DonkeyRuntime/DonkeyCommandBackends.swift
@@ -103,8 +103,14 @@ public enum DonkeyCommandBackends {
guard let app = trimmed(context.call.input["app"]) else {
return invalidInput(context, "app_skill requires an `app` display name or bundle identifier.")
}
+ // On-demand reads return the FULL playbook: app_skill is the model deliberately loading the
+ // guide, unlike the per-step ambient guidance which stays at the default 4k prompt budget.
guard let descriptor = BuiltInLocalAppSkillPacks.appSkillDescriptor(forApp: app, bundleIdentifier: app),
- let guidance = BuiltInLocalAppSkillPacks.appOperatingGuidance(forApp: app, bundleIdentifier: app)
+ let guidance = BuiltInLocalAppSkillPacks.appOperatingGuidance(
+ forApp: app,
+ bundleIdentifier: app,
+ maxCharacters: 12_000
+ )
else {
return success(
context,
@@ -410,13 +416,24 @@ public enum DonkeyCommandBackends {
let stdout = boundedOutput(result.stdout)
guard result.exitCode == 0 else {
let stderr = boundedOutput(result.stderr)
+ // The summary is what the model reads next step; a bare exit code hides WHY the command
+ // failed (e.g. an osascript error naming the real problem) and leaves the planner
+ // guessing, so carry the error text in it.
+ var failureLines = [
+ result.timedOut
+ ? "Command timed out after \(Int(timeout))s and was terminated. Pass timeoutSeconds (max \(Int(shellTimeoutMax))) for known-slow commands."
+ : "Command exited with code \(result.exitCode)."
+ ]
+ if !stderr.text.isEmpty {
+ failureLines.append("stderr: " + String(stderr.text.prefix(500)))
+ } else if !stdout.text.isEmpty {
+ failureLines.append("stdout: " + String(stdout.text.prefix(500)))
+ }
return HarnessToolResult(
callID: context.call.id,
toolName: context.call.name,
status: .failed,
- summary: result.timedOut
- ? "Command timed out after \(Int(timeout))s and was terminated. Pass timeoutSeconds (max \(Int(shellTimeoutMax))) for known-slow commands."
- : "Command exited with code \(result.exitCode).",
+ summary: failureLines.joined(separator: "\n"),
metadata: [
"executor": "donkeyCommandLayer",
"reason": result.timedOut ? "timedOut" : "nonZeroExit",
diff --git a/apps/Donkey/Sources/DonkeyRuntime/LocalAppUserQueryHarnessServices.swift b/apps/Donkey/Sources/DonkeyRuntime/LocalAppUserQueryHarnessServices.swift
index 727c7116..b007b2f9 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/LocalAppUserQueryHarnessServices.swift
+++ b/apps/Donkey/Sources/DonkeyRuntime/LocalAppUserQueryHarnessServices.swift
@@ -1,8 +1,11 @@
import DonkeyContracts
import DonkeyHarness
import Foundation
+import os
public enum LocalAppUserQueryHarnessServices {
+ private static let logger = Logger(subsystem: "com.donkey.app", category: "skill-script")
+
public static func builtInSkillBackedServices() -> HarnessBuiltInToolServices {
HarnessBuiltInToolServices(
skillRegistry: HarnessSkillRegistry(skills: BuiltInLocalAppSkillPacks.descriptors()),
@@ -125,11 +128,18 @@ public enum LocalAppUserQueryHarnessServices {
let scriptStatus = outputMetadata["status"]
let statusReportsFailure = scriptStatus == "not_found" || scriptStatus == "failed"
let succeeded = result.executed && !clarificationRequired && !statusReportsFailure
+ let summary = skillScriptSummary(
+ succeeded: succeeded,
+ executed: result.executed,
+ output: output,
+ error: result.metadata["appleScript.error"] ?? ""
+ )
+ logger.log(
+ "skill script result skillID=\(artifact.ownerSkillID ?? "", privacy: .public) scriptID=\(artifact.id, privacy: .public) executed=\(result.executed) succeeded=\(succeeded) status=\(scriptStatus ?? "", privacy: .public) error=\(result.metadata["appleScript.error"] ?? "", privacy: .public)"
+ )
return HarnessScriptExecutionOutcome(
succeeded: succeeded,
- summary: succeeded
- ? "Skill script executed successfully."
- : "Skill script did not complete successfully.",
+ summary: summary,
output: output,
metadata: result.metadata.merging(outputMetadata) { current, _ in current }.merging([
"skillID": artifact.ownerSkillID ?? "",
@@ -139,6 +149,28 @@ public enum LocalAppUserQueryHarnessServices {
)
}
+ /// The summary is the tool-result body the planner actually reads each step (history lines and
+ /// the thread both carry it; the structured output only lands in world-model facts). A skill
+ /// script's whole feedback loop — `status=not_found` → escalate to vision instead of retrying —
+ /// depends on its self-report traveling in this string, so never collapse a failure to a generic
+ /// one-liner.
+ public static func skillScriptSummary(
+ succeeded: Bool,
+ executed: Bool,
+ output: String,
+ error: String
+ ) -> String {
+ if !executed && output.isEmpty {
+ let detail = error.isEmpty ? "no output" : String(error.prefix(300))
+ return "Skill script errored before reporting a status: \(detail)"
+ }
+ let headline = succeeded
+ ? "Skill script succeeded."
+ : "Skill script ran but reported the goal was not achieved — read its status below and adjust your approach; do not repeat the same call."
+ guard !output.isEmpty else { return headline }
+ return headline + "\nScript report:\n" + String(output.prefix(500))
+ }
+
private static func structuredOutputMetadata(_ output: String) -> [String: String] {
var metadata: [String: String] = [:]
let fields = output
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/GenericHarnessTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/GenericHarnessTests.swift
index 1e9d3b15..9e989749 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/GenericHarnessTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/GenericHarnessTests.swift
@@ -642,6 +642,40 @@ struct GenericHarnessTests {
#expect(script?.language == .appleScript)
}
+ /// The summary is the tool-result body the planner reads, so a skill script's structured
+ /// self-report (`status=not_found`, `escalate.goal=…`) must travel inside it — collapsing a
+ /// failure to a generic one-liner left the planner retrying the identical call instead of
+ /// escalating to vision.
+ @Test
+ func skillScriptSummaryCarriesTheScriptSelfReport() {
+ let notFound = LocalAppUserQueryHarnessServices.skillScriptSummary(
+ succeeded: false,
+ executed: true,
+ output: "status=not_found\nquery=Baby Don't Cry\nescalate.app=Music\nescalate.goal=Play the top song result",
+ error: ""
+ )
+ #expect(notFound.contains("status=not_found"))
+ #expect(notFound.contains("escalate.goal=Play the top song result"))
+ #expect(notFound.contains("do not repeat the same call"))
+
+ let hardError = LocalAppUserQueryHarnessServices.skillScriptSummary(
+ succeeded: false,
+ executed: false,
+ output: "",
+ error: "Music got an error: AppleEvent timed out."
+ )
+ #expect(hardError.contains("AppleEvent timed out"))
+
+ let played = LocalAppUserQueryHarnessServices.skillScriptSummary(
+ succeeded: true,
+ executed: true,
+ output: "status=played\nplayedTitle=Baby Don't Cry\nplayedArtist=EXO",
+ error: ""
+ )
+ #expect(played.contains("succeeded"))
+ #expect(played.contains("playedTitle=Baby Don't Cry"))
+ }
+
@Test
func skillScriptExecuteUsesStructuredOutcomeForSuccessAndClarification() async throws {
let generatedScripts = HarnessGeneratedScriptStore(artifacts: [