Skip to content

Open source CapCut alternative.

TypeScript

fix(app): report a script's own status block as the shell tool summary

David Le8e5887812e40
diff --git a/apps/Donkey/Sources/DonkeyRuntime/DonkeyCommandBackends.swift b/apps/Donkey/Sources/DonkeyRuntime/DonkeyCommandBackends.swift
index 47a89b73..fd79bf6d 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/DonkeyCommandBackends.swift
+++ b/apps/Donkey/Sources/DonkeyRuntime/DonkeyCommandBackends.swift
@@ -335,9 +335,19 @@ public enum DonkeyCommandBackends {
]) { current, _ in current }
)
}
+ // Surface the script's OWN structured status block (e.g. `status=played\nplayedTitle=…\n
+ // playedArtist=…`) as the summary, not a generic "executed successfully". The script already
+ // verified its effect and reported it; showing that to the planner is the evidence it needs to
+ // run.complete directly, instead of reaching for a second tool to re-verify (which is where the
+ // run was looping). Falls back to the generic summary when the script reports nothing.
+ let status = outcome.output
+ .split(whereSeparator: { $0 == "\n" || $0 == "\r" })
+ .map { $0.trimmingCharacters(in: .whitespaces) }
+ .filter { !$0.isEmpty }
+ .joined(separator: "; ")
return success(
context,
- summary: outcome.summary,
+ summary: status.isEmpty ? outcome.summary : status,
facts: ["skillRun.\(scriptID)": outcome.metadata["status"] ?? "succeeded"],
metadata: outcome.metadata
)
@@ -345,8 +355,12 @@ public enum DonkeyCommandBackends {
// MARK: - shell_exec
- /// Max characters accepted for a one-line command.
- private static let shellCommandMaxLength = 400
+ /// Max characters accepted for a one-line command. Sized for real `osascript` one-liners: a
+ /// macOS temp path (e.g. an `llm.generate` file under `/var/folders/.../T/`) is ~100 chars on its
+ /// own, and a multi-`-e` AppleScript that reads such a file into Notes/Mail/Calendar runs to
+ /// ~450+ chars before any content. A tighter cap silently rejected those legitimate commands; the
+ /// bound stays only as a backstop against pathological inline payloads.
+ private static let shellCommandMaxLength = 1_500
/// Seconds before a command is terminated when the call does not set its own budget.
private static let shellTimeout: TimeInterval = 12
/// Upper bound for a caller-provided `timeoutSeconds`, so a planner mistake can never hang a run.
@@ -369,7 +383,12 @@ public enum DonkeyCommandBackends {
return invalidInput(context, "shell_exec only runs a single-line command.")
}
guard command.count <= shellCommandMaxLength else {
- return invalidInput(context, "shell_exec command is too long.")
+ return invalidInput(
+ context,
+ "shell_exec command is \(command.count) chars; the limit is \(shellCommandMaxLength). "
+ + "Don't inline large content — generate it to a file with llm.generate (toFile=true), "
+ + "then run a short command that reads from that file."
+ )
}
// Classify by risk tier. Reads run immediately; anything that changes
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/ShellExecCommandTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/ShellExecCommandTests.swift
new file mode 100644
index 00000000..d481844b
--- /dev/null
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/ShellExecCommandTests.swift
@@ -0,0 +1,61 @@
+import DonkeyContracts
+import DonkeyHarness
+import DonkeyRuntime
+import Foundation
+import Testing
+
+@Suite
+struct ShellExecCommandTests {
+ @MainActor
+ private func shellExec(_ command: String) async -> HarnessToolResult? {
+ let descriptor = DonkeyCommandLayer.descriptors.first { $0.name == "shell_exec" }!
+ let context = HarnessToolExecutionContext(
+ taskID: "test",
+ call: HarnessToolCall(name: "shell_exec", input: ["command": command]),
+ descriptor: descriptor,
+ worldModel: HarnessWorldModel(),
+ grantedPermissions: []
+ )
+ return await DonkeyCommandBackends.makeExecutor()(context)
+ }
+
+ /// The exact "Long content" Notes path that used to fail: read a generated file from the real
+ /// macOS temp directory and create a note from it. The composed command is ~460 chars — over the
+ /// old 400-char cap — so it was rejected as "too long" and the run stalled into failedSafe. With
+ /// the cap raised for real osascript one-liners, the length guard must let it through (it should
+ /// not come back as the "too long" invalidInput).
+ @Test
+ @MainActor
+ func notesFromFileCommandClearsLengthGuard() async {
+ let filePath = FileManager.default.temporaryDirectory
+ .appendingPathComponent("donkey-llm-\(UUID().uuidString).txt").path
+ let command =
+ "osascript -e 'set f to (read POSIX file \"\(filePath)\" as «class utf8»)'"
+ + " -e 'set AppleScript'\"'\"'s text item delimiters to (ASCII character 10)'"
+ + " -e 'set parts to text items of f'"
+ + " -e 'set AppleScript'\"'\"'s text item delimiters to \"<br>\"'"
+ + " -e 'tell application \"Notes\" to make new note"
+ + " with properties {name:\"Taylor Swift — The Tortured Poets Department\", body:(parts as text)}'"
+
+ #expect(command.count > 400, "fixture must exceed the old cap to be a real regression")
+ #expect(command.count <= 1_500)
+
+ let result = await shellExec(command)
+ // It must clear the length guard. Past it the outcome depends on the environment's shell
+ // consent (a gate when not yet granted, otherwise it runs and fails on the missing fixture
+ // file) — but it is never the `invalidInput` "too long" rejection that used to stall the run.
+ #expect(result?.status != .invalidInput)
+ }
+
+ /// A genuinely oversized inline command is still rejected — but now with an actionable message
+ /// that names the limit and points at the llm.generate(toFile) + read-from-file pattern.
+ @Test
+ @MainActor
+ func oversizedCommandIsRejectedWithActionableMessage() async {
+ let command = "echo " + String(repeating: "x", count: 1_600)
+ let result = await shellExec(command)
+ #expect(result?.status == .invalidInput)
+ #expect(result?.summary.contains("the limit is 1500") == true)
+ #expect(result?.summary.contains("llm.generate") == true)
+ }
+}