Skip to content

Open source CapCut alternative.

TypeScript

Clean up

David Le6380a3337356
diff --git a/apps/Donkey/README.md b/apps/Donkey/README.md
index 8a048162..f908697f 100644
--- a/apps/Donkey/README.md
+++ b/apps/Donkey/README.md
@@ -2,9 +2,9 @@
SwiftUI macOS app for the production pointer prompt UI.
-This slice renders a floating native-cursor-sized agent arrowhead and ChatGPT-style `Make this so` composer. Donkey starts in an inactive pointer-only state that follows the main pointer. Command-click anywhere to show and focus the composer at the current pointer location, where the pointer and composer stay pinned until dismissed or dragged. The composer includes a top-left close button, a text area, and controls such as add context, voice, and send; the blue pointer shadow appears only while active. The overlay follows the mouse on a 45-degree bottom-right diagonal by default, flips around an invisible cursor-centered box near screen edges, and clamps itself inside the visible screen.
+This slice renders a floating native-cursor-sized agent arrowhead and compact prompt modal with a live voice waveform. Donkey starts in an inactive pointer-only state that follows the main pointer. Double-tap Command and release to show and focus the prompt modal at the current pointer location, where the pointer and modal stay pinned while live microphone levels drive the waveform. The prompt starts as a wide pill, expands into a rounded rectangle for multiline text, and moves the waveform into a bottom toolbar that matches the input background. Clicking outside the modal dismisses it, and a small gray circular x button at the top-right outside corner closes it directly. The overlay follows the mouse on a 45-degree bottom-right diagonal by default.
-It does not request Accessibility, Screen Recording, model access, capture-loop, or input-control permissions.
+It requests microphone permission for local waveform visualization. It does not request Accessibility, Screen Recording, model access, screen capture-loop, or input-control permissions.
Guides:
diff --git a/apps/Donkey/Sources/Donkey/DonkeyAppDelegate.swift b/apps/Donkey/Sources/Donkey/DonkeyAppDelegate.swift
index 8b8033cd..5be96cdd 100644
--- a/apps/Donkey/Sources/Donkey/DonkeyAppDelegate.swift
+++ b/apps/Donkey/Sources/Donkey/DonkeyAppDelegate.swift
@@ -5,6 +5,8 @@ final class DonkeyAppDelegate: NSObject, NSApplicationDelegate {
private var overlayController: PointerPromptOverlayController?
func applicationDidFinishLaunching(_ notification: Notification) {
+ NSApp.setActivationPolicy(.accessory)
+
let model = PointerPromptOverlayModel()
let controller = PointerPromptOverlayController(model: model)
overlayController = controller
diff --git a/apps/Donkey/Sources/Donkey/MicrophoneWaveformMeter.swift b/apps/Donkey/Sources/Donkey/MicrophoneWaveformMeter.swift
new file mode 100644
index 00000000..f6f0d116
--- /dev/null
+++ b/apps/Donkey/Sources/Donkey/MicrophoneWaveformMeter.swift
@@ -0,0 +1,135 @@
+import AVFoundation
+import DonkeyContracts
+import Foundation
+
+@MainActor
+final class MicrophoneWaveformMeter {
+ private let engine = AVAudioEngine()
+ private let barCount = PointerPromptState.defaultVoiceWaveformLevels.count
+ private var levels = PointerPromptState.defaultVoiceWaveformLevels
+ private var isRunning = false
+ private var isStarting = false
+
+ var onLevelsChanged: (([Double]) -> Void)?
+
+ func start() {
+ guard !isRunning, !isStarting else { return }
+
+ isStarting = true
+ AVCaptureDevice.requestAccess(for: .audio) { [weak self] isGranted in
+ Task { @MainActor in
+ guard self?.isStarting == true else { return }
+
+ guard isGranted else {
+ self?.isStarting = false
+ self?.publishSilence()
+ return
+ }
+
+ self?.startEngine()
+ }
+ }
+ }
+
+ func stop() {
+ guard isRunning || isStarting else { return }
+
+ engine.inputNode.removeTap(onBus: 0)
+ engine.stop()
+ isRunning = false
+ isStarting = false
+ publishSilence()
+ }
+
+ private func startEngine() {
+ guard !isRunning else {
+ isStarting = false
+ return
+ }
+
+ let inputNode = engine.inputNode
+ let format = inputNode.outputFormat(forBus: 0)
+ levels = PointerPromptState.defaultVoiceWaveformLevels
+ publishLevels()
+
+ inputNode.removeTap(onBus: 0)
+ inputNode.installTap(
+ onBus: 0,
+ bufferSize: 512,
+ format: format,
+ block: Self.makeTapBlock(meter: self)
+ )
+
+ engine.prepare()
+
+ do {
+ try engine.start()
+ isRunning = true
+ isStarting = false
+ } catch {
+ inputNode.removeTap(onBus: 0)
+ isRunning = false
+ isStarting = false
+ publishSilence()
+ }
+ }
+
+ private func append(_ level: Double) {
+ levels.append(level)
+ if levels.count > barCount {
+ levels.removeFirst(levels.count - barCount)
+ }
+
+ publishLevels()
+ }
+
+ private func publishSilence() {
+ levels = Array(repeating: 0.08, count: barCount)
+ publishLevels()
+ }
+
+ private func publishLevels() {
+ onLevelsChanged?(levels)
+ }
+
+ nonisolated private static func makeTapBlock(meter: MicrophoneWaveformMeter) -> AVAudioNodeTapBlock {
+ { [weak meter] buffer, _ in
+ let level = Self.normalizedLevel(from: buffer)
+
+ Task { @MainActor in
+ meter?.append(level)
+ }
+ }
+ }
+
+ nonisolated private static func normalizedLevel(from buffer: AVAudioPCMBuffer) -> Double {
+ guard let channelData = buffer.floatChannelData,
+ buffer.frameLength > 0 else {
+ return 0
+ }
+
+ let channelCount = Int(buffer.format.channelCount)
+ let frameCount = Int(buffer.frameLength)
+ var sumOfSquares: Float = 0
+ var sampleCount = 0
+
+ for channel in 0..<channelCount {
+ let samples = channelData[channel]
+
+ for frame in 0..<frameCount {
+ let sample = samples[frame]
+ sumOfSquares += sample * sample
+ }
+
+ sampleCount += frameCount
+ }
+
+ guard sampleCount > 0 else { return 0 }
+
+ let rms = sqrt(sumOfSquares / Float(sampleCount))
+ let decibels = 20 * log10(max(rms, 0.000_001))
+ let normalized = (Double(decibels) + 55) / 45
+
+ return min(max(normalized, 0), 1)
+ }
+}
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
index e158da85..63bdbefc 100644
--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
@@ -9,6 +9,7 @@ final class PointerPromptOverlayController {
private let model: PointerPromptOverlayModel
private let fixedPlacement: PointerPromptPlacement = .bottomRight
private let activationShortcut: PointerPromptActivationShortcut
+ private let microphoneWaveformMeter = MicrophoneWaveformMeter()
private var panel: NSPanel?
private var timer: Timer?
@@ -26,6 +27,9 @@ final class PointerPromptOverlayController {
) {
self.model = model
self.activationShortcut = activationShortcut
+ microphoneWaveformMeter.onLevelsChanged = { [weak model] levels in
+ model?.updateVoiceWaveformLevels(levels)
+ }
}
func show() {
@@ -74,6 +78,7 @@ final class PointerPromptOverlayController {
timer?.invalidate()
timer = nil
stopActivationMonitoring()
+ microphoneWaveformMeter.stop()
panel?.close()
panel = nil
}
@@ -126,6 +131,11 @@ final class PointerPromptOverlayController {
case .flagsChanged:
handleModifierFlagsChanged(modifierFlags)
case .keyDown, .leftMouseDown, .rightMouseDown, .otherMouseDown:
+ if type != .keyDown, dismissActivePromptIfClickIsOutside() {
+ resetActivationTapSequence()
+ return
+ }
+
resetActivationTapSequence()
default:
break
@@ -237,9 +247,11 @@ final class PointerPromptOverlayController {
private func activateAtCurrentMouseLocation() {
guard !model.promptState.isActive else {
- NSApp.activate(ignoringOtherApps: true)
- panel?.makeKeyAndOrderFront(nil)
+ if let panel {
+ activateForKeyboardInput(panel)
+ }
focusComposerTextInput()
+ microphoneWaveformMeter.start()
return
}
@@ -259,10 +271,10 @@ final class PointerPromptOverlayController {
guard let panel else { return }
model.activate()
+ microphoneWaveformMeter.start()
tick(mouseLocation: mouseLocation)
- NSApp.activate(ignoringOtherApps: true)
- panel.makeKeyAndOrderFront(nil)
+ activateForKeyboardInput(panel)
focusComposerTextInput()
}
@@ -280,6 +292,10 @@ final class PointerPromptOverlayController {
private func tick(mouseLocation explicitMouseLocation: CGPoint? = nil) {
guard let panel else { return }
+ if !model.promptState.isActive {
+ microphoneWaveformMeter.stop()
+ }
+
activateVoiceInputIfNeeded()
updateMouseEventPassthrough(for: panel)
if model.promptState.isActive, explicitMouseLocation == nil {
@@ -390,46 +406,15 @@ final class PointerPromptOverlayController {
guard model.promptState.isActive else { return [] }
let composerFrame = composerFrame(for: fixedPlacement)
- let inputFrame = composerInputFrame(in: composerFrame)
- let closeControlFrame = CGRect(
- x: composerFrame.minX + PointerPromptLayout.closeButtonInset,
- y: composerFrame.maxY -
- PointerPromptLayout.closeButtonInset -
- PointerPromptLayout.closeButtonSize,
- width: PointerPromptLayout.closeControlWidth,
- height: PointerPromptLayout.closeButtonSize
- ).insetBy(dx: -6, dy: -6)
-
+ let inputSurfaceFrame = composerInputSurfaceFrame(in: composerFrame)
+ let closeButtonFrame = composerCloseButtonFrame(in: composerFrame).insetBy(dx: -3, dy: -3)
var regions = [
- CGRect(
- x: closeControlFrame.maxX,
- y: inputFrame.maxY,
- width: composerFrame.maxX - closeControlFrame.maxX,
- height: composerFrame.maxY - inputFrame.maxY
- ),
- CGRect(
- x: composerFrame.minX,
- y: inputFrame.maxY,
- width: closeControlFrame.minX - composerFrame.minX,
- height: composerFrame.maxY - inputFrame.maxY
- ),
+ inputSurfaceFrame,
CGRect(
x: composerFrame.minX,
- y: inputFrame.minY,
- width: inputFrame.minX - composerFrame.minX,
- height: inputFrame.height
- ),
- CGRect(
- x: inputFrame.maxX,
- y: inputFrame.minY,
- width: composerFrame.maxX - inputFrame.maxX,
- height: inputFrame.height
- ),
- CGRect(
- x: composerFrame.minX,
- y: composerFrame.minY,
- width: composerFrame.width,
- height: inputFrame.minY - composerFrame.minY
+ y: inputSurfaceFrame.maxY,
+ width: max(0, closeButtonFrame.minX - composerFrame.minX),
+ height: max(0, composerFrame.maxY - inputSurfaceFrame.maxY)
)
]
@@ -450,9 +435,12 @@ final class PointerPromptOverlayController {
return CGRect(
x: x,
- y: currentContentSize.height - composerTopFromPanelTop - currentComposerHeight,
+ y: currentContentSize.height -
+ composerTopFromPanelTop -
+ PointerPromptLayout.externalCloseButtonOutsideMargin -
+ currentComposerHeight,
width: PointerPromptLayout.composerWidth,
- height: currentComposerHeight
+ height: currentComposerHeight + PointerPromptLayout.externalCloseButtonOutsideMargin
)
}
@@ -460,16 +448,51 @@ final class PointerPromptOverlayController {
stageVerticalInset + PointerPromptLayout.stageVerticalPadding
}
- private func composerInputFrame(in composerFrame: CGRect) -> CGRect {
- let inputHeight = PointerPromptLayout.composerInputHeight(
- inputTextHeight: model.inputTextHeight
+ private func composerInputSurfaceFrame(in composerFrame: CGRect) -> CGRect {
+ return CGRect(
+ x: composerFrame.minX,
+ y: composerFrame.minY,
+ width: PointerPromptLayout.composerInputSurfaceWidth,
+ height: PointerPromptLayout.composerInputHeight(inputTextHeight: model.inputTextHeight)
)
+ }
+
+ private func composerCloseButtonFrame(in composerFrame: CGRect) -> CGRect {
+ CGRect(
+ x: composerFrame.maxX - PointerPromptLayout.externalCloseButtonSize,
+ y: composerFrame.maxY - PointerPromptLayout.externalCloseButtonSize,
+ width: PointerPromptLayout.externalCloseButtonSize,
+ height: PointerPromptLayout.externalCloseButtonSize
+ )
+ }
+
+ private func composerTextInputFrame(in inputSurfaceFrame: CGRect) -> CGRect {
+ if PointerPromptLayout.isComposerInputExpanded(inputTextHeight: model.inputTextHeight) {
+ return CGRect(
+ x: inputSurfaceFrame.minX +
+ PointerPromptLayout.composerExpandedTextHorizontalPadding,
+ y: inputSurfaceFrame.maxY -
+ PointerPromptLayout.composerExpandedTextTopPadding -
+ model.inputTextHeight,
+ width: inputSurfaceFrame.width -
+ PointerPromptLayout.composerExpandedTextHorizontalPadding * 2,
+ height: model.inputTextHeight
+ )
+ }
+
+ let waveformAndSpacingWidth: CGFloat = 54 + 12
+ let x = inputSurfaceFrame.minX + PointerPromptLayout.composerInputLeadingContentPadding
+ let width = inputSurfaceFrame.width -
+ PointerPromptLayout.composerInputLeadingContentPadding -
+ PointerPromptLayout.composerInputTrailingContentPadding -
+ waveformAndSpacingWidth
+ let height = model.inputTextHeight
return CGRect(
- x: composerFrame.minX + PointerPromptLayout.composerInputHorizontalPadding,
- y: composerFrame.minY + PointerPromptLayout.composerBottomPadding,
- width: composerFrame.width - PointerPromptLayout.composerInputHorizontalPadding * 2,
- height: inputHeight
+ x: x,
+ y: inputSurfaceFrame.midY - height / 2,
+ width: width,
+ height: height
)
}
@@ -488,6 +511,22 @@ final class PointerPromptOverlayController {
panel.ignoresMouseEvents = !composerFrame(for: fixedPlacement).contains(mouseLocationInPanel)
}
+ private func dismissActivePromptIfClickIsOutside() -> Bool {
+ guard model.promptState.isActive,
+ let panel else {
+ return false
+ }
+
+ let mouseLocationInPanel = panel.convertPoint(fromScreen: NSEvent.mouseLocation)
+ guard !composerFrame(for: fixedPlacement).contains(mouseLocationInPanel) else {
+ return false
+ }
+
+ model.handle(.dismissed)
+ microphoneWaveformMeter.stop()
+ return true
+ }
+
private var currentContentSize: CGSize {
PointerPromptLayout.contentSize(inputTextHeight: model.inputTextHeight)
}
@@ -518,8 +557,7 @@ final class PointerPromptOverlayController {
private func focusComposerTextInput(attempt: Int = 0) {
guard let panel else { return }
- panel.ignoresMouseEvents = false
- panel.makeKeyAndOrderFront(nil)
+ activateForKeyboardInput(panel)
guard let textView = firstComposerTextView(in: panel.contentView) else {
guard attempt < 8 else { return }
@@ -532,6 +570,24 @@ final class PointerPromptOverlayController {
panel.makeFirstResponder(textView)
textView.window?.makeFirstResponder(textView)
+
+ guard attempt < 8,
+ (!NSApp.isActive ||
+ !panel.isKeyWindow ||
+ !isComposerTextInputFocused(in: panel)) else {
+ return
+ }
+
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.025) {
+ self.focusComposerTextInput(attempt: attempt + 1)
+ }
+ }
+
+ private func activateForKeyboardInput(_ panel: NSPanel) {
+ panel.ignoresMouseEvents = false
+ NSApp.activate(ignoringOtherApps: true)
+ panel.orderFrontRegardless()
+ panel.makeKeyAndOrderFront(nil)
}
private func firstComposerTextView(in view: NSView?) -> NSTextView? {
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
index b19d7e25..0088ee6f 100644
--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
@@ -38,6 +38,13 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
promptState.leadingSignalLevel = .ready
}
+ func updateVoiceWaveformLevels(_ levels: [Double]) {
+ let normalizedLevels = levels.map { min(max($0, 0), 1) }
+ guard promptState.voiceWaveformLevels != normalizedLevels else { return }
+
+ promptState.voiceWaveformLevels = normalizedLevels
+ }
+
func handle(_ intent: PointerPromptIntent) {
switch intent {
case .addContextRequested:
diff --git a/apps/Donkey/Sources/DonkeyContracts/PointerPromptContracts.swift b/apps/Donkey/Sources/DonkeyContracts/PointerPromptContracts.swift
index 7ed08a41..6b9e485f 100644
--- a/apps/Donkey/Sources/DonkeyContracts/PointerPromptContracts.swift
+++ b/apps/Donkey/Sources/DonkeyContracts/PointerPromptContracts.swift
@@ -2,24 +2,37 @@ import CoreGraphics
import Foundation
public struct PointerPromptState: Equatable, Sendable {
+ public static let defaultVoiceWaveformLevels: [Double] = [
+ 0.12,
+ 0.2,
+ 0.34,
+ 0.5,
+ 0.34,
+ 0.2,
+ 0.12
+ ]
+
public var promptText: String
public var isPrimaryActionEnabled: Bool
public var leadingSignalLevel: SignalLevel
public var isActive: Bool
public var theme: PointerPromptTheme
+ public var voiceWaveformLevels: [Double]
public init(
promptText: String,
isPrimaryActionEnabled: Bool = true,
leadingSignalLevel: SignalLevel = .idle,
isActive: Bool = false,
- theme: PointerPromptTheme = .defaultBlue
+ theme: PointerPromptTheme = .defaultBlue,
+ voiceWaveformLevels: [Double] = PointerPromptState.defaultVoiceWaveformLevels
) {
self.promptText = promptText
self.isPrimaryActionEnabled = isPrimaryActionEnabled
self.leadingSignalLevel = leadingSignalLevel
self.isActive = isActive
self.theme = theme
+ self.voiceWaveformLevels = voiceWaveformLevels
}
public static let productionDefault = PointerPromptState(
diff --git a/apps/Donkey/Sources/DonkeyContracts/PointerPromptLayout.swift b/apps/Donkey/Sources/DonkeyContracts/PointerPromptLayout.swift
index 4856cb76..cb88517a 100644
--- a/apps/Donkey/Sources/DonkeyContracts/PointerPromptLayout.swift
+++ b/apps/Donkey/Sources/DonkeyContracts/PointerPromptLayout.swift
@@ -1,8 +1,8 @@
import CoreGraphics
public enum PointerPromptLayout {
- public static let contentWidth: CGFloat = 448
- public static let contentExtraHeight: CGFloat = 4
+ public static let contentWidth: CGFloat = 684
+ public static let contentExtraHeight: CGFloat = 8
public static let stageHorizontalPadding: CGFloat = 8
public static let stageVerticalPadding: CGFloat = 10
public static let pointerSlotSize = CGSize(width: 58, height: 68)
@@ -12,21 +12,29 @@ public enum PointerPromptLayout {
public static let pointerDistanceFromCursor: CGFloat = 48
public static let pointerDiagonalComponent = pointerDistanceFromCursor / CGFloat(2).squareRoot()
public static let pointerComposerSpacing: CGFloat = 16
- public static let composerWidth: CGFloat = 350
- public static let composerCornerRadius: CGFloat = 12
+ public static let composerWidth: CGFloat = 576
+ public static let composerInputSurfaceWidth: CGFloat = 576
+ public static let composerCornerRadius: CGFloat = 22
public static let composerDragBorderThickness: CGFloat = 14
- public static let composerTitlebarHeight: CGFloat = 48
- public static let composerBottomPadding: CGFloat = 16
+ public static let composerTitlebarHeight: CGFloat = 0
+ public static let composerBottomPadding: CGFloat = 0
public static let composerInputHorizontalPadding: CGFloat = 16
public static let composerInputLeadingContentPadding: CGFloat = 20
public static let composerInputTrailingContentPadding: CGFloat = 8
- public static let composerInputMinimumHeight: CGFloat = 46.4
+ public static let composerInputMinimumHeight: CGFloat = 66
public static let composerInputTextMinimumHeight: CGFloat = 19.2
- public static let composerInputTextVerticalPadding: CGFloat = 13.6
+ public static let composerInputTextVerticalPadding: CGFloat = 23.4
public static let composerInputVoiceButtonSize: CGFloat = 33.6
+ public static let composerExpandedTextTopPadding: CGFloat = 18
+ public static let composerExpandedTextHorizontalPadding: CGFloat = 24
+ public static let composerExpandedToolbarHeight: CGFloat = 54
+ public static let composerExpandedMinimumHeight: CGFloat = 156
public static let closeButtonSize: CGFloat = 12
public static let closeButtonInset: CGFloat = 16
public static let closeControlWidth = closeButtonSize
+ public static let externalCloseButtonSize: CGFloat = 24
+ public static let externalCloseButtonGap: CGFloat = 2
+ public static let externalCloseButtonOutsideMargin: CGFloat = externalCloseButtonSize + externalCloseButtonGap
public static let contentSize = contentSize(inputTextHeight: composerInputTextMinimumHeight)
public static let composerSize = CGSize(
@@ -35,6 +43,22 @@ public enum PointerPromptLayout {
)
public static func composerInputHeight(inputTextHeight: CGFloat) -> CGFloat {
+ guard isComposerInputExpanded(inputTextHeight: inputTextHeight) else {
+ return composerInputMinimumHeight
+ }
+
+ let measuredHeight = inputTextHeight +
+ composerExpandedTextTopPadding +
+ composerExpandedToolbarHeight
+
+ return max(composerExpandedMinimumHeight, measuredHeight)
+ }
+
+ public static func isComposerInputExpanded(inputTextHeight: CGFloat) -> Bool {
+ inputTextHeight > composerInputTextMinimumHeight + 1
+ }
+
+ public static func singleLineComposerInputHeight(inputTextHeight: CGFloat) -> CGFloat {
max(
composerInputMinimumHeight,
inputTextHeight + composerInputTextVerticalPadding * 2
@@ -42,9 +66,7 @@ public enum PointerPromptLayout {
}
public static func composerHeight(inputTextHeight: CGFloat) -> CGFloat {
- composerTitlebarHeight +
- composerInputHeight(inputTextHeight: inputTextHeight) +
- composerBottomPadding
+ composerInputHeight(inputTextHeight: inputTextHeight)
}
public static func contentSize(inputTextHeight: CGFloat) -> CGSize {
diff --git a/apps/Donkey/Sources/DonkeyUI/PointerPromptStageView.swift b/apps/Donkey/Sources/DonkeyUI/PointerPromptStageView.swift
index 8b47e2d9..d2c7c0db 100644
--- a/apps/Donkey/Sources/DonkeyUI/PointerPromptStageView.swift
+++ b/apps/Donkey/Sources/DonkeyUI/PointerPromptStageView.swift
@@ -63,9 +63,6 @@ public struct PointerPromptStageView: View {
state: state,
messageText: $messageText,
inputTextHeight: inputTextHeight,
- voiceInput: {
- intentSink?.handle(.voiceInputRequested)
- },
dismiss: {
intentSink?.handle(.dismissed)
},
@@ -94,63 +91,236 @@ private struct PointerPromptComposer: View {
let state: PointerPromptState
@Binding var messageText: String
let inputTextHeight: CGFloat
- let voiceInput: @MainActor () -> Void
let dismiss: @MainActor () -> Void
let submit: @MainActor () -> Void
let inputTextHeightChanged: @MainActor (CGFloat) -> Void
var body: some View {
- ZStack(alignment: .topLeading) {
- HStack(spacing: 12) {
- ComposerMultilineTextInput(
- text: $messageText,
- placeholder: state.promptText,
- isActive: state.isActive,
- textHeightChanged: inputTextHeightChanged,
- submit: submit
+ ZStack(alignment: .topTrailing) {
+ promptSurface
+
+ ComposerExternalCloseButton(action: dismiss)
+ .offset(
+ x: 0,
+ y: -PointerPromptLayout.externalCloseButtonSize -
+ PointerPromptLayout.externalCloseButtonGap
)
- .frame(maxWidth: .infinity)
- .frame(height: inputTextHeight)
+ }
+ .frame(
+ width: PointerPromptLayout.composerInputSurfaceWidth,
+ height: PointerPromptLayout.composerInputHeight(inputTextHeight: inputTextHeight),
+ alignment: .topLeading
+ )
+ .padding(.top, PointerPromptLayout.externalCloseButtonSize + PointerPromptLayout.externalCloseButtonGap)
+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
+ }
- ComposerVoiceButton(action: voiceInput)
- }
- .frame(height: PointerPromptLayout.composerInputHeight(inputTextHeight: inputTextHeight))
- .padding(.leading, PointerPromptLayout.composerInputLeadingContentPadding)
- .padding(.trailing, PointerPromptLayout.composerInputTrailingContentPadding)
- .background {
- Capsule(style: .continuous)
- .fill(Color(red: 0.13, green: 0.13, blue: 0.13))
- .overlay {
- Capsule(style: .continuous)
- .stroke(Color.white.opacity(0.07), lineWidth: 1)
- }
- }
- .padding(.horizontal, PointerPromptLayout.composerInputHorizontalPadding)
- .padding(.top, PointerPromptLayout.composerTitlebarHeight)
- .padding(.bottom, PointerPromptLayout.composerBottomPadding)
+ @ViewBuilder
+ private var promptSurface: some View {
+ if isExpanded {
+ expandedPromptSurface
+ } else {
+ promptCapsule
+ }
+ }
- ComposerCloseControl(close: dismiss)
- .offset(
- x: PointerPromptLayout.closeButtonInset,
- y: PointerPromptLayout.closeButtonInset
+ private var promptCapsule: some View {
+ HStack(spacing: 12) {
+ textInput
+
+ VoiceWaveformView(levels: state.voiceWaveformLevels)
+ .frame(width: 54, height: 28)
+ }
+ .padding(.leading, PointerPromptLayout.composerInputLeadingContentPadding)
+ .padding(.trailing, PointerPromptLayout.composerInputTrailingContentPadding)
+ .frame(
+ width: PointerPromptLayout.composerInputSurfaceWidth,
+ height: PointerPromptLayout.composerInputHeight(inputTextHeight: inputTextHeight)
+ )
+ .background {
+ Capsule(style: .continuous)
+ .fill(Color.black)
+ }
+ .overlay {
+ Capsule(style: .continuous)
+ .stroke(Color.white.opacity(0.34), lineWidth: 1)
+ }
+ .shadow(
+ color: Color.black.opacity(state.isActive ? 0.2 : 0.08),
+ radius: state.isActive ? 12 : 6,
+ x: 0,
+ y: state.isActive ? 5 : 2
+ )
+ .accessibilityElement(children: .contain)
+ }
+
+ private var expandedPromptSurface: some View {
+ VStack(spacing: 0) {
+ textInput
+ .padding(.top, PointerPromptLayout.composerExpandedTextTopPadding)
+ .padding(.horizontal, PointerPromptLayout.composerExpandedTextHorizontalPadding)
+ .frame(
+ width: PointerPromptLayout.composerInputSurfaceWidth,
+ height: expandedTextAreaHeight,
+ alignment: .top
)
+
+ promptToolbar
}
- .frame(maxWidth: .infinity, maxHeight: .infinity)
+ .frame(
+ width: PointerPromptLayout.composerInputSurfaceWidth,
+ height: PointerPromptLayout.composerInputHeight(inputTextHeight: inputTextHeight)
+ )
.background {
- RoundedRectangle(cornerRadius: PointerPromptLayout.composerCornerRadius, style: .continuous)
- .fill(Color(red: 0.08, green: 0.085, blue: 0.085))
+ RoundedRectangle(
+ cornerRadius: PointerPromptLayout.composerCornerRadius,
+ style: .continuous
+ )
+ .fill(Color.black)
}
.overlay {
- RoundedRectangle(cornerRadius: PointerPromptLayout.composerCornerRadius, style: .continuous)
- .stroke(Color.white.opacity(0.09), lineWidth: 1)
+ RoundedRectangle(
+ cornerRadius: PointerPromptLayout.composerCornerRadius,
+ style: .continuous
+ )
+ .stroke(Color.white.opacity(0.28), lineWidth: 1)
}
.shadow(
- color: Color.black.opacity(state.isActive ? 0.16 : 0.08),
- radius: state.isActive ? 14 : 8,
+ color: Color.black.opacity(state.isActive ? 0.2 : 0.08),
+ radius: state.isActive ? 12 : 6,
x: 0,
- y: state.isActive ? 6 : 3
+ y: state.isActive ? 5 : 2
)
- .controlSize(.regular)
+ .accessibilityElement(children: .contain)
+ }
+
+ private var promptToolbar: some View {
+ HStack {
+ toolbarIcon(systemName: "plus")
+
+ HStack(spacing: 8) {
+ Image(systemName: "hand.raised")
+ .font(.system(size: 15, weight: .medium))
+
+ Text("Default permissions")
+ .font(.system(size: 14, weight: .medium))
+
+ Image(systemName: "chevron.down")
+ .font(.system(size: 11, weight: .semibold))
+ }
+ .foregroundStyle(Color.white.opacity(0.6))
+
+ Spacer(minLength: 0)
+
+ VoiceWaveformView(levels: state.voiceWaveformLevels)
+ .frame(width: 54, height: 28)
+ }
+ .padding(.horizontal, PointerPromptLayout.composerExpandedTextHorizontalPadding)
+ .frame(
+ width: PointerPromptLayout.composerInputSurfaceWidth,
+ height: PointerPromptLayout.composerExpandedToolbarHeight
+ )
+ .overlay(alignment: .top) {
+ Rectangle()
+ .fill(Color.white.opacity(0.08))
+ .frame(height: 1)
+ }
+ }
+
+ private func toolbarIcon(systemName: String) -> some View {
+ Image(systemName: systemName)
+ .font(.system(size: 18, weight: .regular))
+ .foregroundStyle(Color.white.opacity(0.62))
+ .frame(width: 24, height: 24)
+ }
+
+ private var textInput: some View {
+ ComposerMultilineTextInput(
+ text: $messageText,
+ placeholder: state.promptText,
+ isActive: state.isActive,
+ textHeightChanged: inputTextHeightChanged,
+ submit: submit
+ )
+ .frame(maxWidth: .infinity)
+ .frame(height: inputTextHeight)
+ }
+
+ private var expandedSurfaceHeight: CGFloat {
+ PointerPromptLayout.composerInputHeight(inputTextHeight: inputTextHeight)
+ }
+
+ private var expandedTextAreaHeight: CGFloat {
+ max(
+ inputTextHeight + PointerPromptLayout.composerExpandedTextTopPadding,
+ expandedSurfaceHeight - PointerPromptLayout.composerExpandedToolbarHeight
+ )
+ }
+
+ private var isExpanded: Bool {
+ messageText.contains("\n") ||
+ PointerPromptLayout.isComposerInputExpanded(inputTextHeight: inputTextHeight)
+ }
+}
+
+private struct ComposerExternalCloseButton: View {
+ let action: @MainActor () -> Void
+ @State private var isHovered = false
+
+ var body: some View {
+ Button(action: action) {
+ Image(systemName: "xmark")
+ .font(.system(size: 11, weight: .bold))
+ .foregroundStyle(Color.white.opacity(0.82))
+ .frame(
+ width: PointerPromptLayout.externalCloseButtonSize,
+ height: PointerPromptLayout.externalCloseButtonSize
+ )
+ .background {
+ Circle()
+ .fill(Color.white.opacity(isHovered ? 0.28 : 0.2))
+ }
+ }
+ .buttonStyle(.plain)
+ .frame(
+ width: PointerPromptLayout.externalCloseButtonSize,
+ height: PointerPromptLayout.externalCloseButtonSize
+ )
+ .contentShape(Circle())
+ .onHover { isHovered = $0 }
+ .animation(.easeOut(duration: 0.12), value: isHovered)
+ .accessibilityLabel("Close prompt")
+ }
+}
+
+private struct VoiceWaveformView: View {
+ let levels: [Double]
+
+ var body: some View {
+ HStack(spacing: 4) {
+ ForEach(Array(displayLevels.enumerated()), id: \.offset) { _, level in
+ Capsule(style: .continuous)
+ .fill(Color.white)
+ .frame(
+ width: 4,
+ height: barHeight(for: level)
+ )
+ }
+ }
+ .animation(.linear(duration: 0.08), value: displayLevels)
+ }
+
+ private var displayLevels: [Double] {
+ let clampedLevels = levels.map { min(max($0, 0), 1) }
+ guard clampedLevels.count >= 7 else {
+ return PointerPromptState.defaultVoiceWaveformLevels
+ }
+
+ return Array(clampedLevels.suffix(7))
+ }
+
+ private func barHeight(for level: Double) -> CGFloat {
+ 5 + CGFloat(level) * 24
}
}
@@ -343,92 +513,6 @@ private final class ComposerTextView: NSTextView {
}
}
-private struct ComposerCloseControl: View {
- let close: @MainActor () -> Void
-
- var body: some View {
- ComposerTrafficLight(
- color: Color.white.opacity(0.34),
- hoverColor: Color(nsColor: .systemRed),
- accessibilityLabel: "Close prompt",
- action: close
- )
- }
-}
-
-private struct ComposerTrafficLight: View {
- let color: Color
- var hoverColor: Color?
- var accessibilityLabel: String?
- var action: (@MainActor () -> Void)?
- @State private var isHovered = false
-
- @ViewBuilder
- var body: some View {
- if let action {
- Button(action: action) {
- trafficLight
- }
- .buttonStyle(.plain)
- .frame(
- width: PointerPromptLayout.closeButtonSize,
- height: PointerPromptLayout.closeButtonSize
- )
- .contentShape(Circle())
- .onHover { isHovered = $0 }
- .accessibilityLabel(accessibilityLabel ?? "Window control")
- } else {
- trafficLight
- .accessibilityHidden(true)
- }
- }
-
- private var trafficLight: some View {
- ZStack {
- Circle()
- .fill(isHovered ? hoverColor ?? color : color)
- .overlay {
- Circle()
- .stroke(Color.black.opacity(0.18), lineWidth: 0.5)
- }
-
- if action != nil {
- Image(systemName: "xmark")
- .font(.system(size: 6, weight: .bold))
- .foregroundStyle(Color.black.opacity(0.58))
- .opacity(isHovered ? 1 : 0)
- }
- }
- .animation(.easeOut(duration: 0.12), value: isHovered)
- .frame(
- width: PointerPromptLayout.closeButtonSize,
- height: PointerPromptLayout.closeButtonSize
- )
- }
-}
-
-private struct ComposerVoiceButton: View {
- let action: @MainActor () -> Void
-
- var body: some View {
- Button(action: action) {
- Image(systemName: "waveform")
- .font(.system(size: 16, weight: .semibold))
- .foregroundStyle(Color.black)
- .frame(
- width: PointerPromptLayout.composerInputVoiceButtonSize,
- height: PointerPromptLayout.composerInputVoiceButtonSize
- )
- .background {
- Circle()
- .fill(Color.white)
- }
- }
- .buttonStyle(.plain)
- .accessibilityLabel("Voice input")
- }
-}
-
private struct AgentPointerView: View {
let placement: PointerPromptPlacement
let theme: PointerPromptTheme
diff --git a/docs/guides/pointer-prompt-overlay.md b/docs/guides/pointer-prompt-overlay.md
index a29eb8e6..3b5f91d2 100644
--- a/docs/guides/pointer-prompt-overlay.md
+++ b/docs/guides/pointer-prompt-overlay.md
@@ -5,13 +5,16 @@
Donkey supports a floating macOS pointer prompt overlay:
- shows a small inactive agent pointer that follows the user pointer immediately when Donkey starts
-- double-tap Command and release to activate and focus the prompt composer at the current pointer location without clicking into the target app
+- double-tap Command and release to activate and focus a compact prompt modal at the current pointer location without clicking into the target app
- double-tap Command and hold the second Command press to activate voice input
-- shows a native-cursor-sized agent arrowhead and standard macOS-style `Make this so` composer
-- shows a dynamic multiline text input, white voice button, and active pointer shadow only while active
-- keeps the pointer and composer pinned where activation happened until the user closes or drags the composer
-- closes the active composer with a single gray traffic-light-style top-left close button that turns into a close affordance on hover
-- supports dragging the active composer from any area outside the input surface
+- shows a native-cursor-sized agent arrowhead and a black prompt modal with text input and a white voice waveform while active
+- uses a wide pill-shaped prompt for single-line text, then expands to a rounded rectangle when text wraps at the max input width or the user inserts new lines
+- places the waveform and toolbar affordances in a bottom toolbar that uses the same background color as the input when the prompt is expanded
+- captures microphone audio while active and renders the waveform from recent live audio levels
+- keeps the pointer and prompt modal pinned where activation happened until the user drags, dismisses, or closes the modal
+- dismisses the active modal when the user clicks outside it
+- closes the active modal with a small gray circular x button outside the prompt surface at the top-right corner
+- supports dragging the active modal from capsule areas outside the text input
- lets normal clicks pass through the inactive pointer-only overlay and transparent active overlay space
- follows the user mouse at a fixed 45-degree bottom-right diagonal
- keeps that fixed offset at screen edges instead of flipping or clamping to the visible screen bounds
@@ -19,28 +22,29 @@ Donkey supports a floating macOS pointer prompt overlay:
- supports user-accessible theme customization through `apps/Donkey/Sources/Donkey/Resources/theme.json`
- keeps runtime and AI harness behavior behind explicit integration boundaries
-This is a visual UI capability. It does not capture the screen, send input, call models, or require Accessibility permission.
+This is a visual and microphone-level UI capability. It does not capture the screen, send input, call models, or require Accessibility permission. It does request microphone permission so the waveform can reflect live local audio levels.
## Technical Guidelines
- The overlay window is an `NSPanel` owned by `PointerPromptOverlayController`.
+- Donkey runs with the accessory activation policy, and prompt focus must make the app active, make the panel key, then make the composer text view first responder. A blinking insertion point alone does not mean macOS is sending keyboard events to the panel.
- SwiftUI rendering stays in `DonkeyUI`; it receives `PointerPromptState` and `PointerPromptPlacement` from `DonkeyContracts`.
- Product state stays in `PointerPromptOverlayModel`.
-- Treat the composer like a compact macOS window containing a single rounded input surface. The input has a fixed width, wraps text into additional lines, and grows the overlay height as text expands.
-- Return submits typed text. Shift-Return inserts a deliberate newline.
-- The only visible input-adjacent control for now is the white voice button.
-- Composer controls should emit typed `PointerPromptIntent` values instead of reaching into runtime, AI, or controller code.
+- Treat the active modal as a compact black prompt surface with a text input, embedded waveform, and a small gray circular x button perched outside the surface at the top-right corner. It has no separate voice button.
+- Single-line input should render as a full pill. Multiline input should render as a rounded rectangle with non-pill corners and a bottom toolbar matching the input background, containing the waveform and lightweight control affordances.
+- Text wraps at the prompt width. Return submits typed text. Shift-Return inserts a deliberate newline.
+- The controller owns microphone capture and publishes normalized audio levels into product state; SwiftUI only renders the levels it receives.
- Pointer colors load from JSON into `PointerPromptTheme`; views must not hard-code product colors.
-- The active composer should use a normal system-window corner radius, reserve a small titlebar band with a single gray traffic-light-style top-left close control that shows its close affordance on hover, and keep the input surface and close control interactive while non-input composer surfaces drag the window. Transparent active overlay space must pass clicks through to windows underneath.
-- The active composer top edge should align with the highest visible point of the agent pointer.
+- The active prompt modal should use a capsule shape and keep transparent active overlay space passing clicks through to windows underneath after it dismisses.
+- The active modal top edge should align with the highest visible point of the agent pointer.
- The agent pointer should remain close to native cursor size, use the mirrored SVG cursor silhouette from the Noun Project pointer asset, point in the same up-left direction as the native macOS cursor, and keep its tip 48px from the real pointer on an equal x/y diagonal.
- Runtime placement is fixed to `bottomRight`; alternate `PointerPromptPlacement` values are only rendering variants.
-- The controller must not clamp visible pointer/composer bounds to `NSScreen.visibleFrame`; cursor positioning is a direct fixed-offset calculation.
-- Launch positioning and double-Command focus handling belong in `PointerPromptOverlayController`, not the SwiftUI view.
+- The controller must not clamp visible pointer/modal bounds to `NSScreen.visibleFrame`; cursor positioning is a direct fixed-offset calculation.
+- Launch positioning and double-Command activation handling belong in `PointerPromptOverlayController`, not the SwiftUI view.
- Double-Command is the only active shortcut today. Its default lives in `PointerPromptActivationShortcut.doubleCommand` so a future settings layer can supply a different shortcut without rewriting controller event handling.
-- Double-Command prompt activation should require two clean Command down/up taps within 450ms. Any intervening key press, mouse press, extra modifier, or overlong Command hold should reset the sequence so normal shortcuts do not summon the composer.
-- Holding the second clean Command press for the shortcut's configured hold duration should activate the composer and send the voice input intent instead of waiting for the second release.
-- Keep the overlay non-invasive: no capture loop, input execution, Accessibility prompt, or LLM call in this feature.
+- Double-Command prompt activation should require two clean Command down/up taps within 450ms. Any intervening key press, mouse press, extra modifier, or overlong Command hold should reset the sequence so normal shortcuts do not summon the modal.
+- Holding the second clean Command press for the shortcut's configured hold duration should activate the prompt modal and start microphone level capture instead of waiting for the second release.
+- Keep the overlay non-invasive: no screen capture loop, input execution, Accessibility prompt, or LLM call in this feature.
## Verification
@@ -51,7 +55,7 @@ swift build
swift run Donkey
```
-Launch Donkey and confirm only the small agent pointer appears and follows the main pointer at a fixed bottom-right diagonal offset. Double-tap Command and release to show the composer with keyboard focus, then move the mouse and confirm the active pointer and composer stay pinned. Double-tap Command again but hold the second Command press, and confirm voice input is requested. Type enough text to wrap and confirm the window grows downward while its top edge stays fixed. Press Shift-Return and confirm it inserts a newline; press Return and confirm it submits. Click through transparent overlay space into another desktop window, drag the composer from non-input areas, close it with the top-left close button, and confirm the inactive pointer resumes following the main pointer. Activate near the bottom-right screen edge to confirm the prompt keeps the same fixed offset instead of flipping or clamping. Confirm Command plus another key, Command-click, and a single Command tap do not activate the composer.
+Launch Donkey and confirm only the small agent pointer appears and follows the main pointer at a fixed bottom-right diagonal offset. Double-tap Command and release to show the black prompt capsule with keyboard focus, grant microphone permission if prompted, then speak or tap near the microphone and confirm the waveform responds to real audio levels. Type enough text to wrap and confirm the prompt changes from a pill into a rounded rectangle, grows downward while its top edge stays fixed, and moves the waveform into a blended bottom toolbar. Press Shift-Return and confirm it inserts a newline; press Return and confirm it submits. Move the mouse and confirm the active pointer and modal stay pinned. Double-tap Command again but hold the second Command press, and confirm the same prompt modal appears. Click outside the active modal and confirm it dismisses. Reactivate, click the gray rounded x button outside the capsule, and confirm it closes. Drag the modal from non-input capsule areas. Activate near the bottom-right screen edge to confirm the prompt keeps the same fixed offset instead of flipping or clamping. Confirm Command plus another key, Command-click, and a single Command tap do not activate the modal.
To verify color customization, edit `apps/Donkey/Sources/Donkey/Resources/theme.json`, rebuild, and run Donkey.