Open source CapCut alternative.
TypeScript
refactor(app): make the chin show the conversation's latest line, always
David Le1b8e43fa7a98
diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swiftindex 41502d62..ff491488 100644--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift@@ -1268,11 +1268,12 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {// reaches here). A matched task that reaches this point has a stopped loop, so a new turn// resumes it: seed it back to running rather than restarting it under a replaced goal.//- // The chin echoes `commandText` while a task runs, so the resumed turn must adopt the new- // follow-up text — otherwise the chin keeps reading back the original prompt for the whole- // run instead of what the user just asked.+ // The chin shows the conversation's latest line (`detail`), so seed both the command and that+ // line with what the user just sent; the agent's narration and reply overwrite `detail` from+ // there. (`appendAgentEvent` also writes these for the resume path, but the inject path seeds+ // straight here, so set them at the source too.)task.commandText = text- task.detail = Self.runningSeedDetail+ task.detail = texttask.status = .runningtask.updatedAt = Date()// Restamp the run-start: a resumed run's elapsed time should measure this run, not the idle@@ -1296,7 +1297,7 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {let task = UserQueryConversation(id: UUID().uuidString,title: taskLabel,- detail: Self.runningSeedDetail,+ detail: text,commandText: text,status: .running,accentIndex: nextAccentIndex@@ -1465,14 +1466,15 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {sequence: sequence))- // The collapsed chin echoes the latest turn while the agent works, reading it from the task's- // `commandText`. Every user turn — fresh, follow-up, resumed, or one folded into a still-running- // task via the inject path — passes through here, but the inject path updates no task field on its- // own, so a follow-up would leave the chin reading back the original prompt for the whole run.- // Refresh it here, the one chokepoint every user message crosses, so the chin always shows the- // message the user just sent rather than a stale earlier one.+ // The chin shows the latest line of the conversation, and `detail` holds it. A user message is the+ // newest line the instant it is sent, so write it here — the one chokepoint every user turn crosses+ // (fresh, follow-up, resumed, or folded into a still-running task via the inject path) — rather than+ // at each call site, where a path that forgets leaves the chin reading back an older line. Clear any+ // in-flight streamed answer so the agent's next reply replaces this message instead of appending to+ // it; keep `commandText` in sync for the other surfaces (prompt pill, follow-up matching).if role == .user {- updateTask(id: conversationID, commandText: trimmedText)+ conversationsStreamingAnswer.remove(conversationID)+ updateTask(id: conversationID, commandText: trimmedText, detail: trimmedText)}return eventID}@@ -1685,11 +1687,6 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {return UserQueryAccentPalette.index(after: mostRecentAccentIndex)}- /// The status line a freshly-started task shows before the agent's first narration lands. Uses the- /// centralized activity vocabulary ("Thinking") rather than a bare "Running", and is replaced step- /// by step as `runProgressHandler` streams the planner's narration in.- private static let runningSeedDetail = UserQueryActivity.Kind.working.label-/// The task's title is the user's prompt, whitespace-collapsed. It is NOT hard-truncated here: every/// place that shows it (the collapsed bar, the prompt pill, each expanded row) renders it on a single/// line and tail-truncates to its own available width, so the expanded row title spans the full rowdiff --git a/apps/Donkey/Sources/DonkeyContracts/UserQueryConversationContracts.swift b/apps/Donkey/Sources/DonkeyContracts/UserQueryConversationContracts.swiftindex 31f9a7a5..173cd841 100644--- a/apps/Donkey/Sources/DonkeyContracts/UserQueryConversationContracts.swift+++ b/apps/Donkey/Sources/DonkeyContracts/UserQueryConversationContracts.swift@@ -59,23 +59,15 @@ public struct UserQueryConversation: Codable, Equatable, Identifiable, Sendable}public extension UserQueryConversation {- /// The single line the collapsed chin shows for this task: the user's prompt while it runs, the- /// assistant's reply as it streams in (and once answered, its `detail`). The chin renderer and the- /// chin-band height measurement both read this, so the band is always sized to the exact line it- /// renders — a running task can't show a wrapped prompt inside a band measured for a shorter seed.+ /// The single line the collapsed chin shows for this task — always the latest line of the+ /// conversation. `detail` is the one field that carries it: the user's message the instant they send+ /// it, the agent's live step narration while it works, then the agent's reply. Each of those writes+ /// `detail` at its own source (see `UserQueryOverlayModel`), so the chin never reconstructs "what's+ /// newest" from the prompt, title, and status — it just renders this. `title` (the first prompt) is+ /// only a fallback for a task that has no line yet. The chin renderer and the chin-band height+ /// measurement both read this, so the band is always sized to the exact line it renders.var chinDisplayText: String {- if status == .running {- // While the agent works, the chin narrates its latest step — each planner narration and the- // streaming final answer land in `detail`. Show that the moment it advances past the initial- // "Thinking" seed; the user's prompt is only the first frame, before any narration arrives.- let detailText = detail.trimmingCharacters(in: .whitespacesAndNewlines)- if !detailText.isEmpty, detailText != UserQueryActivity.Kind.working.label {- return detail- }- let prompt = commandText.trimmingCharacters(in: .whitespacesAndNewlines)- if !prompt.isEmpty { return prompt }- }- return detail.isEmpty ? title : detail+ detail.isEmpty ? title : detail}}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryChinDisplayTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryChinDisplayTests.swiftnew file mode 100644index 00000000..90d09c12--- /dev/null+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryChinDisplayTests.swift@@ -0,0 +1,51 @@+import DonkeyContracts+import Foundation+import Testing++/// The collapsed chin shows one line: the latest line of the conversation, which always lives in the+/// task's `detail`. These lock the invariant so a future change can't reintroduce the old bug where the+/// chin reconstructed "what's newest" from the prompt/title/status and got stuck on a stale earlier line.+@Suite+struct UserQueryChinDisplayTests {+ private func task(+ title: String = "first prompt",+ commandText: String = "first prompt",+ detail: String,+ status: UserQueryConversationStatus+ ) -> UserQueryConversation {+ UserQueryConversation(+ id: "t",+ title: title,+ detail: detail,+ commandText: commandText,+ status: status,+ accentIndex: 0+ )+ }++ @Test+ func chinShowsDetailInEveryState() {+ // `detail` is the chin line whether the agent is mid-run or finished — no status branch decides it.+ for status in [UserQueryConversationStatus.running, .chatting, .completed, .waitingForClarification] {+ #expect(task(detail: "latest line", status: status).chinDisplayText == "latest line")+ }+ }++ @Test+ func chinNeverFallsBackToTheStaleCommandText() {+ // The exact bug: a follow-up's reply is in `detail`, but `commandText`/`title` still hold the+ // original prompt. The chin must show the latest line, not read back the opening "hi".+ let answered = task(+ title: "hi",+ commandText: "hi",+ detail: "It's 72°F and sunny.",+ status: .running+ )+ #expect(answered.chinDisplayText == "It's 72°F and sunny.")+ }++ @Test+ func chinFallsBackToTitleOnlyWhenThereIsNoLineYet() {+ #expect(task(title: "hi", detail: "", status: .running).chinDisplayText == "hi")+ }+}