Skip to content

Open source CapCut alternative.

TypeScript

Clean up

David Le5bb695a8fdde
diff --git a/apps/Donkey/Package.swift b/apps/Donkey/Package.swift
index b0cad930..95f6bcf6 100644
--- a/apps/Donkey/Package.swift
+++ b/apps/Donkey/Package.swift
@@ -38,7 +38,6 @@ let package = Package(
dependencies: [
"DonkeyAI",
"DonkeyContracts",
- "DonkeyRuntime",
"DonkeyUI"
],
resources: [
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
index 21a3a75f..67c0dcba 100644
--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
@@ -4,8 +4,6 @@ import SwiftUI
@MainActor
final class PointerPromptOverlayController {
- static let contentSize = PointerPromptLayout.contentSize
-
private let model: PointerPromptOverlayModel
private let fixedPlacement: PointerPromptPlacement = .bottomRight
private let activationShortcut: PointerPromptActivationShortcut
@@ -33,20 +31,38 @@ final class PointerPromptOverlayController {
}
func show() {
- let rootView = PointerPromptOverlayRootView(model: model)
let initialContentSize = currentContentSize
- let hostingView = NSHostingView(rootView: rootView)
- hostingView.frame = CGRect(origin: .zero, size: initialContentSize)
+ let hostingView = makeHostingView(size: initialContentSize)
+ let panel = makePanel(size: initialContentSize, hostingView: hostingView)
+
+ self.panel = panel
+ startActivationMonitoring()
+ positionAtCurrentMouseLocation()
+ panel.orderFrontRegardless()
+ startTimer()
+ }
+
+ private func makeHostingView(size: CGSize) -> NSHostingView<PointerPromptOverlayRootView> {
+ let hostingView = NSHostingView(rootView: PointerPromptOverlayRootView(model: model))
+ hostingView.frame = CGRect(origin: .zero, size: size)
hostingView.autoresizingMask = [.width, .height]
hostingView.wantsLayer = true
hostingView.layer?.backgroundColor = NSColor.clear.cgColor
+ return hostingView
+ }
+
+ private func makePanel(
+ size: CGSize,
+ hostingView: NSHostingView<PointerPromptOverlayRootView>
+ ) -> PointerPromptPanel {
let panel = PointerPromptPanel(
- contentRect: CGRect(origin: .zero, size: initialContentSize),
+ contentRect: CGRect(origin: .zero, size: size),
styleMask: [.borderless],
backing: .buffered,
defer: false
)
+
panel.title = "Donkey"
panel.contentView = hostingView
panel.backgroundColor = .clear
@@ -67,11 +83,7 @@ final class PointerPromptOverlayController {
.stationary
]
- self.panel = panel
- startActivationMonitoring()
- positionAtCurrentMouseLocation()
- panel.orderFrontRegardless()
- startTimer()
+ return panel
}
func stop() {
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
index f2834511..03076076 100644
--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
@@ -1,6 +1,5 @@
import DonkeyAI
import DonkeyContracts
-import DonkeyRuntime
import Foundation
import SwiftUI
@@ -12,17 +11,10 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
@Published var inputTextHeight = PointerPromptLayout.composerInputTextMinimumHeight
@Published var isInputExpanded = false
- private let runtimeProvider: any RuntimeStatusProviding
- private let aiProvider: any AIHarnessSnapshotProviding
-
init(
- runtimeProvider: any RuntimeStatusProviding = OffTheShelfRunLoopBoundary(),
aiProvider: any AIHarnessSnapshotProviding = AIHarnessBoundary(),
theme: PointerPromptTheme = PointerPromptOverlayModel.bundledTheme()
) {
- self.runtimeProvider = runtimeProvider
- self.aiProvider = aiProvider
-
let aiSnapshot = aiProvider.snapshot()
promptState = PointerPromptState(
promptText: aiSnapshot.suggestedPromptText,
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayRootView.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayRootView.swift
index 4f40bc5a..4fbdf9ae 100644
--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayRootView.swift
+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayRootView.swift
@@ -15,14 +15,15 @@ struct PointerPromptOverlayRootView: View {
intentSink: model
)
.frame(
- width: PointerPromptLayout.contentSize(
- inputTextHeight: model.inputTextHeight,
- isExpanded: model.isInputExpanded
- ).width,
- height: PointerPromptLayout.contentSize(
- inputTextHeight: model.inputTextHeight,
- isExpanded: model.isInputExpanded
- ).height
+ width: contentSize.width,
+ height: contentSize.height
+ )
+ }
+
+ private var contentSize: CGSize {
+ PointerPromptLayout.contentSize(
+ inputTextHeight: model.inputTextHeight,
+ isExpanded: model.isInputExpanded
)
}
}
diff --git a/plans/00-overview.md b/plans/00-overview.md
index 384051e8..32d7935e 100644
--- a/plans/00-overview.md
+++ b/plans/00-overview.md
@@ -74,6 +74,7 @@ Every frame should use local, bounded-cost logic:
- [18-macos-accessibility.md](18-macos-accessibility.md): macOS Accessibility tree/action backend
- [19-ai-harness.md](19-ai-harness.md): slow-path memory, LLM/VLM connection, model routing, and update plan
- [20-off-the-shelf-run-loop.md](20-off-the-shelf-run-loop.md): off-the-shelf perception, deterministic control, and low-latency runtime stack
+- [22-manual-target-context-capture.md](22-manual-target-context-capture.md): manual screenshot, Accessibility tree, and trace artifact capture for one run
## System Priorities
diff --git a/plans/22-manual-target-context-capture.md b/plans/22-manual-target-context-capture.md
new file mode 100644
index 00000000..cddb969a
--- /dev/null
+++ b/plans/22-manual-target-context-capture.md
@@ -0,0 +1,177 @@
+# Manual Target Context Capture
+
+## Goal
+
+Build the first read-only data capture milestone for Donkey runs.
+
+One manual command or UI action should create a run session, select any visible target window, capture a screenshot, dump a shallow macOS Accessibility tree, write trace artifacts, and publish ordered runtime events.
+
+This should prove the data path before continuous capture, perception models, or synthetic input are added.
+
+## Related Plans And Guides
+
+- [20-off-the-shelf-run-loop.md](20-off-the-shelf-run-loop.md): runtime shell, event streams, session lifecycle, and coordinator boundary
+- [18-macos-accessibility.md](18-macos-accessibility.md): Accessibility tree/action backend and iPhone Mirroring window guard
+- [02-capture-and-perception.md](02-capture-and-perception.md): screenshot capture and world-state direction
+- [06-benchmarking.md](06-benchmarking.md): trace events, timestamps, and run artifact shape
+- [12-iphone-mirroring.md](12-iphone-mirroring.md): first target surface for mobile-game capture
+- [../docs/guides/minimal-run-coordinator.md](../docs/guides/minimal-run-coordinator.md): supported run coordinator behavior
+
+## Scope
+
+Build a manual, read-only capture flow:
+
+```text
+prompt / debug command
+ -> RunSession
+ -> target window resolver
+ -> screenshot capture
+ -> Accessibility tree snapshot
+ -> trace artifact write
+ -> RunCoordinator tool/lifecycle events
+ -> compact context summary
+```
+
+In scope:
+
+- enumeration and selection of any visible macOS window
+- active, focused, or explicitly selected window metadata
+- iPhone Mirroring as one supported target option, not a special-only path
+- screenshot artifact metadata and PNG output
+- shallow Accessibility tree snapshot with roles, labels/titles, values, frames, pid, and window metadata
+- local trace folder for one run
+- ordered runtime events for capture and persistence
+- privacy-oriented redaction boundaries for sensitive windows
+
+Out of scope:
+
+- continuous frame capture
+- OCR, object detection, SAM, or model inference
+- synthetic input or Accessibility actions
+- remote model calls
+- full desktop recording
+- hot-loop performance optimization
+
+## Implementation Plan
+
+### Runtime And Permission Integration
+
+- Add a capture-facing service in `DonkeyRuntime` that works with `RunCoordinator`.
+- Extend the current tool capability policy only as needed for read-only capture:
+ - screenshot/window capture
+ - Accessibility tree read
+ - trace persistence
+- Keep input/action capabilities denied by default.
+- Emit `tool` events for target resolution, screenshot capture, Accessibility snapshot, and artifact persistence.
+- Emit `lifecycle` events for manual capture start, completion, abort, timeout, and failure.
+
+### Target Window Resolution
+
+- Add a macOS target resolver that can enumerate and describe candidate windows:
+ - pid
+ - app name or bundle id when available
+ - window title
+ - bounds in screen coordinates
+ - focus/frontmost status
+- Support explicit targeting by window id, pid/title tuple, or selected candidate from a debug UI/command.
+- Use the focused window only as a default when no explicit target is provided.
+- Treat iPhone Mirroring as a normal candidate window with optional target-specific metadata.
+- Stop and record a safe failure if the target appears to be a system prompt, payment/login surface, or unknown sensitive window.
+
+### Screenshot Capture
+
+- Start with one manual screenshot per run.
+- Capture the explicitly selected target window bounds, not the whole desktop by default.
+- Store screenshots under:
+
+```text
+runs/<run-id>/screenshots/<artifact-id>.png
+```
+
+- Write sidecar metadata:
+ - artifact id
+ - run id
+ - trace id
+ - monotonic and wall-clock timestamps
+ - target/window metadata
+ - coordinate space
+ - image size
+ - capture method
+
+### Accessibility Tree Snapshot
+
+- Add an Accessibility adapter that can:
+ - check trust status
+ - get frontmost/focused app and window
+ - resolve a selected target window by pid/title/window metadata when possible
+ - read a shallow AX tree with bounded depth and child count
+ - serialize role, title/label, value summary, frame, enabled/focused state, and action names
+- Store AX snapshots under:
+
+```text
+runs/<run-id>/accessibility/<artifact-id>.json
+```
+
+- Keep the tree bounded. Do not dump arbitrarily large app trees.
+- Redact long text values by default and store summaries instead of full sensitive text.
+
+### Trace Artifact Store
+
+- Add a simple local run artifact layout:
+
+```text
+runs/<run-id>/
+ events.jsonl
+ summary.json
+ screenshots/
+ accessibility/
+```
+
+- Write event and artifact records in append order.
+- Keep the artifact store simple and local for this milestone. It can become async or buffered later.
+
+### Context Assembly
+
+- Feed compact artifact references into context assembly:
+ - screenshot artifact ids and target metadata
+ - Accessibility tree summary
+ - recent capture failures
+ - run goal and target id
+- Do not pass raw screenshots or full AX trees to an LLM yet.
+
+## Acceptance Criteria
+
+- A manual command or prompt action creates a run session and one trace folder.
+- The trace folder contains `events.jsonl`, `summary.json`, one screenshot artifact, and one Accessibility snapshot when permission is available.
+- The capture flow records ordered `tool` and `lifecycle` events through `RunCoordinator`.
+- Screenshot capture is target/window scoped by default.
+- Accessibility tree capture is shallow, bounded, and serializable.
+- Missing Accessibility permission produces a clear event and a partial run summary instead of crashing.
+- Input and Accessibility actions remain disabled.
+- Sensitive/system/payment/login windows are refused or marked as safety stops.
+- Unit tests cover metadata serialization, bounded AX tree serialization, policy denial for input, and run artifact path generation.
+- Manual verification works against at least two different windows, such as iPhone Mirroring and a normal Mac app window.
+
+## Handoff Notes For The Next LLM
+
+- Before implementing, re-read `docs/README.md`, `docs/guides/minimal-run-coordinator.md`, `plans/18-macos-accessibility.md`, and `plans/20-off-the-shelf-run-loop.md`.
+- Keep this plan active while manual capture is incomplete.
+- When this milestone is complete, create or update a supported guide in `docs/guides/` for data capture and Accessibility snapshots.
+- After the guide exists and tests/manual verification pass, move this plan to `plans/done/`.
+- Clean up overlapping completed details in active plans:
+ - keep `plans/20-off-the-shelf-run-loop.md` focused on future off-the-shelf perception and runtime direction
+ - avoid duplicating the already-supported minimal coordinator behavior from `docs/guides/minimal-run-coordinator.md`
+ - keep `plans/18-macos-accessibility.md` focused on future AX actions/window guards once read-only AX capture is documented
+- Prefer shrinking active `plans/` when a capability becomes supported. Completed implementation facts should live in `docs/guides/`, not in long active plan sections.
+
+## What Should Be Done Next
+
+Start with the smallest read-only vertical slice:
+
+1. Add the local `runs/<run-id>/` artifact writer.
+2. Add window enumeration and target selection metadata.
+3. Add one target-scoped screenshot artifact.
+4. Add shallow Accessibility tree capture behind permission checks.
+5. Wire those steps through `RunCoordinator` events.
+6. Add tests for artifact metadata and bounded AX serialization.
+7. Manually verify against iPhone Mirroring and at least one other visible Mac app window.