Skip to content

Open source CapCut alternative.

TypeScript

feat(app): narrate each harness step in a warm first-person voice

David Leb3efa93e6e4c
diff --git a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift
index 0b43081a..11ee1607 100644
--- a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift
+++ b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift
@@ -506,14 +506,14 @@ struct LocalAppUserQueryCommandHandler: UserQueryCommandHandling {
if let result = step.toolResult {
// One grouped block per step through the trace manager: the model's full thought
// summary (persisted here and nowhere else, so the planning context stays bounded),
- // its one-line reason, the action with its input, the output, any planning retries
+ // its warm one-line narration, the action with its input, the output, any planning retries
// hit while choosing this step, and the timing the manager attaches — decision time
// vs. tool time plus which sensing modality the step used. The overlay/progress gets
// only the clipped one-line narration below.
trace.recordStep(
number: step.task.toolHistory.count,
thought: planner.lastThinking,
- reason: planner.lastNarration,
+ narration: planner.lastNarration,
tool: result.toolName,
input: step.task.toolHistory.last?.call.input ?? [:],
status: result.status.rawValue,
diff --git a/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift b/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift
index 44b12b9e..cbe594ab 100644
--- a/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift
+++ b/apps/Donkey/Sources/DonkeyAI/DonkeyPrompts.swift
@@ -272,8 +272,16 @@ public enum DonkeyPrompts {
not the process: what is now true ("Playing Yellow by Coldplay"), not the steps taken.
Never fake completion — if the goal could not be reached, say plainly what happened and
the most likely reason, with any caveat the user needs.
- Return JSON: {"tool": "<one tool name>", "input": {"key": "value", ...}, "reason": "<one sentence>"}. \
- ALWAYS include "input" with every required field for the chosen tool filled, exactly as its schema names them; use {} only for a tool that needs no input.\(retryNote.map { "\nIMPORTANT: \($0)" } ?? "")
+ Return JSON: {"tool": "<one tool name>", "input": {"key": "value", ...}, "narration": "<one warm sentence>"}. \
+ ALWAYS include "input" with every required field for the chosen tool filled, exactly as its schema names them; use {} only for a tool that needs no input.
+ "narration" is the one line the user reads for this step, shown live and saved to the conversation. \
+ Write it in the first person, present or near tense, as if you were narrating your work to the person \
+ watching — warm and plain, never robotic ("I'll start by reading the attached screenshots and finding \
+ the relevant notch UI code.", "Let me check what's already on screen before I click.", "Found the file — \
+ now I'll make the edit."). Say what you're doing this step and why in one breath. This narrates the \
+ process; it is NOT the result. Reporting what is now true for the user is done only in conversation.respond \
+ and run.complete, which still report the result, not the steps. Keep narration to one sentence; do not \
+ restate the whole plan or repeat the previous step.\(retryNote.map { "\nIMPORTANT: \($0)" } ?? "")
"""
}
diff --git a/apps/Donkey/Sources/DonkeyAI/HostedHarnessStepPlanner.swift b/apps/Donkey/Sources/DonkeyAI/HostedHarnessStepPlanner.swift
index ad6888ad..1f6112f2 100644
--- a/apps/Donkey/Sources/DonkeyAI/HostedHarnessStepPlanner.swift
+++ b/apps/Donkey/Sources/DonkeyAI/HostedHarnessStepPlanner.swift
@@ -46,7 +46,8 @@ public final class HostedHarnessStepPlanner: HarnessNextStepPlanning {
/// state, i.e. not a read-only observation). The route turns this into the "time to first action"
/// telemetry; nil until the first action is planned.
public private(set) var firstActionUptimeMS: Double?
- /// Most recent one-line rationale, surfaced to the user as the run's narration.
+ /// The most recent step's warm, first-person narration line, surfaced live to the user and saved to
+ /// the conversation record as the run's account of what it is doing.
public private(set) var lastNarration: String?
/// The model's full thought summary for the most recent step, when thinking is enabled. Persisted
/// to the thread transcript (not fed back into the per-step prompt, so context stays bounded).
@@ -134,7 +135,7 @@ public final class HostedHarnessStepPlanner: HarnessNextStepPlanning {
retryNote = Self.retryNote(after: error)
continue
}
- lastNarration = decision.reason.flatMap { $0.isEmpty ? nil : $0 } ?? lastNarration
+ lastNarration = decision.narration.flatMap { $0.isEmpty ? nil : $0 } ?? lastNarration
lastThinking = decision.thinking.flatMap { $0.isEmpty ? nil : $0 }
guard let toolName = decision.tool.flatMap({ $0.isEmpty ? nil : $0 }) else {
lastPlanningErrors.append(
@@ -232,9 +233,10 @@ public final class HostedHarnessStepPlanner: HarnessNextStepPlanning {
private struct Decision: Sendable {
var tool: String?
var input: [String: String]?
- var reason: String?
+ var narration: String?
/// The model's full thought summary for this step (thinking enabled), persisted to the thread.
- /// Separate from `reason`, which is the one-line rationale shown live in the overlay.
+ /// Separate from `narration`, which is the warm one-line account of the step shown live and saved
+ /// to the conversation record.
var thinking: String?
/// The reply's decision JSON as received, kept for failure diagnostics (e.g. proving whether
/// a missing tool input was omitted by the model or lost in response mapping).
@@ -244,14 +246,14 @@ public final class HostedHarnessStepPlanner: HarnessNextStepPlanning {
private struct DecisionWire: Decodable {
var tool: String?
var input: [String: String]?
- var reason: String?
+ var narration: String?
- private enum CodingKeys: String, CodingKey { case tool, input, reason }
+ private enum CodingKeys: String, CodingKey { case tool, input, narration }
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
tool = try container.decodeIfPresent(String.self, forKey: .tool)
- reason = try container.decodeIfPresent(String.self, forKey: .reason)
+ narration = try container.decodeIfPresent(String.self, forKey: .narration)
// The response schema is non-strict, so the model can emit a numeric or boolean input value
// (e.g. {"elementID": 3}). Coerce scalars to strings instead of failing the whole turn.
input = try container.decodeIfPresent([String: ScalarString].self, forKey: .input)?
@@ -397,7 +399,7 @@ public final class HostedHarnessStepPlanner: HarnessNextStepPlanning {
return Decision(
tool: wire.tool,
input: wire.input,
- reason: wire.reason,
+ narration: wire.narration,
thinking: RemoteInferenceResponseHelpers.reasoningText(from: response),
raw: json
)
diff --git a/apps/Donkey/Sources/DonkeyRuntime/HarnessTurnTrace.swift b/apps/Donkey/Sources/DonkeyRuntime/HarnessTurnTrace.swift
index 64be5b1b..7091a292 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/HarnessTurnTrace.swift
+++ b/apps/Donkey/Sources/DonkeyRuntime/HarnessTurnTrace.swift
@@ -67,7 +67,7 @@ public final class HarnessTurnTrace: HarnessTurnTracing, @unchecked Sendable {
public func recordStep(
number: Int,
thought: String?,
- reason: String?,
+ narration: String?,
tool: String,
input: [String: String],
status: String,
@@ -87,7 +87,7 @@ public final class HarnessTurnTrace: HarnessTurnTracing, @unchecked Sendable {
transcript.step(
number: number,
thought: thought,
- reason: reason,
+ narration: narration,
tool: tool,
input: input,
status: status,
diff --git a/apps/Donkey/Sources/DonkeyRuntime/ThreadTranscript.swift b/apps/Donkey/Sources/DonkeyRuntime/ThreadTranscript.swift
index 154b5ecf..acd3e1f5 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/ThreadTranscript.swift
+++ b/apps/Donkey/Sources/DonkeyRuntime/ThreadTranscript.swift
@@ -2,7 +2,7 @@ import Foundation
/// The canonical, human-readable record of a thread — the real conversation, the way ChatGPT or
/// Claude keeps one, not a debug dump. The user's request, session events, and the assistant's
-/// answer are flat entries; each executed step is one grouped block (the decision — thought, reason,
+/// answer are flat entries; each executed step is one grouped block (the decision — narration, thought,
/// action with its input — then that action's output), so the whole reasoning trace reads
/// decision → output → next decision.
///
@@ -102,7 +102,7 @@ public final class ThreadTranscript: @unchecked Sendable {
/// One executed step, rendered as a single grouped block so the trace reads decision → output →
/// next decision. The decision carries the model's full thought summary (bounded so a verbose
/// chain of thought can't bloat the file — it is persisted only here, never in the per-step
- /// planning prompt), its one-line reason, and the action with its complete input. Planning
+ /// planning prompt), its warm one-line narration, and the action with its complete input. Planning
/// retries hit while choosing this step open the block, so a step that needed recovery reads as
/// one unit instead of scattered entries. The thought is also where the model interprets the
/// previous step's output, so each block's output is reasoned about at the top of the next.
@@ -115,7 +115,7 @@ public final class ThreadTranscript: @unchecked Sendable {
public func step(
number: Int,
thought: String?,
- reason: String?,
+ narration: String?,
tool: String,
input: [String: String],
status: String,
@@ -133,12 +133,14 @@ public final class ThreadTranscript: @unchecked Sendable {
if !text.isEmpty { block += "\n⚠️ \(text)\n" }
}
block += "\n### 🧠 Decision\n"
+ // The warm, first-person narration leads the block — it's the line the user reads as the agent's
+ // own account of this step — with the fuller thought summary kept beneath it for the record.
+ if let narration = narration?.trimmingCharacters(in: .whitespacesAndNewlines), !narration.isEmpty {
+ block += "\n\(Self.clip(narration, 600))\n"
+ }
if let thought = thought?.trimmingCharacters(in: .whitespacesAndNewlines), !thought.isEmpty {
block += "\n**Thought:** \(Self.clip(thought, 4_000))\n"
}
- if let reason = reason?.trimmingCharacters(in: .whitespacesAndNewlines), !reason.isEmpty {
- block += "\n**Reason:** \(Self.clip(reason, 600))\n"
- }
block += "\n**Action:** `\(tool)`\n```\n\(Self.inputBody(input))\n```\n"
block += "\n### 📄 Output — `\(status)`\n\n```\n\(Self.clip(output, 2_000))\n```\n"
if let timing = Self.timingLine(
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessTurnTraceTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessTurnTraceTests.swift
index 14ed06bd..ce919b64 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessTurnTraceTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HarnessTurnTraceTests.swift
@@ -48,7 +48,7 @@ struct HarnessTurnTraceTests {
trace.recordStep(
number: 1,
thought: nil,
- reason: "Reading the screen.",
+ narration: "Reading the screen.",
tool: "vision.capture",
input: [:],
status: "succeeded",
@@ -81,7 +81,7 @@ struct HarnessTurnTraceTests {
trace.recordModelCall(plannerCall(attempt: 1, started: p0, ended: p1))
clock.advance(by: 50)
trace.recordStep(
- number: 1, thought: nil, reason: nil, tool: "ax.observe", input: [:],
+ number: 1, thought: nil, narration: nil, tool: "ax.observe", input: [:],
status: "succeeded", output: "ok", planningErrors: [], modality: .accessibility,
cacheHit: nil, elementCount: 7
)
@@ -103,7 +103,7 @@ struct HarnessTurnTraceTests {
trace.recordModelCall(plannerCall(attempt: 1, started: p0, ended: p1))
clock.advance(by: 20)
trace.recordStep(
- number: 1, thought: nil, reason: nil, tool: "shell_exec", input: ["command": "ls"],
+ number: 1, thought: nil, narration: nil, tool: "shell_exec", input: ["command": "ls"],
status: "succeeded", output: "ok", planningErrors: [], modality: .none,
cacheHit: true, elementCount: 99
)
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/HostedHarnessStepPlannerTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/HostedHarnessStepPlannerTests.swift
index 55d8a48e..a48c30fb 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/HostedHarnessStepPlannerTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/HostedHarnessStepPlannerTests.swift
@@ -186,8 +186,8 @@ struct HostedHarnessStepPlannerTests {
// A refusal or truncated reply decodes with no tool. That must re-ask once and then fail
// safe — never run.complete, which would record an unverified claim as success.
let httpClient = SequencedHTTPClient(responses: [
- (Data(#"{"output_text":"{\"tool\":\"\",\"reason\":\"cannot help\"}"}"#.utf8), 200),
- (Data(#"{"output_text":"{\"tool\":\"\",\"reason\":\"cannot help\"}"}"#.utf8), 200)
+ (Data(#"{"output_text":"{\"tool\":\"\",\"narration\":\"cannot help\"}"}"#.utf8), 200),
+ (Data(#"{"output_text":"{\"tool\":\"\",\"narration\":\"cannot help\"}"}"#.utf8), 200)
])
let planner = makePlanner(httpClient: httpClient, understanding: nil)
@@ -200,7 +200,7 @@ struct HostedHarnessStepPlannerTests {
@Test
func emptyToolNameRecoversWhenTheRetryNamesATool() async {
let httpClient = SequencedHTTPClient(responses: [
- (Data(#"{"output_text":"{\"tool\":\"\",\"reason\":\"unsure\"}"}"#.utf8), 200),
+ (Data(#"{"output_text":"{\"tool\":\"\",\"narration\":\"unsure\"}"}"#.utf8), 200),
(cannedDecision(tool: "ax.observe"), 200)
])
let planner = makePlanner(httpClient: httpClient, understanding: nil)
@@ -218,7 +218,7 @@ struct HostedHarnessStepPlannerTests {
// the legacy integer budget), and the model's thought summary (returned separately from
// output_text so it can't corrupt the decision JSON) is captured for the thread transcript.
let httpClient = FixtureHTTPClient(
- data: Data(#"{"output_text":"{\"tool\":\"ax.observe\",\"reason\":\"look first\"}","reasoning_text":"The window state is unknown, so I observe before acting."}"#.utf8),
+ data: Data(#"{"output_text":"{\"tool\":\"ax.observe\",\"narration\":\"look first\"}","reasoning_text":"The window state is unknown, so I observe before acting."}"#.utf8),
statusCode: 200
)
let planner = makePlanner(httpClient: httpClient, understanding: nil)
@@ -238,8 +238,8 @@ struct HostedHarnessStepPlannerTests {
// which only yields invalidInput and, repeated, fails the run. The planner must retry once with
// a corrective note, then use the corrected call.
let httpClient = SequencedHTTPClient(responses: [
- (Data(#"{"output_text":"{\"tool\":\"shell_exec\",\"reason\":\"verify\"}"}"#.utf8), 200),
- (Data(#"{"output_text":"{\"tool\":\"shell_exec\",\"input\":{\"command\":\"date\"},\"reason\":\"verify\"}"}"#.utf8), 200)
+ (Data(#"{"output_text":"{\"tool\":\"shell_exec\",\"narration\":\"verify\"}"}"#.utf8), 200),
+ (Data(#"{"output_text":"{\"tool\":\"shell_exec\",\"input\":{\"command\":\"date\"},\"narration\":\"verify\"}"}"#.utf8), 200)
])
let planner = HostedHarnessStepPlanner(
backend: DonkeyBackendInferenceClient(
@@ -279,7 +279,7 @@ struct HostedHarnessStepPlannerTests {
// yields invalidInput, which tells the model nothing the retry notes didn't. Each attempt's
// raw reply is recorded so the thread shows whether the model emitted an empty input object
// or the field was lost in response mapping.
- let inputlessReply = (Data(#"{"output_text":"{\"tool\":\"shell_exec\",\"reason\":\"verify\"}"}"#.utf8), 200)
+ let inputlessReply = (Data(#"{"output_text":"{\"tool\":\"shell_exec\",\"narration\":\"verify\"}"}"#.utf8), 200)
let httpClient = SequencedHTTPClient(responses: [inputlessReply, inputlessReply, inputlessReply])
let planner = HostedHarnessStepPlanner(
backend: DonkeyBackendInferenceClient(
@@ -423,7 +423,7 @@ struct HostedHarnessStepPlannerTests {
}
private func cannedDecision(tool: String) -> Data {
- Data(#"{"output_text":"{\"tool\":\"\#(tool)\",\"reason\":\"step\"}"}"#.utf8)
+ Data(#"{"output_text":"{\"tool\":\"\#(tool)\",\"narration\":\"step\"}"}"#.utf8)
}
private func requestBodyString(_ httpClient: FixtureHTTPClient, index: Int = 0) -> String {
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/MusicPlaylistLiveE2ETests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/MusicPlaylistLiveE2ETests.swift
index c01051ea..85d6d93f 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/MusicPlaylistLiveE2ETests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/MusicPlaylistLiveE2ETests.swift
@@ -139,7 +139,7 @@ struct MusicPlaylistLiveE2ETests {
transcript.step(
number: step.task.toolHistory.count,
thought: nil,
- reason: nil,
+ narration: nil,
tool: result.toolName,
input: step.task.toolHistory.last?.call.input ?? [:],
status: result.status.rawValue,
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/ThreadTranscriptTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/ThreadTranscriptTests.swift
index 694052f4..109884a4 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/ThreadTranscriptTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/ThreadTranscriptTests.swift
@@ -10,7 +10,7 @@ struct ThreadTranscriptTests {
transcript.step(
number: 3,
thought: "Search worked, so now I create the playlist container before adding songs.",
- reason: "Creating the \"Best of 2000\" playlist.",
+ narration: "Creating the \"Best of 2000\" playlist.",
tool: "music.playlist",
input: ["action": "create", "name": "Best of 2000"],
status: "failed",
@@ -23,7 +23,12 @@ struct ThreadTranscriptTests {
#expect(text.contains("⚠️ planning attempt 1/3"))
#expect(text.contains("### 🧠 Decision"))
#expect(text.contains("**Thought:** Search worked"))
- #expect(text.contains("**Reason:** Creating the \"Best of 2000\" playlist."))
+ // The narration is the warm lead line of the block — rendered plainly, not behind a label.
+ #expect(text.contains("\nCreating the \"Best of 2000\" playlist.\n"))
+ // It leads the decision block, above the fuller thought summary.
+ let narrationRange = try #require(text.range(of: "Creating the \"Best of 2000\" playlist."))
+ let thoughtRange = try #require(text.range(of: "**Thought:**"))
+ #expect(narrationRange.lowerBound < thoughtRange.lowerBound)
#expect(text.contains("**Action:** `music.playlist`"))
#expect(text.contains("action: create\nname: Best of 2000"))
#expect(text.contains("### 📄 Output — `failed`"))
@@ -36,12 +41,12 @@ struct ThreadTranscriptTests {
}
@Test
- func stepOmitsAbsentThoughtAndReasonLabels() throws {
+ func stepOmitsAbsentThoughtAndNarration() throws {
let transcript = makeTranscript()
transcript.step(
number: 1,
thought: nil,
- reason: " ",
+ narration: " ",
tool: "music.status",
input: [:],
status: "succeeded",
@@ -50,8 +55,8 @@ struct ThreadTranscriptTests {
let text = try threadText(transcript)
#expect(!text.contains("**Thought:**"))
- #expect(!text.contains("**Reason:**"))
- #expect(text.contains("**Action:** `music.status`"))
+ // Blank narration is dropped: the decision block goes straight to the action.
+ #expect(text.contains("### 🧠 Decision\n\n**Action:** `music.status`"))
#expect(text.contains("(no input)"))
#expect(text.contains("### 📄 Output — `succeeded`"))
}
@@ -116,7 +121,7 @@ struct ThreadTranscriptTests {
transcript.step(
number: 2,
thought: nil,
- reason: "Reading the screen.",
+ narration: "Reading the screen.",
tool: "vision.capture",
input: [:],
status: "succeeded",
@@ -138,7 +143,7 @@ struct ThreadTranscriptTests {
transcript.step(
number: 1,
thought: nil,
- reason: nil,
+ narration: nil,
tool: "shell_exec",
input: ["command": "ls"],
status: "succeeded",