Open source CapCut alternative.
TypeScript
Refine spawn label follow-up input
David Le3aa7c199b940
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swiftindex 35d29a88..7f9bcd03 100644--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift@@ -26,9 +26,7 @@ final class PointerPromptOverlayController {private var completedActivationTapCount = 0private var lastActivationTapCompletedAt: Date?private var activationHoldStartedAt: Date?- private var spawnVoiceHoldStartedAt: Date?private var isVoiceInputActive = false- private var activeSpawnVoiceInputID: String?private var isStatusExpanded = falseprivate var isStatusHostExpanded = false// Hover can produce enter/exit samples faster than SwiftUI's spring can settle.@@ -290,20 +288,11 @@ final class PointerPromptOverlayController {return}- if activeSpawnVoiceInputID != nil, !isActivationModifierDown {- finishSpawnVoiceInput()- resetActivationTapSequence()- return- }-if isCleanActivationModifierOnly {if activationTapStartedAt == nil {let now = Date()activationTapStartedAt = nowactivationTapIsClean = true- if shouldStartSpawnVoiceHoldCandidate() {- spawnVoiceHoldStartedAt = now- }if shouldStartVoiceHoldCandidate(at: now) {activationHoldStartedAt = now}@@ -319,7 +308,6 @@ final class PointerPromptOverlayController {completedActivationTapCount = 0lastActivationTapCompletedAt = nilactivationHoldStartedAt = nil- spawnVoiceHoldStartedAt = nilreturn}@@ -336,7 +324,6 @@ final class PointerPromptOverlayController {tapDuration <= activationShortcut.maximumTapDurationself.activationTapStartedAt = nilactivationTapIsClean = false- spawnVoiceHoldStartedAt = nilguard completedCleanTap else {resetActivationTapSequence()@@ -371,11 +358,6 @@ final class PointerPromptOverlayController {completedActivationTapCount = 0lastActivationTapCompletedAt = nilactivationHoldStartedAt = nil- spawnVoiceHoldStartedAt = nil- }-- private func shouldStartSpawnVoiceHoldCandidate() -> Bool {- !model.promptState.isActive && !model.spawnStates.isEmpty}private func shouldStartVoiceHoldCandidate(at now: Date) -> Bool {@@ -390,14 +372,10 @@ final class PointerPromptOverlayController {}private func activateVoiceInputIfNeeded() {- guard !activatePromptVoiceInputIfNeeded() else { return }-- activateSpawnVoiceInputIfNeeded()+ _ = activatePromptVoiceInputIfNeeded()}private func activatePromptVoiceInputIfNeeded() -> Bool {- guard activeSpawnVoiceInputID == nil else { return false }-guard let holdToVoiceInputDuration = activationShortcut.holdToVoiceInputDuration,let activationHoldStartedAt,activationTapIsClean,@@ -431,49 +409,6 @@ final class PointerPromptOverlayController {model.handle(.voiceInputRequested)}- private func activateSpawnVoiceInputIfNeeded() {- guard activeSpawnVoiceInputID == nil,- let spawnVoiceHoldStartedAt,- activationTapIsClean,- Date().timeIntervalSince(spawnVoiceHoldStartedAt) >= spawnVoiceHoldDuration else {- return- }-- guard let spawnID = model.beginSpawnVoiceInput() else { return }- guard spawnOverlayController.beginVoiceInput(spawnID: spawnID) else {- model.cancelSpawnVoiceInput(spawnID: spawnID)- return- }-- activeSpawnVoiceInputID = spawnID- resetActivationTapSequence()- microphoneWaveformMeter.startAudioCapture()- }-- private var spawnVoiceHoldDuration: TimeInterval {- activationShortcut.holdToVoiceInputDuration ?? 0.35- }-- private func finishSpawnVoiceInput() {- guard let spawnID = activeSpawnVoiceInputID else { return }-- activeSpawnVoiceInputID = nil- spawnVoiceHoldStartedAt = nil- let audio = microphoneWaveformMeter.finishAudioCapture()- model.transcribeSpawnVoiceAudio(spawnID: spawnID, audio: audio) { [weak self] transcript in- guard let self else { return }-- guard let transcript,- !transcript.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {- self.spawnOverlayController.cancelVoiceInput(spawnID: spawnID)- self.model.cancelSpawnVoiceInput(spawnID: spawnID)- return- }-- self.spawnOverlayController.completeVoiceInput(spawnID: spawnID, text: transcript)- }- }-private func finishVoiceInput() {guard isVoiceInputActive else { return }diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swiftindex 7b8d28c0..7e59be44 100644--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift@@ -14,7 +14,7 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink@Published var notchCommandText = ""@Published private(set) var notchCommandInputTextHeight = PointerPromptLayout.composerInputTextMinimumHeight@Published private(set) var isNotchCommandInputExpanded = true- @Published private(set) var notchAccentIndex = Int.random(in: 0..<8)+ @Published private(set) var notchAccentIndex = 0@Published private(set) var isCurrentTaskPaused = false@Published private(set) var updateState: PointerPromptUpdateState@Published private(set) var notchTasks: [PointerPromptNotchTask]@@ -164,52 +164,21 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink}}- func transcribeSpawnVoiceAudio(- spawnID: String,- audio: LocalVoiceAudioBuffer?,- transcriptReceived: @escaping @MainActor (String?) -> Void- ) {- guard let audio else {+ private func submitCommand(_ text: String, source: AppHarnessTurnSource = .typedPrompt) {+ let candidates = followUpCandidates()+ let promptFollowUpTarget = promptSubmissionFollowUpTarget()+ let spawnID: String?+ if let promptFollowUpTarget {updateSpawn(- id: spawnID,- label: "No voice captured",- inputState: .collapsed- )- transcriptReceived(nil)- return- }-- updateSpawn(id: spawnID, label: "Transcribing...")- let sourceTraceID = "pointer-prompt-spawn-voice-\(UUID().uuidString)"- Task { [weak self, voiceTranscriber] in- let result = await voiceTranscriber.transcribe(- LocalVoiceTranscriptionRequest(- audio: audio,- sourceTraceID: sourceTraceID- )+ id: promptFollowUpTarget.spawnID,+ commandText: text,+ label: Self.collapsedDisplayText(for: text),+ phase: .holding)- await MainActor.run {- guard let self else { return }-- let transcript = result.transcript?.text.trimmingCharacters(in: .whitespacesAndNewlines)- if transcript?.isEmpty == false {- self.updateSpawn(id: spawnID, label: "Heard you")- transcriptReceived(transcript)- } else {- self.updateSpawn(- id: spawnID,- label: "I didn't catch that",- inputState: .collapsed- )- transcriptReceived(nil)- }- }+ spawnID = promptFollowUpTarget.spawnID+ } else {+ spawnID = source == .voiceTranscript ? nil : beginSpawn(for: text)}- }-- private func submitCommand(_ text: String, source: AppHarnessTurnSource = .typedPrompt) {- let candidates = followUpCandidates()- let spawnID = source == .voiceTranscript ? nil : beginSpawn(for: text)clearSubmissionInputs()promptState.isActive = falsepromptState.isVoiceInputActive = false@@ -219,7 +188,9 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinklet confidenceThreshold = Self.followUpMatchConfidenceThresholdTask { [weak self, followUpResolver] inlet matchedTaskID: String?- if candidates.isEmpty {+ if let taskID = promptFollowUpTarget?.taskID {+ matchedTaskID = taskID+ } else if candidates.isEmpty {matchedTaskID = nil} else {let resolution = await followUpResolver.resolveFollowUp(@@ -296,75 +267,25 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinkselectedSpawnID = spawnID}- func beginSpawnVoiceInput() -> String? {- let selectedID = selectedSpawnID.flatMap { id in- spawn(withID: id).map { spawn -> String? in- spawn.taskID != nil && (spawn.phase == .holding || spawn.phase == .traveling) ? id : nil- } ?? nil- } ?? nil- guard let spawnID = selectedID ?? latestInteractableSpawnID() else { return nil }-- updateSpawn(- id: spawnID,- label: "Listening...",- phase: .holding,- inputState: .editing- )- selectedSpawnID = spawnID- return spawnID- }-- func completeSpawnVoiceInput(spawnID: String, transcript: String?) {- let trimmedText = transcript?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""+ func submitSpawnFollowUp(spawnID: String, taskID: String, text: String) {+ let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)guard !trimmedText.isEmpty,- let taskID = spawn(withID: spawnID)?.taskID else {- updateSpawn(- id: spawnID,- label: "I didn't catch that",- inputState: .collapsed- )+ taskIDForInteractableSpawn(id: spawnID) == taskID else {return}- submitSpawnFollowUp(spawnID: spawnID, taskID: taskID, text: trimmedText)- }-- func cancelSpawnVoiceInput(spawnID: String) {+ selectedSpawnID = spawnIDupdateSpawn(id: spawnID,- label: "Paused",- inputState: .collapsed- )- }-- func submitSpawnFollowUp(spawnID: String, taskID: String, text: String) {- let fallbackState = PointerPromptSpawnState(- id: spawnID,- taskID: taskID,- commandText: text,- label: "Routing follow-up",- accentIndex: notchAccentIndex,+ commandText: trimmedText,+ label: Self.collapsedDisplayText(for: trimmedText),phase: .holding)- let state = spawn(withID: spawnID) ?? fallbackState- guard let submission = PointerPromptSpawnLifecycle.followUpSubmission(- from: state,- text: text- ) else { return }-- updateSpawn(- id: submission.spawnID,- taskID: submission.taskID,- commandText: submission.text,- label: "Routing follow-up",- phase: .holding,- inputState: .collapsed- )startCommandRun(- text: submission.text,- matchedTaskID: submission.taskID,+ text: trimmedText,+ matchedTaskID: taskID,source: .followUp,- spawnID: submission.spawnID+ spawnID: spawnID)}@@ -379,7 +300,6 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinkupdateSpawn(id: spawnID,taskID: task.id,- label: "Finding destination",accentIndex: task.accentIndex)activeTaskIDs.insert(task.id)@@ -482,17 +402,18 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinkprivate func beginSpawn(for text: String,- label: String = "Routing task",+ label: String? = nil,taskID: String? = nil,accentIndex: Int? = nil) -> String {let spawnID = UUID().uuidStringlet displayText = Self.taskLabel(for: text)+ let labelText = label ?? Self.collapsedDisplayText(for: text)let spawnState = PointerPromptSpawnState(id: spawnID,taskID: taskID,commandText: text,- label: label,+ label: labelText,accentIndex: accentIndex ?? Self.nextAccentIndex(after: notchAccentIndex),phase: .notchCue)@@ -510,8 +431,7 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinklabel: String? = nil,accentIndex: Int? = nil,targetHint: PointerPromptSpawnTargetHint? = nil,- phase: PointerPromptSpawnPhase? = nil,- inputState: PointerPromptSpawnInputState? = nil+ phase: PointerPromptSpawnPhase? = nil) {guard let spawnID,let index = spawnIndex(id: spawnID) else {@@ -540,9 +460,6 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinkspawnState.phase = phase}}- if let inputState {- spawnState.inputState = inputState- }spawnState.updatedAt = Date()spawnStates[index] = spawnState}@@ -560,14 +477,10 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinkspawnState.label = Self.spawnCompletionLabel(for: result)spawnState.updatedAt = Date()- switch result.threadStatus {- case .waitingForClarification, .waitingForReview, .needsAttention:- spawnState.phase = .holding- spawnStates[index] = spawnState- case .running, .paused:+ if PointerPromptSpawnLifecycle.keepsVisibleResult(for: result.threadStatus) {spawnState.phase = .holdingspawnStates[index] = spawnState- case .chatting, .completed, .failed:+ } else {spawnStates[index] = spawnStatescheduleSpawnFade(id: spawnID)}@@ -610,6 +523,30 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink.id}+ private func promptSubmissionFollowUpTarget() -> (spawnID: String, taskID: String)? {+ if let selectedSpawnID,+ let taskID = taskIDForInteractableSpawn(id: selectedSpawnID) {+ return (selectedSpawnID, taskID)+ }++ guard let spawnID = latestInteractableSpawnID(),+ let taskID = taskIDForInteractableSpawn(id: spawnID) else {+ return nil+ }++ return (spawnID, taskID)+ }++ private func taskIDForInteractableSpawn(id spawnID: String) -> String? {+ guard let spawn = spawn(withID: spawnID),+ let taskID = spawn.taskID,+ spawn.phase == .holding || spawn.phase == .traveling else {+ return nil+ }++ return taskID+ }+private func removeSpawn(id spawnID: String) {spawnStates.removeAll { $0.id == spawnID }if selectedSpawnID == spawnID {@@ -875,7 +812,7 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinkcase .paused:return "Paused"case .chatting:- return result.summary.isEmpty ? "Answered" : truncated(result.summary, maxLength: 42)+ return result.summary.isEmpty ? "Answered" : result.summarycase .completed:return "Done"case .failed:@@ -885,18 +822,11 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinkprivate static func nextAccentIndex(after currentIndex: Int) -> Int {let accentCount = 8- var nextIndex = Int.random(in: 0..<accentCount)- if nextIndex == currentIndex {- nextIndex = (nextIndex + 1) % accentCount- }- return nextIndex+ return (currentIndex + 1) % accentCount}private static func taskLabel(for text: String) -> String {- let collapsed = text- .trimmingCharacters(in: .whitespacesAndNewlines)- .split(whereSeparator: \.isWhitespace)- .joined(separator: " ")+ let collapsed = collapsedDisplayText(for: text)guard !collapsed.isEmpty else { return "New task" }let maxLength = 44@@ -906,6 +836,13 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSinkreturn String(collapsed[..<endIndex]).trimmingCharacters(in: .whitespacesAndNewlines) + "..."}+ private static func collapsedDisplayText(for text: String) -> String {+ text+ .trimmingCharacters(in: .whitespacesAndNewlines)+ .split(whereSeparator: \.isWhitespace)+ .joined(separator: " ")+ }+private static func assetUploadEventText(_ assetNames: [String]) -> String {let displayNames = assetNames.map { truncated($0, maxLength: 80) }diff --git a/apps/Donkey/Sources/Donkey/PointerPromptSpawnOverlayController.swift b/apps/Donkey/Sources/Donkey/PointerPromptSpawnOverlayController.swiftindex 8e69b149..f5eb57f5 100644--- a/apps/Donkey/Sources/Donkey/PointerPromptSpawnOverlayController.swift+++ b/apps/Donkey/Sources/Donkey/PointerPromptSpawnOverlayController.swift@@ -75,7 +75,6 @@ final class PointerPromptSpawnOverlayController {) {let destination = destinationPoint(for: spawnState.targetHint,- viewModel: viewModelsByID[spawnState.id],screen: screen,notchMetrics: notchMetrics)@@ -246,17 +245,38 @@ final class PointerPromptSpawnOverlayController {}private func configureCallbacks(for surface: PointerPromptSpawnSurface) {- surface.viewModel.inputActivityChanged = { [weak self, weak surface] isActive in+ surface.viewModel.labelLayoutChanged = { [weak self, weak surface] inguard let self,let surface else {return}- self.updateInputInteractivity(- isActive: isActive,- for: surface+ self.layoutSurface(+ surface,+ on: surface.screen,+ animated: false)}+ surface.viewModel.labelEditingChanged = { [weak self, weak surface] isEditing in+ guard let self,+ let surface else {+ return+ }++ self.layoutSurface(+ surface,+ on: surface.screen,+ animated: false+ )+ if isEditing {+ NSApp.activate(ignoringOtherApps: true)+ surface.panel.orderFrontRegardless()+ surface.panel.makeKeyAndOrderFront(nil)+ } else {+ surface.panel.orderFrontRegardless()+ }+ self.updateMouseEventPassthrough(for: surface)+ }surface.viewModel.travelCompleted = { [weak self, weak surface] inguard let self,let surface else {@@ -371,28 +391,6 @@ final class PointerPromptSpawnOverlayController {surface.screen = screen}- private func updateInputInteractivity(- isActive: Bool,- for surface: PointerPromptSpawnSurface- ) {- surface.travelWorkItem?.cancel()- surface.isTraveling = false- layoutSurface(- surface,- on: surface.screen,- animated: false- )-- if isActive {- NSApp.activate(ignoringOtherApps: true)- surface.panel.orderFrontRegardless()- surface.panel.makeKeyAndOrderFront(nil)- } else {- surface.panel.orderFrontRegardless()- }- updateMouseEventPassthrough(for: surface)- }-private func updateMouseEventPassthrough(for surface: PointerPromptSpawnSurface) {let hitTestFrame = surface.viewModel.localHitTestFrameguard !hitTestFrame.isNull, !hitTestFrame.isEmpty else {@@ -404,25 +402,6 @@ final class PointerPromptSpawnOverlayController {surface.panel.ignoresMouseEvents = !hitTestFrame.contains(mouseLocation)}- func beginVoiceInput(spawnID: String) -> Bool {- guard let viewModel = viewModelsByID[spawnID] else { return false }-- viewModel.beginVoiceInput()- return true- }-- func completeVoiceInput(spawnID: String, text: String) {- guard let viewModel = viewModelsByID[spawnID] else { return }-- viewModel.applyTranscribedInput(text, submit: !text.isEmpty)- }-- func cancelVoiceInput(spawnID: String) {- guard let viewModel = viewModelsByID[spawnID] else { return }-- viewModel.collapseInput()- }-func cueState(for spawnState: PointerPromptSpawnState?,screen: NSScreen?,@@ -482,27 +461,6 @@ final class PointerPromptSpawnOverlayController {return CGPoint(x: screen.frame.width / 2 + stagger, y: -24)}- private func destinationPoint(- for hint: PointerPromptSpawnTargetHint?,- viewModel: PointerPromptSpawnOverlayViewModel?,- screen: NSScreen,- notchMetrics: PointerPromptNotchMetrics- ) -> CGPoint {- guard viewModel?.freezesMovement != true else {- return viewModel?.destination ?? destinationPoint(- for: hint,- screen: screen,- notchMetrics: notchMetrics- )- }-- return destinationPoint(- for: hint,- screen: screen,- notchMetrics: notchMetrics- )- }-private func destinationPoint(for hint: PointerPromptSpawnTargetHint?,screen: NSScreen,diff --git a/apps/Donkey/Sources/DonkeyContracts/PointerPromptSpawnContracts.swift b/apps/Donkey/Sources/DonkeyContracts/PointerPromptSpawnContracts.swiftindex 493c4ff6..35a0a108 100644--- a/apps/Donkey/Sources/DonkeyContracts/PointerPromptSpawnContracts.swift+++ b/apps/Donkey/Sources/DonkeyContracts/PointerPromptSpawnContracts.swift@@ -8,11 +8,6 @@ public enum PointerPromptSpawnPhase: String, Codable, Equatable, Sendable {case fading}-public enum PointerPromptSpawnInputState: String, Codable, Equatable, Sendable {- case collapsed- case editing-}-public struct PointerPromptSpawnTargetHint: Codable, Equatable, Sendable {public var appName: String?public var bundleIdentifier: String?@@ -44,7 +39,6 @@ public struct PointerPromptSpawnState: Codable, Equatable, Identifiable, Sendablpublic var phase: PointerPromptSpawnPhasepublic var notchCueAngleDegrees: Doublepublic var targetHint: PointerPromptSpawnTargetHint?- public var inputState: PointerPromptSpawnInputStatepublic var updatedAt: Datepublic init(@@ -56,7 +50,6 @@ public struct PointerPromptSpawnState: Codable, Equatable, Identifiable, Sendablphase: PointerPromptSpawnPhase = .notchCue,notchCueAngleDegrees: Double = PointerPromptSpawnGeometry.defaultExitAngleDegrees,targetHint: PointerPromptSpawnTargetHint? = nil,- inputState: PointerPromptSpawnInputState = .collapsed,updatedAt: Date = Date()) {self.id = id@@ -67,7 +60,6 @@ public struct PointerPromptSpawnState: Codable, Equatable, Identifiable, Sendablself.phase = phaseself.notchCueAngleDegrees = notchCueAngleDegreesself.targetHint = targetHint- self.inputState = inputStateself.updatedAt = updatedAt}}@@ -88,47 +80,24 @@ public struct PointerPromptSpawnProgressUpdate: Equatable, Sendable {}}-public struct PointerPromptSpawnFollowUpSubmission: Equatable, Sendable {- public var spawnID: String- public var taskID: String- public var text: String-- public init(- spawnID: String,- taskID: String,- text: String- ) {- self.spawnID = spawnID- self.taskID = taskID- self.text = text- }-}-public enum PointerPromptSpawnLifecycle {- public static func freezesMovement(- inputState: PointerPromptSpawnInputState,- draftText: String+ public static func keepsVisibleResult(+ for threadStatus: PointerPromptTaskStatus) -> Bool {- inputState == .editing ||- !draftText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty- }-- public static func followUpSubmission(- from state: PointerPromptSpawnState,- text: String- ) -> PointerPromptSpawnFollowUpSubmission? {- let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)- guard !trimmedText.isEmpty,- let taskID = state.taskID else {- return nil+ switch threadStatus {+ case .chatting,+ .running,+ .paused,+ .waitingForClarification,+ .waitingForReview,+ .needsAttention,+ .failed:+ true+ case .completed:+ false}-- return PointerPromptSpawnFollowUpSubmission(- spawnID: state.id,- taskID: taskID,- text: trimmedText- )}+}public enum PointerPromptSpawnGeometry {diff --git a/apps/Donkey/Sources/DonkeyUI/PointerPromptSpawnOverlayView.swift b/apps/Donkey/Sources/DonkeyUI/PointerPromptSpawnOverlayView.swiftindex bfcb1fce..5dfaca22 100644--- a/apps/Donkey/Sources/DonkeyUI/PointerPromptSpawnOverlayView.swift+++ b/apps/Donkey/Sources/DonkeyUI/PointerPromptSpawnOverlayView.swift@@ -14,11 +14,13 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {@Published public private(set) var opacity: Double = 0@Published public private(set) var isHolding = false@Published public private(set) var isSelected = false- @Published public var inputText = ""- @Published public var inputTextHeight: CGFloat = PointerPromptSpawnOverlayViewModel.inputMinimumTextHeight- @Published public private(set) var isInputExpanded = false+ @Published public private(set) var isLabelHovered = false+ @Published public private(set) var isLabelEditing = false+ @Published public var draftText = ""+ @Published public private(set) var draftTextHeight: CGFloat = PointerPromptSpawnOverlayViewModel.inlineEditorMinimumTextHeight- public var inputActivityChanged: ((Bool) -> Void)?+ public var labelLayoutChanged: (() -> Void)?+ public var labelEditingChanged: ((Bool) -> Void)?public var followUpSubmitted: ((String, String, String) -> Void)?public var selected: ((String) -> Void)?public var travelCompleted: (() -> Void)?@@ -27,26 +29,6 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {public init() {}- public var isInputActive: Bool {- state?.inputState == .editing- }-- public var freezesMovement: Bool {- PointerPromptSpawnLifecycle.freezesMovement(- inputState: state?.inputState ?? .collapsed,- draftText: inputText- )- }-- public var canSubmitInput: Bool {- guard let state else { return false }-- return PointerPromptSpawnLifecycle.followUpSubmission(- from: state,- text: inputText- ) != nil- }-public var hitTestFrame: CGRect {guard state != nil, isHolding else { return .null }@@ -72,20 +54,47 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {)}+ public var localCursorCenter: CGPoint {+ renderPosition+ }++ public var localHaloCenter: CGPoint {+ CGPoint(+ x: localCursorCenter.x,+ y: localCursorCenter.y + Self.collapsedHaloVerticalOffset+ )+ }++ public func localLabelCenter(in screenSize: CGSize) -> CGPoint {+ let offset = labelOffset(in: screenSize)+ return CGPoint(+ x: localCursorCenter.x + offset.width,+ y: localCursorCenter.y + offset.height+ )+ }+public var isTraveling: Bool {state != nil && !isHolding}+ public var freezesMovement: Bool {+ isLabelEditing || !draftText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty+ }+public var hasScreenSize: Bool {screenSize.width > 0 && screenSize.height > 0}+ public var hasViewportSize: Bool {+ viewportSize.width > 0 && viewportSize.height > 0+ }+public func cursorOnlyVisualFrame(at point: CGPoint) -> CGRect {CGRect(- x: point.x - 30,- y: point.y - 30,- width: 60,- height: 60+ x: point.x - Self.cursorVisualFrameSize.width / 2,+ y: point.y - Self.cursorVisualFrameSize.height / 2,+ width: Self.cursorVisualFrameSize.width,+ height: Self.cursorVisualFrameSize.height)}@@ -101,14 +110,13 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {var frame = cursorOnlyVisualFrame(at: point)guard includesLabel else { return frame }- let width: CGFloat = isInputActive ? 312 : 244- let height: CGFloat = isInputActive ? 142 : 54+ let labelSize = labelSize()let offset = labelOffset(for: point, in: screenSize)let origin = CGPoint(- x: point.x + offset.width - width / 2,- y: point.y + offset.height - height / 2+ x: point.x + offset.width - labelSize.width / 2,+ y: point.y + offset.height - labelSize.height / 2)- frame = frame.union(CGRect(origin: origin, size: CGSize(width: width, height: height)))+ frame = frame.union(CGRect(origin: origin, size: labelSize))return frame.insetBy(dx: -10, dy: -10)}@@ -131,26 +139,32 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {for cursorPosition: CGPoint,in screenSize: CGSize) -> CGSize {- let labelSize = CGSize(- width: isInputActive ? 292 : 220,- height: isInputActive ? 126 : 46- )+ let labelSize = labelSize()let margin: CGFloat = 20- let rightOffset = Self.preferredLabelOffset- let leftOffset = CGSize(width: -labelSize.width / 2 - 40, height: rightOffset.height)- let upOffset = CGSize(width: rightOffset.width, height: -labelSize.height - 28)- let upLeftOffset = CGSize(width: leftOffset.width, height: upOffset.height)+ let preferredOffset = CGSize(width: 0, height: -(labelSize.height / 2 + Self.collapsedLabelBottomGap))+ let rightOffset = CGSize(width: labelSize.width / 2 + 44, height: 0)+ let leftOffset = CGSize(width: -labelSize.width / 2 - 44, height: 0)+ let belowOffset = CGSize(width: 0, height: labelSize.height / 2 + 44)- if point(cursorPosition, offsetBy: rightOffset, labelSize: labelSize, fitsIn: screenSize, margin: margin) {- return rightOffset+ if point(cursorPosition, offsetBy: preferredOffset, labelSize: labelSize, fitsIn: screenSize, margin: margin) {+ return preferredOffset}if point(cursorPosition, offsetBy: leftOffset, labelSize: labelSize, fitsIn: screenSize, margin: margin) {return leftOffset}- if point(cursorPosition, offsetBy: upOffset, labelSize: labelSize, fitsIn: screenSize, margin: margin) {- return upOffset+ if point(cursorPosition, offsetBy: rightOffset, labelSize: labelSize, fitsIn: screenSize, margin: margin) {+ return rightOffset}- return upLeftOffset+ return belowOffset+ }++ private func labelSize() -> CGSize {+ if isLabelEditing {+ return Self.inlineEditorLabelSize(for: state?.label ?? "")+ }+ guard isLabelHovered else { return Self.collapsedLabelSize }++ return Self.expandedCollapsedLabelSize(for: state?.label ?? "")}public func show(@@ -168,10 +182,12 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {self.isHolding = falseself.viewportOrigin = .zeroself.viewportSize = .zero- self.inputText = ""- self.inputTextHeight = Self.inputMinimumTextHeight- self.isInputExpanded = false- inputActivityChanged?(false)+ self.isLabelHovered = false+ self.isLabelEditing = false+ self.draftText = ""+ self.draftTextHeight = Self.inlineEditorMinimumTextHeight+ labelLayoutChanged?()+ labelEditingChanged?(false)let generation = animationGenerationDispatchQueue.main.async { [weak self] in@@ -194,7 +210,7 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {return}- self.state = stateWithPreservedLocalInput(state)+ self.state = stateself.screenSize = screenSizeguard state.phase != .fading else {fadeOut()@@ -216,7 +232,6 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {public func fadeOut() {animationGeneration += 1- inputActivityChanged?(false)withAnimation(.easeOut(duration: 0.18)) {opacity = 0}@@ -227,101 +242,99 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {self.state = nilself.isHolding = false- self.inputText = ""- self.inputTextHeight = Self.inputMinimumTextHeight- self.isInputExpanded = false+ self.isLabelHovered = false+ self.isLabelEditing = false+ self.draftText = ""+ self.draftTextHeight = Self.inlineEditorMinimumTextHeightself.viewportOrigin = .zeroself.viewportSize = .zero+ self.labelLayoutChanged?()+ self.labelEditingChanged?(false)}}- public func beginInput() {- guard var state, isHolding else { return }+ public func setSelected(_ isSelected: Bool) {+ guard self.isSelected != isSelected else { return }- selected?(state.id)- state.inputState = .editing- state.updatedAt = Date()- self.state = state- inputActivityChanged?(true)+ self.isSelected = isSelected}- public func beginVoiceInput() {- guard var state else { return }+ public func setLabelHovered(_ isHovered: Bool) {+ guard !isLabelEditing else { return }- selected?(state.id)- state.inputState = .editing- state.label = "Listening..."- state.updatedAt = Date()- self.state = state- inputText = ""- inputTextHeight = Self.inputMinimumTextHeight- isInputExpanded = false- isHolding = true- inputActivityChanged?(true)+ let shouldExpand = isHovered && Self.collapsedLabelNeedsExpansion(state?.label ?? "")+ guard isLabelHovered != shouldExpand else { return }++ isLabelHovered = shouldExpand+ labelLayoutChanged?()}- public func applyTranscribedInput(_ text: String, submit: Bool) {- guard var state else { return }+ public func select() {+ guard let state else { return }++ selected?(state.id)+ }- state.inputState = .editing- state.label = text.isEmpty ? "I didn't catch that" : "Heard you"- state.updatedAt = Date()- self.state = state- inputText = text- inputActivityChanged?(true)- if submit {- submitInput()+ public func beginInlineInput() {+ guard let state,+ state.taskID != nil,+ !isLabelEditing else {+ select()+ return}++ selected?(state.id)+ isLabelHovered = false+ draftText = ""+ draftTextHeight = Self.inlineEditorMinimumTextHeight+ isLabelEditing = true+ labelLayoutChanged?()+ labelEditingChanged?(true)}- public func collapseInput() {- guard var state else { return }+ public func cancelInlineInput() {+ guard isLabelEditing || !draftText.isEmpty else { return }- inputText = ""- inputTextHeight = Self.inputMinimumTextHeight- isInputExpanded = false- state.inputState = .collapsed- state.updatedAt = Date()- self.state = state- inputActivityChanged?(false)- }-- public func submitInput() {- guard var state,- let submission = PointerPromptSpawnLifecycle.followUpSubmission(- from: state,- text: inputText- )- else { return }-- inputText = ""- inputTextHeight = Self.inputMinimumTextHeight- isInputExpanded = false- state.inputState = .collapsed- state.updatedAt = Date()- self.state = state- inputActivityChanged?(false)- followUpSubmitted?(submission.spawnID, submission.taskID, submission.text)+ draftText = ""+ draftTextHeight = Self.inlineEditorMinimumTextHeight+ isLabelEditing = false+ labelLayoutChanged?()+ labelEditingChanged?(false)}- public func setSelected(_ isSelected: Bool) {- guard self.isSelected != isSelected else { return }+ public func closeInlineInputIfIdle() {+ guard isLabelEditing,+ draftText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {+ return+ }- self.isSelected = isSelected+ cancelInlineInput()}- public func select() {+ public func submitInlineInput() {guard let state else { return }- selected?(state.id)+ let trimmedText = draftText.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !trimmedText.isEmpty,+ let taskID = state.taskID else {+ cancelInlineInput()+ return+ }++ draftText = ""+ draftTextHeight = Self.inlineEditorMinimumTextHeight+ isLabelEditing = false+ labelLayoutChanged?()+ labelEditingChanged?(false)+ followUpSubmitted?(state.id, taskID, trimmedText)}- public func updateInputTextHeight(_ height: CGFloat) {- let clamped = min(max(height, Self.inputMinimumTextHeight), Self.inputMaximumTextHeight)- guard abs(inputTextHeight - clamped) > 0.5 else { return }+ public func updateDraftTextHeight(_ height: CGFloat) {+ let clamped = min(max(height, Self.inlineEditorMinimumTextHeight), Self.inlineEditorMaximumTextHeight)+ guard abs(draftTextHeight - clamped) > 0.5 else { return }- inputTextHeight = clamped- isInputExpanded = clamped > Self.inputMinimumTextHeight + 1 || inputText.contains("\n")+ draftTextHeight = clamped+ labelLayoutChanged?()}private func finishTravelAfterDelay(generation: Int, finalPosition: CGPoint) {@@ -343,21 +356,6 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {hypot(lhs.x - rhs.x, lhs.y - rhs.y)}- private func stateWithPreservedLocalInput(- _ incomingState: PointerPromptSpawnState- ) -> PointerPromptSpawnState {- guard let currentState = state,- currentState.id == incomingState.id,- currentState.inputState == .editing- else {- return incomingState- }-- var mergedState = incomingState- mergedState.inputState = .editing- return mergedState- }-private func point(_ point: CGPoint,offsetBy offset: CGSize,@@ -378,15 +376,99 @@ public final class PointerPromptSpawnOverlayViewModel: ObservableObject {}public static let travelDuration: TimeInterval = 0.82- public static let inputMinimumTextHeight: CGFloat = 16- public static let inputMaximumTextHeight: CGFloat = 76- private static let preferredLabelOffset = CGSize(width: 138, height: 48)+ fileprivate static let cursorVisualFrameSize = CGSize(width: 84, height: 112)+ fileprivate static let labelHorizontalPadding: CGFloat = 10+ fileprivate static let collapsedLabelContentWidth: CGFloat = 240+ fileprivate static let collapsedLabelSize = CGSize(width: 260, height: 48)+ fileprivate static let collapsedLabelBottomGap: CGFloat = 22+ fileprivate static let expandedCollapsedLabelWidth: CGFloat = 480+ fileprivate static let inlineEditorContentWidth: CGFloat = expandedCollapsedLabelWidth+ fileprivate static let inlineEditorInputHeight: CGFloat = 64+ fileprivate static let inlineEditorHorizontalPadding: CGFloat = 16+ fileprivate static let inlineEditorVerticalPadding: CGFloat = 14+ fileprivate static let inlineEditorSpacing: CGFloat = 12+ public static let inlineEditorMinimumTextHeight: CGFloat = 14+ public static let inlineEditorMaximumTextHeight: CGFloat = 44+ fileprivate static let collapsedHaloSize: CGFloat = 40+ fileprivate static let collapsedHaloVerticalOffset: CGFloat = 12private static let travelAnimation = Animation.timingCurve(0.45, 0.05, 0.3, 1, duration: travelDuration)++ private static func expandedCollapsedLabelSize(for text: String) -> CGSize {+ let characterCount = max(Array(text).count, 1)+ let approximateCharactersPerLine = 44+ let lineCount = max(1, Int(ceil(Double(characterCount) / Double(approximateCharactersPerLine))))+ let height = CGFloat(lineCount) * 14 + 12+ return CGSize(+ width: expandedCollapsedLabelWidth + Self.labelHorizontalPadding * 2,+ height: max(collapsedLabelSize.height, height)+ )+ }++ private static func inlineEditorLabelSize(for text: String) -> CGSize {+ CGSize(+ width: inlineEditorContentWidth + inlineEditorHorizontalPadding * 2,+ height: inlineEditorMessageHeight(for: text) ++ inlineEditorSpacing ++ inlineEditorInputHeight ++ inlineEditorVerticalPadding * 2+ )+ }++ private static func inlineEditorMessageHeight(for text: String) -> CGFloat {+ let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !trimmedText.isEmpty else { return 20 }++ let font = NSFont.systemFont(ofSize: 13, weight: .bold)+ let paragraphStyle = NSMutableParagraphStyle()+ paragraphStyle.lineBreakMode = .byWordWrapping+ let attributes: [NSAttributedString.Key: Any] = [+ .font: font,+ .paragraphStyle: paragraphStyle+ ]+ let rect = (trimmedText as NSString).boundingRect(+ with: CGSize(+ width: inlineEditorContentWidth,+ height: CGFloat.greatestFiniteMagnitude+ ),+ options: [.usesLineFragmentOrigin, .usesFontLeading],+ attributes: attributes+ )+ let lineHeight = NSLayoutManager().defaultLineHeight(for: font)+ return min(max(ceil(rect.height), lineHeight), ceil(lineHeight * 3))+ }++ private static func collapsedLabelNeedsExpansion(_ text: String) -> Bool {+ let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !trimmedText.isEmpty else { return false }++ let font = NSFont.systemFont(ofSize: 10, weight: .medium)+ let paragraphStyle = NSMutableParagraphStyle()+ paragraphStyle.lineBreakMode = .byWordWrapping+ paragraphStyle.alignment = .center+ let attributes: [NSAttributedString.Key: Any] = [+ .font: font,+ .paragraphStyle: paragraphStyle+ ]+ let singleLineWidth = ceil((trimmedText as NSString).size(withAttributes: attributes).width)+ let boundingRect = (trimmedText as NSString).boundingRect(+ with: CGSize(+ width: collapsedLabelContentWidth,+ height: CGFloat.greatestFiniteMagnitude+ ),+ options: [.usesLineFragmentOrigin, .usesFontLeading],+ attributes: attributes+ )+ let lineHeight = NSLayoutManager().defaultLineHeight(for: font)+ let maximumVisibleHeight = ceil(lineHeight * 2 + 1)++ return singleLineWidth > collapsedLabelContentWidth * 2 ||+ ceil(boundingRect.height) > maximumVisibleHeight+ }}public struct PointerPromptSpawnOverlayView: View {@ObservedObject private var viewModel: PointerPromptSpawnOverlayViewModel- @FocusState private var labelIsFocused: Bool+ @State private var haloPulseActive = falsepublic init(viewModel: PointerPromptSpawnOverlayViewModel) {self.viewModel = viewModel@@ -397,7 +479,11 @@ public struct PointerPromptSpawnOverlayView: View {ZStack(alignment: .topLeading) {if let state = viewModel.state {spawnSurface(state: state, screenSize: viewModel.hasScreenSize ? viewModel.screenSize : proxy.size)- .position(viewModel.renderPosition)+ .frame(+ width: viewModel.hasViewportSize ? viewModel.viewportSize.width : proxy.size.width,+ height: viewModel.hasViewportSize ? viewModel.viewportSize.height : proxy.size.height,+ alignment: .topLeading+ ).opacity(viewModel.opacity)}}@@ -412,29 +498,32 @@ public struct PointerPromptSpawnOverlayView: View {ZStack(alignment: .topLeading) {if viewModel.isHolding {Circle()- .stroke(accentColor(for: state.accentIndex).opacity(0.68), lineWidth: 1.4)- .frame(width: 36, height: 36)- .scaleEffect(holdingPulseScale)- .opacity(holdingPulseOpacity)- .position(.zero)- }-- if viewModel.isSelected {- Circle()- .stroke(Color.white.opacity(0.52), lineWidth: 1.2)- .frame(width: 42, height: 42)- .position(.zero)+ .stroke(accentColor(for: state.accentIndex), lineWidth: 1.5)+ .frame(+ width: PointerPromptSpawnOverlayViewModel.collapsedHaloSize,+ height: PointerPromptSpawnOverlayViewModel.collapsedHaloSize+ )+ .scaleEffect(haloPulseScale)+ .opacity(haloPulseOpacity)+ .position(viewModel.localHaloCenter)+ .animation(+ .easeInOut(duration: 1.6).repeatForever(autoreverses: true),+ value: haloPulseActive+ )+ .onAppear {+ haloPulseActive = true+ }+ .onDisappear {+ haloPulseActive = false+ }}cursor(state: state)- .position(.zero)+ .position(viewModel.localCursorCenter)if viewModel.isHolding {stationaryLabel(state: state)- .offset(- x: viewModel.labelOffset(in: screenSize).width,- y: viewModel.labelOffset(in: screenSize).height- )+ .position(viewModel.localLabelCenter(in: screenSize)).transition(.opacity.combined(with: .scale(scale: 0.96, anchor: .topLeading)))}}@@ -455,84 +544,101 @@ public struct PointerPromptSpawnOverlayView: View {.frame(width: 28, height: 28).rotationEffect(.degrees(cursorAngleDegrees + 50)).scaleEffect(viewModel.isHolding ? holdingCursorScale : 1)+ .animation(+ .easeInOut(duration: 1.4).repeatForever(autoreverses: true),+ value: haloPulseActive+ )}private func stationaryLabel(state: PointerPromptSpawnState) -> some View {- VStack(alignment: .leading, spacing: 8) {- TypewriterText(- text: state.label,- identity: PointerPromptSpawnGeometry.labelTypingIdentity(- spawnID: state.id,- label: state.label- )- )- .font(.system(size: 11, weight: .medium))- .foregroundStyle(.white)- .lineLimit(2)- .fixedSize(horizontal: false, vertical: true)-- if viewModel.isInputActive {- compactInput+ Group {+ if viewModel.isLabelEditing {+ inlineLabelEditor(state: state)+ } else {+ displayLabel(state: state)}}- .padding(.horizontal, 10)- .padding(.vertical, 7)- .frame(width: viewModel.isInputActive ? 292 : 220, alignment: .leading).background {RoundedRectangle(cornerRadius: 8, style: .continuous)- .fill(Color.black.opacity(0.82))- }- .overlay {- RoundedRectangle(cornerRadius: 8, style: .continuous)- .stroke(Color.white.opacity(viewModel.isInputActive ? 0.26 : 0.16), lineWidth: 1)- .overlay {- RoundedRectangle(cornerRadius: 8, style: .continuous)- .stroke(Color.white.opacity(viewModel.isSelected ? 0.34 : 0), lineWidth: 1.4)- }+ .fill(accentColor(for: state.accentIndex))}- .shadow(color: Color.black.opacity(0.32), radius: 10, x: 0, y: 5)+ .shadow(color: Color.black.opacity(0.3), radius: 3, x: 0, y: 1).contentShape(RoundedRectangle(cornerRadius: 8, style: .continuous)).onTapGesture {- viewModel.select()- viewModel.beginInput()+ viewModel.beginInlineInput()}- .focusable(true)- .focused($labelIsFocused)- .onChange(of: labelIsFocused) {- if labelIsFocused {- viewModel.beginInput()- }+ .onHover { isHovered in+ viewModel.setLabelHovered(isHovered)}}- private var compactInput: some View {- HStack(alignment: .bottom, spacing: 8) {- SpawnLabelTextInput(- text: $viewModel.inputText,- isActive: viewModel.isInputActive,- textHeightChanged: viewModel.updateInputTextHeight,- submit: viewModel.submitInput,- cancel: viewModel.collapseInput+ private func displayLabel(state: PointerPromptSpawnState) -> some View {+ TypewriterText(+ text: state.label,+ identity: PointerPromptSpawnGeometry.labelTypingIdentity(+ spawnID: state.id,+ label: state.label+ )+ )+ .font(.system(size: 10, weight: .medium))+ .foregroundStyle(.white)+ .multilineTextAlignment(.center)+ .lineLimit(viewModel.isLabelHovered ? nil : 2)+ .truncationMode(.tail)+ .frame(+ maxWidth: viewModel.isLabelHovered ? PointerPromptSpawnOverlayViewModel.expandedCollapsedLabelWidth : PointerPromptSpawnOverlayViewModel.collapsedLabelContentWidth,+ alignment: .center+ )+ .padding(.horizontal, PointerPromptSpawnOverlayViewModel.labelHorizontalPadding)+ .padding(.vertical, 3)+ }++ private func inlineLabelEditor(state: PointerPromptSpawnState) -> some View {+ VStack(alignment: .leading, spacing: PointerPromptSpawnOverlayViewModel.inlineEditorSpacing) {+ Text(state.label)+ .font(.system(size: 13, weight: .bold))+ .foregroundStyle(.white)+ .multilineTextAlignment(.leading)+ .lineLimit(3)+ .truncationMode(.tail)+ .frame(+ width: PointerPromptSpawnOverlayViewModel.inlineEditorContentWidth,+ alignment: .leading+ )++ SpawnLabelInlineTextInput(+ text: $viewModel.draftText,+ isActive: viewModel.isLabelEditing,+ textHeightChanged: viewModel.updateDraftTextHeight,+ submit: viewModel.submitInlineInput,+ cancel: viewModel.cancelInlineInput,+ focusLost: viewModel.closeInlineInputIfIdle)- .frame(height: viewModel.inputTextHeight)- .padding(.horizontal, 10)+ .frame(+ width: PointerPromptSpawnOverlayViewModel.inlineEditorContentWidth - 24,+ height: max(viewModel.draftTextHeight, PointerPromptSpawnOverlayViewModel.inlineEditorMinimumTextHeight),+ alignment: .topLeading+ )+ .padding(.horizontal, 12).padding(.vertical, 8)- .frame(minHeight: 34)- .background(Color.white.opacity(0.09))- .clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))-- Button(action: viewModel.submitInput) {- Image(systemName: "arrow.up")- .font(.system(size: 11, weight: .semibold))- .foregroundStyle(Color.black.opacity(0.78))- .frame(width: 26, height: 26)- .background(Color.white.opacity(0.92))- .clipShape(Circle())+ .frame(+ width: PointerPromptSpawnOverlayViewModel.inlineEditorContentWidth,+ height: PointerPromptSpawnOverlayViewModel.inlineEditorInputHeight,+ alignment: .topLeading+ )+ .background {+ RoundedRectangle(cornerRadius: 7, style: .continuous)+ .fill(inputAccentColor(for: state.accentIndex))}- .buttonStyle(.plain)- .disabled(!viewModel.canSubmitInput)}- .frame(width: 272)+ .frame(+ width: PointerPromptSpawnOverlayViewModel.inlineEditorContentWidth,+ alignment: .center+ )+ .padding(.horizontal, PointerPromptSpawnOverlayViewModel.inlineEditorHorizontalPadding)+ .padding(.vertical, PointerPromptSpawnOverlayViewModel.inlineEditorVerticalPadding)+ .transition(.opacity.combined(with: .scale(scale: 0.98)))+ .animation(.easeOut(duration: 0.12), value: viewModel.isLabelEditing)}private var cursorAngleDegrees: Double {@@ -542,22 +648,26 @@ public struct PointerPromptSpawnOverlayView: View {)}- private var holdingPulseScale: CGFloat {- viewModel.freezesMovement ? 1.04 : 1.14+ private var haloPulseScale: CGFloat {+ haloPulseActive ? 1.15 : 1.0}- private var holdingPulseOpacity: Double {- viewModel.freezesMovement ? 0.32 : 0.2+ private var haloPulseOpacity: Double {+ haloPulseActive ? 0.2 : 0.6}private var holdingCursorScale: CGFloat {- viewModel.freezesMovement ? 1.02 : 1.08+ haloPulseActive ? 1.08 : 1.0}private func accentColor(for index: Int) -> Color {Self.accentColors[((index % Self.accentColors.count) + Self.accentColors.count) % Self.accentColors.count]}+ private func inputAccentColor(for index: Int) -> Color {+ Self.inputAccentColors[((index % Self.inputAccentColors.count) + Self.inputAccentColors.count) % Self.inputAccentColors.count]+ }+private static let accentColors: [Color] = [Color(red: 0.114, green: 0.62, blue: 0.46),Color(red: 0.94, green: 0.62, blue: 0.15),@@ -568,6 +678,17 @@ public struct PointerPromptSpawnOverlayView: View {Color(red: 0.24, green: 0.69, blue: 0.71),Color(red: 0.66, green: 0.34, blue: 0.79)]++ private static let inputAccentColors: [Color] = [+ Color(red: 0.69, green: 0.87, blue: 0.81),+ Color(red: 0.98, green: 0.87, blue: 0.70),+ Color(red: 0.94, green: 0.77, blue: 0.82),+ Color(red: 0.73, green: 0.84, blue: 0.95),+ Color(red: 0.83, green: 0.81, blue: 0.95),+ Color(red: 0.96, green: 0.77, blue: 0.75),+ Color(red: 0.73, green: 0.89, blue: 0.90),+ Color(red: 0.88, green: 0.77, blue: 0.93)+ ]}private struct TypewriterText: View {@@ -604,12 +725,13 @@ private struct TypewriterText: View {}}-private struct SpawnLabelTextInput: NSViewRepresentable {+private struct SpawnLabelInlineTextInput: NSViewRepresentable {@Binding var text: Stringlet isActive: Boollet textHeightChanged: @MainActor (CGFloat) -> Voidlet submit: @MainActor () -> Voidlet cancel: @MainActor () -> Void+ let focusLost: @MainActor () -> Voidfunc makeNSView(context: Context) -> NSScrollView {let scrollView = NSScrollView()@@ -619,7 +741,7 @@ private struct SpawnLabelTextInput: NSViewRepresentable {scrollView.hasHorizontalScroller = falsescrollView.autohidesScrollers = true- let textView = SpawnLabelTextView()+ let textView = SpawnLabelInlineTextView()textView.delegate = context.coordinatortextView.shouldFocusWhenAttached = isActivetextView.submit = {@@ -632,9 +754,14 @@ private struct SpawnLabelTextInput: NSViewRepresentable {cancel()}}+ textView.focusLost = {+ Task { @MainActor in+ focusLost()+ }+ }textView.string = text- textView.insertionPointColor = .white- SpawnLabelTextStyle.apply(to: textView)+ textView.insertionPointColor = NSColor.black.withAlphaComponent(0.72)+ SpawnLabelInlineTextStyle.apply(to: textView)textView.backgroundColor = .cleartextView.drawsBackground = falsetextView.isRichText = false@@ -644,7 +771,7 @@ private struct SpawnLabelTextInput: NSViewRepresentable {textView.isSelectable = truetextView.isHorizontallyResizable = falsetextView.isVerticallyResizable = true- textView.minSize = CGSize(width: 0, height: PointerPromptSpawnOverlayViewModel.inputMinimumTextHeight)+ textView.minSize = CGSize(width: 0, height: PointerPromptSpawnOverlayViewModel.inlineEditorMinimumTextHeight)textView.maxSize = CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)textView.autoresizingMask = [.width]textView.textContainerInset = .zero@@ -658,7 +785,7 @@ private struct SpawnLabelTextInput: NSViewRepresentable {func updateNSView(_ scrollView: NSScrollView, context: Context) {context.coordinator.parent = self- guard let textView = scrollView.documentView as? SpawnLabelTextView else { return }+ guard let textView = scrollView.documentView as? SpawnLabelInlineTextView else { return }textView.shouldFocusWhenAttached = isActivetextView.submit = {@@ -671,11 +798,16 @@ private struct SpawnLabelTextInput: NSViewRepresentable {cancel()}}- SpawnLabelTextStyle.apply(to: textView)+ textView.focusLost = {+ Task { @MainActor in+ focusLost()+ }+ }+ SpawnLabelInlineTextStyle.apply(to: textView)if textView.string != text {textView.string = text- SpawnLabelTextStyle.apply(to: textView)+ SpawnLabelInlineTextStyle.apply(to: textView)textView.needsDisplay = true}@@ -695,16 +827,17 @@ private struct SpawnLabelTextInput: NSViewRepresentable {@MainActorfinal class Coordinator: NSObject, NSTextViewDelegate {- var parent: SpawnLabelTextInput+ var parent: SpawnLabelInlineTextInput- init(parent: SpawnLabelTextInput) {+ init(parent: SpawnLabelInlineTextInput) {self.parent = parent}func textDidChange(_ notification: Notification) {- guard let textView = notification.object as? SpawnLabelTextView else { return }+ guard let textView = notification.object as? SpawnLabelInlineTextView else { return }parent.text = textView.string+ SpawnLabelInlineTextStyle.apply(to: textView)textView.needsDisplay = truereportTextHeight(for: textView)textView.scrollRangeToVisible(textView.selectedRange())@@ -717,7 +850,7 @@ private struct SpawnLabelTextInput: NSViewRepresentable {let width = max(1, scrollView.contentView.bounds.width)textView.textContainer?.containerSize = CGSize(width: width, height: .greatestFiniteMagnitude)let documentHeight = max(- PointerPromptSpawnOverlayViewModel.inputMinimumTextHeight,+ PointerPromptSpawnOverlayViewModel.inlineEditorMinimumTextHeight,measuredTextHeight(for: textView))textView.frame = CGRect(x: 0, y: 0, width: width, height: documentHeight)@@ -730,22 +863,23 @@ private struct SpawnLabelTextInput: NSViewRepresentable {private func measuredTextHeight(for textView: NSTextView) -> CGFloat {guard let layoutManager = textView.layoutManager,let textContainer = textView.textContainer else {- return PointerPromptSpawnOverlayViewModel.inputMinimumTextHeight+ return PointerPromptSpawnOverlayViewModel.inlineEditorMinimumTextHeight}layoutManager.ensureLayout(for: textContainer)let usedRect = layoutManager.usedRect(for: textContainer)return ceil(max(- PointerPromptSpawnOverlayViewModel.inputMinimumTextHeight,+ PointerPromptSpawnOverlayViewModel.inlineEditorMinimumTextHeight,usedRect.height))}}}-private final class SpawnLabelTextView: NSTextView {+private final class SpawnLabelInlineTextView: NSTextView {var submit: (() -> Void)?var cancel: (() -> Void)?+ var focusLost: (() -> Void)?var shouldFocusWhenAttached = falseoverride var acceptsFirstResponder: Bool {@@ -760,7 +894,19 @@ private final class SpawnLabelTextView: NSTextView {func focusIfNeeded() {guard shouldFocusWhenAttached else { return }- window?.makeFirstResponder(self)+ DispatchQueue.main.async { [weak self] in+ guard let self else { return }++ self.window?.makeFirstResponder(self)+ }+ }++ override func resignFirstResponder() -> Bool {+ let didResign = super.resignFirstResponder()+ if didResign {+ focusLost?()+ }+ return didResign}override func keyDown(with event: NSEvent) {@@ -783,15 +929,16 @@ private final class SpawnLabelTextView: NSTextView {}@MainActor-private enum SpawnLabelTextStyle {+private enum SpawnLabelInlineTextStyle {static var font: NSFont {- NSFont.systemFont(ofSize: 12, weight: .regular)+ NSFont.systemFont(ofSize: 13, weight: .medium)}static func apply(to textView: NSTextView) {- let textAttributes = attributes(color: .white, font: font)+ let textAttributes = attributes(color: NSColor.black.withAlphaComponent(0.68), font: font)textView.font = font- textView.textColor = .white+ textView.textColor = NSColor.black.withAlphaComponent(0.68)+ textView.alignment = .lefttextView.typingAttributes = textAttributeslet textRange = NSRange(location: 0, length: textView.string.utf16.count)@@ -804,10 +951,14 @@ private enum SpawnLabelTextStyle {color: NSColor,font: NSFont) -> [NSAttributedString.Key: Any] {- [+ let paragraphStyle = NSMutableParagraphStyle()+ paragraphStyle.alignment = .left+ paragraphStyle.lineBreakMode = .byWordWrapping+ return [.foregroundColor: color,.font: font,- .ligature: 0+ .ligature: 0,+ .paragraphStyle: paragraphStyle]}}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptSpawnGeometryTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptSpawnGeometryTests.swiftindex 6e4c6b48..b71598f5 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptSpawnGeometryTests.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptSpawnGeometryTests.swift@@ -1,5 +1,6 @@import CoreGraphicsimport DonkeyContracts+import DonkeyUIimport Testing@Suite@@ -70,4 +71,138 @@ struct PointerPromptSpawnGeometryTests {))}++ @Test @MainActor+ func spawnOverlayPlacesCursorInsideViewportAndLabelAboveIt() {+ let viewModel = PointerPromptSpawnOverlayViewModel()+ let cursorPoint = CGPoint(x: 600, y: 282)+ let screenSize = CGSize(width: 1200, height: 800)+ let state = PointerPromptSpawnState(+ id: "spawn-1",+ commandText: "hi there",+ label: "hi there",+ accentIndex: 1,+ phase: .holding+ )++ viewModel.show(+ state: state,+ origin: cursorPoint,+ destination: cursorPoint,+ screenSize: screenSize+ )+ let cursorFrame = viewModel.cursorOnlyVisualFrame(at: cursorPoint)+ viewModel.updateViewport(origin: cursorFrame.origin, size: cursorFrame.size)++ #expect(viewModel.localCursorCenter.x == cursorFrame.width / 2)+ #expect(viewModel.localCursorCenter.y == cursorFrame.height / 2)+ #expect(viewModel.localHaloCenter.x == viewModel.localCursorCenter.x)+ #expect(viewModel.localHaloCenter.y > viewModel.localCursorCenter.y)+ #expect(viewModel.localLabelCenter(in: screenSize).x == viewModel.localCursorCenter.x)+ #expect(viewModel.localLabelCenter(in: screenSize).y < viewModel.localCursorCenter.y)+ #expect(viewModel.localCursorCenter.y - viewModel.localLabelCenter(in: screenSize).y == 46)+ }++ @Test @MainActor+ func spawnLabelOnlyExpandsOnHoverWhenCollapsedTextOverflows() {+ let viewModel = PointerPromptSpawnOverlayViewModel()+ let shortState = PointerPromptSpawnState(+ id: "spawn-1",+ commandText: "hi there",+ label: "hi there",+ accentIndex: 1,+ phase: .holding+ )++ viewModel.show(+ state: shortState,+ origin: CGPoint(x: 600, y: 282),+ destination: CGPoint(x: 600, y: 282),+ screenSize: CGSize(width: 1200, height: 800)+ )+ viewModel.setLabelHovered(true)+ #expect(!viewModel.isLabelHovered)++ let longState = PointerPromptSpawnState(+ id: "spawn-1",+ commandText: "long",+ label: Array(repeating: "details", count: 30).joined(separator: " "),+ accentIndex: 1,+ phase: .holding+ )+ viewModel.update(+ state: longState,+ destination: CGPoint(x: 600, y: 282),+ screenSize: CGSize(width: 1200, height: 800)+ )+ viewModel.setLabelHovered(true)+ #expect(viewModel.isLabelHovered)+ }++ @Test @MainActor+ func inlineSpawnLabelEditorSubmitsTrimmedFollowUpForTask() {+ let viewModel = PointerPromptSpawnOverlayViewModel()+ let state = PointerPromptSpawnState(+ id: "spawn-1",+ taskID: "task-1",+ commandText: "hi there",+ label: "hi there",+ accentIndex: 1,+ phase: .holding+ )+ var submittedSpawnID: String?+ var submittedTaskID: String?+ var submittedText: String?+ viewModel.followUpSubmitted = { spawnID, taskID, text in+ submittedSpawnID = spawnID+ submittedTaskID = taskID+ submittedText = text+ }++ viewModel.show(+ state: state,+ origin: CGPoint(x: 600, y: 282),+ destination: CGPoint(x: 600, y: 282),+ screenSize: CGSize(width: 1200, height: 800)+ )+ viewModel.beginInlineInput()+ #expect(viewModel.isLabelEditing)+ #expect(viewModel.freezesMovement)++ viewModel.draftText = " do this next "+ viewModel.submitInlineInput()++ #expect(!viewModel.isLabelEditing)+ #expect(!viewModel.freezesMovement)+ #expect(submittedSpawnID == "spawn-1")+ #expect(submittedTaskID == "task-1")+ #expect(submittedText == "do this next")+ }++ @Test @MainActor+ func inlineSpawnLabelEditorClosesWhenIdleFocusIsLost() {+ let viewModel = PointerPromptSpawnOverlayViewModel()+ let state = PointerPromptSpawnState(+ id: "spawn-1",+ taskID: "task-1",+ commandText: "hi there",+ label: "hi there",+ accentIndex: 1,+ phase: .holding+ )++ viewModel.show(+ state: state,+ origin: CGPoint(x: 600, y: 282),+ destination: CGPoint(x: 600, y: 282),+ screenSize: CGSize(width: 1200, height: 800)+ )+ viewModel.beginInlineInput()+ #expect(viewModel.isLabelEditing)++ viewModel.closeInlineInputIfIdle()++ #expect(!viewModel.isLabelEditing)+ #expect(viewModel.draftText.isEmpty)+ }}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptSpawnLifecycleTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptSpawnLifecycleTests.swiftindex 9b1a6bc9..9b92fcdd 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptSpawnLifecycleTests.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptSpawnLifecycleTests.swift@@ -4,82 +4,13 @@ import Testing@Suitestruct PointerPromptSpawnLifecycleTests {@Test- func inputFreezeTracksEditingAndDirtyDrafts() {- #expect(- PointerPromptSpawnLifecycle.freezesMovement(- inputState: .editing,- draftText: ""- )- )- #expect(- PointerPromptSpawnLifecycle.freezesMovement(- inputState: .collapsed,- draftText: " clarify this "- )- )- #expect(- !PointerPromptSpawnLifecycle.freezesMovement(- inputState: .collapsed,- draftText: " \n"- )- )+ func completedActionSpawnsCanFadeButConversationStaysReadable() {+ #expect(!PointerPromptSpawnLifecycle.keepsVisibleResult(for: .completed))+ #expect(PointerPromptSpawnLifecycle.keepsVisibleResult(for: .chatting))+ #expect(PointerPromptSpawnLifecycle.keepsVisibleResult(for: .waitingForClarification))+ #expect(PointerPromptSpawnLifecycle.keepsVisibleResult(for: .waitingForReview))+ #expect(PointerPromptSpawnLifecycle.keepsVisibleResult(for: .needsAttention))+ #expect(PointerPromptSpawnLifecycle.keepsVisibleResult(for: .failed))}- @Test- func followUpSubmissionRoutesToSameTask() throws {- let state = PointerPromptSpawnState(- id: "spawn-1",- taskID: "task-1",- commandText: "open music",- label: "Waiting for detail",- accentIndex: 3,- phase: .holding- )-- let submission = try #require(- PointerPromptSpawnLifecycle.followUpSubmission(- from: state,- text: " play the next song "- )- )-- #expect(submission.spawnID == "spawn-1")- #expect(submission.taskID == "task-1")- #expect(submission.text == "play the next song")- }-- @Test- func followUpSubmissionRequiresTaskAndText() {- let state = PointerPromptSpawnState(- id: "spawn-1",- taskID: nil,- commandText: "answer this",- label: "Answering",- accentIndex: 0,- phase: .holding- )-- #expect(- PointerPromptSpawnLifecycle.followUpSubmission(- from: state,- text: "more detail"- ) == nil- )-- let taskedState = PointerPromptSpawnState(- id: "spawn-2",- taskID: "task-2",- commandText: "open notes",- label: "Waiting",- accentIndex: 1,- phase: .holding- )-- #expect(- PointerPromptSpawnLifecycle.followUpSubmission(- from: taskedState,- text: " \n "- ) == nil- )- }}