Skip to content

Open source CapCut alternative.

TypeScript

refactor(app): delete document-form-fill subsystem

David Le153af4b12b43
diff --git a/apps/Donkey/Sources/Donkey/DocumentFormFillReviewWindowController.swift b/apps/Donkey/Sources/Donkey/DocumentFormFillReviewWindowController.swift
deleted file mode 100644
index 0e0390c7..00000000
--- a/apps/Donkey/Sources/Donkey/DocumentFormFillReviewWindowController.swift
+++ /dev/null
@@ -1,178 +0,0 @@
-import AppKit
-import DonkeyAI
-import DonkeyRuntime
-import SwiftUI
-
-@MainActor
-final class DocumentFormFillReviewWindowController {
- private var window: NSWindow?
- private var viewModel: DocumentFormFillReviewViewModel?
-
- func show(request: DocumentFormFillReviewRequest) {
- let viewModel = DocumentFormFillReviewViewModel(
- request: request,
- close: { [weak self] in self?.close() }
- )
- self.viewModel = viewModel
-
- let hostingView = NSHostingView(
- rootView: DocumentFormFillReviewView(viewModel: viewModel)
- )
- let window = NSWindow(
- contentRect: CGRect(x: 0, y: 0, width: 560, height: 420),
- styleMask: [.titled, .closable, .miniaturizable],
- backing: .buffered,
- defer: false
- )
- window.title = "Review Form Fill"
- window.contentView = hostingView
- window.isReleasedWhenClosed = false
- window.center()
- window.makeKeyAndOrderFront(nil)
- NSApp.activate(ignoringOtherApps: true)
- self.window = window
- }
-
- private func close() {
- window?.close()
- window = nil
- viewModel = nil
- }
-}
-
-@MainActor
-private final class DocumentFormFillReviewViewModel: ObservableObject {
- @Published var selectedFieldIDs: Set<String>
- @Published private(set) var statusText: String
- @Published private(set) var isExecuting = false
-
- let request: DocumentFormFillReviewRequest
- private let close: @MainActor () -> Void
- private let runner: DocumentFormFillApprovalLiveRunner
-
- init(
- request: DocumentFormFillReviewRequest,
- close: @escaping @MainActor () -> Void,
- runner: DocumentFormFillApprovalLiveRunner = DocumentFormFillApprovalLiveRunner(
- appController: MacLocalAppTaskController(
- uiUnderstandingRunner: DonkeyUIUnderstandingRunnerFactory.defaultRunner()
- ),
- coordinator: RunCoordinator()
- )
- ) {
- self.request = request
- self.close = close
- self.runner = runner
- selectedFieldIDs = Set(request.plan.proposals.map(\.fieldID))
- statusText = "\(request.plan.proposals.count) proposed fields"
- }
-
- func approveSelected() {
- guard !isExecuting else { return }
-
- let fieldIDs = Array(selectedFieldIDs)
- isExecuting = true
- statusText = "Applying approved fields..."
- close()
-
- Task { [request, runner] in
- _ = await runner.run(
- plan: request.plan,
- definition: request.definition,
- traceID: request.traceID,
- approvedFieldIDs: fieldIDs
- )
- }
- }
-
- func cancel() {
- close()
- }
-}
-
-private struct DocumentFormFillReviewView: View {
- @ObservedObject var viewModel: DocumentFormFillReviewViewModel
-
- var body: some View {
- VStack(alignment: .leading, spacing: 16) {
- header
- proposalList
- footer
- }
- .padding(20)
- .frame(minWidth: 560, minHeight: 420)
- }
-
- private var header: some View {
- VStack(alignment: .leading, spacing: 4) {
- Text("Review field values")
- .font(.title3.weight(.semibold))
- Text(viewModel.statusText)
- .font(.subheadline)
- .foregroundStyle(.secondary)
- }
- }
-
- private var proposalList: some View {
- ScrollView {
- LazyVStack(spacing: 8) {
- ForEach(viewModel.request.plan.proposals, id: \.fieldID) { proposal in
- Toggle(isOn: selectionBinding(for: proposal.fieldID)) {
- VStack(alignment: .leading, spacing: 3) {
- Text(proposal.fieldLabel)
- .font(.system(size: 13, weight: .semibold))
- Text(proposal.proposedValue)
- .font(.system(size: 13))
- .foregroundStyle(.primary)
- Text("From \(proposal.sourceKey)")
- .font(.caption)
- .foregroundStyle(.secondary)
- }
- .frame(maxWidth: .infinity, alignment: .leading)
- }
- .toggleStyle(.checkbox)
- .padding(10)
- .background(Color(nsColor: .controlBackgroundColor))
- .clipShape(RoundedRectangle(cornerRadius: 8))
- }
- }
- }
- }
-
- private var footer: some View {
- HStack {
- if !viewModel.request.plan.unmappedRequiredFieldIDs.isEmpty {
- Text("\(viewModel.request.plan.unmappedRequiredFieldIDs.count) required fields are unmapped")
- .font(.caption)
- .foregroundStyle(.secondary)
- }
-
- Spacer()
-
- Button("Cancel") {
- viewModel.cancel()
- }
-
- Button("Apply Approved") {
- viewModel.approveSelected()
- }
- .keyboardShortcut(.defaultAction)
- .disabled(viewModel.selectedFieldIDs.isEmpty || viewModel.isExecuting)
- }
- }
-
- private func selectionBinding(for fieldID: String) -> Binding<Bool> {
- Binding(
- get: {
- viewModel.selectedFieldIDs.contains(fieldID)
- },
- set: { isSelected in
- if isSelected {
- viewModel.selectedFieldIDs.insert(fieldID)
- } else {
- viewModel.selectedFieldIDs.remove(fieldID)
- }
- }
- )
- }
-}
diff --git a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift
index a17f9fa0..fd15200f 100644
--- a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift
+++ b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift
@@ -35,7 +35,6 @@ struct UserQueryCommandHandlingResult: Equatable, Sendable {
var taskLabel: String?
var traceID: String
var metadata: [String: String]
- var documentReviewRequest: DocumentFormFillReviewRequest?
var agentVisualizationPlan: AgentVisualizationPlan?
var cursorOverlayRequest: PointerCoachCursorGuideRequest?
@@ -47,7 +46,6 @@ struct UserQueryCommandHandlingResult: Equatable, Sendable {
traceID: String,
metadata: [String: String],
taskLabel: String? = nil,
- documentReviewRequest: DocumentFormFillReviewRequest? = nil,
agentVisualizationPlan: AgentVisualizationPlan? = nil,
cursorOverlayRequest: PointerCoachCursorGuideRequest? = nil
) {
@@ -58,18 +56,11 @@ struct UserQueryCommandHandlingResult: Equatable, Sendable {
self.taskLabel = taskLabel
self.traceID = traceID
self.metadata = metadata
- self.documentReviewRequest = documentReviewRequest
self.agentVisualizationPlan = agentVisualizationPlan
self.cursorOverlayRequest = cursorOverlayRequest
}
}
-struct DocumentFormFillReviewRequest: Equatable, Sendable {
- var plan: DocumentFormFillPlan
- var definition: LocalAppTaskDefinition
- var traceID: String
-}
-
struct UserQueryCommandContext: Sendable {
var task: UserQueryNotchTask
var recentEvents: [UserQueryTaskEvent]
diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift
index 65759435..7b84579e 100644
--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift
+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift
@@ -31,7 +31,6 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {
private let voiceTranscriber: LocalVoiceTranscriptionAdapter
private let liveController: GeminiLiveVoiceController
private var updateChecker: any DonkeyUpdateChecking
- private let documentReviewController: DocumentFormFillReviewWindowController
private let appCatalogRefreshLoop: LocalAppDynamicCatalogRefreshLoop
private var activeTaskIDs: Set<String> = []
private var lastActiveTaskID: String?
@@ -48,7 +47,6 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {
runtime: ProcessBackedParakeetTranscriptionRuntime()
),
updateChecker: any DonkeyUpdateChecking = SparkleUpdateController(),
- documentReviewController: DocumentFormFillReviewWindowController = DocumentFormFillReviewWindowController(),
liveController: GeminiLiveVoiceController = GeminiLiveVoiceController(),
theme: UserQueryTheme = UserQueryOverlayModel.bundledTheme()
) {
@@ -58,7 +56,6 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {
self.voiceTranscriber = voiceTranscriber
self.liveController = liveController
self.updateChecker = updateChecker
- self.documentReviewController = documentReviewController
self.appCatalogRefreshLoop = LocalAppDynamicCatalogRefreshLoop(
profileGenerator: HostedLocalAppCatalogProfileGenerator()
)
@@ -416,9 +413,6 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {
taskID: task.id,
result: result
)
- if let documentReviewRequest = result.documentReviewRequest {
- self.documentReviewController.show(request: documentReviewRequest)
- }
let cursorOverlayRequest = result.cursorOverlayRequest
if let cursorOverlayRequest {
self.agentVisualizationPresenter?(cursorOverlayRequest, spawnID)
diff --git a/apps/Donkey/Sources/DonkeyRuntime/DocumentFormFillApprovalLiveRunner.swift b/apps/Donkey/Sources/DonkeyRuntime/DocumentFormFillApprovalLiveRunner.swift
deleted file mode 100644
index 67110e68..00000000
--- a/apps/Donkey/Sources/DonkeyRuntime/DocumentFormFillApprovalLiveRunner.swift
+++ /dev/null
@@ -1,164 +0,0 @@
-@preconcurrency import AppKit
-import DonkeyContracts
-import Foundation
-
-public enum DocumentFormFillApprovalRunStatus: String, Equatable, Sendable {
- case completed
- case partiallyCompleted
- case noApprovedFields
- case failedSafe
-}
-
-public struct DocumentFormFillApprovalRunResult: Equatable, Sendable {
- public var status: DocumentFormFillApprovalRunStatus
- public var approval: DocumentFormFillApproval
- public var actionTraces: [ActionEngineCommandTrace]
- public var metadata: [String: String]
-
- public init(
- status: DocumentFormFillApprovalRunStatus,
- approval: DocumentFormFillApproval,
- actionTraces: [ActionEngineCommandTrace],
- metadata: [String: String] = [:]
- ) {
- self.status = status
- self.approval = approval
- self.actionTraces = actionTraces
- self.metadata = metadata
- }
-}
-
-public struct DocumentFormFillApprovalLiveRunner: Sendable {
- public typealias ActionEngineFactory = @Sendable (LocalAppTaskDefinition) -> ActionEngineGuardrail
-
- public var planner: DocumentFormFillPlanner
- public var appController: any LocalAppTaskAppControlling
- public var availabilityProvider: any LocalAppAvailabilityProviding
- public var permissionPolicy: ToolCallPolicy
- public var coordinator: RunCoordinator?
- public var actionEngineFactory: ActionEngineFactory
-
- public init(
- planner: DocumentFormFillPlanner = DocumentFormFillPlanner(),
- appController: any LocalAppTaskAppControlling = MacLocalAppTaskController(),
- availabilityProvider: any LocalAppAvailabilityProviding = MacLocalAppAvailabilityProvider(),
- permissionPolicy: ToolCallPolicy = ToolCallPolicy(
- allowedCapabilities: ToolCallPolicy.defaultAllowedCapabilities.union([.input]),
- deniedCapabilities: []
- ),
- coordinator: RunCoordinator? = nil,
- actionEngineFactory: @escaping ActionEngineFactory = LocalAppTaskActionEngines.accessibility(for:)
- ) {
- self.planner = planner
- self.appController = appController
- self.availabilityProvider = availabilityProvider
- self.permissionPolicy = permissionPolicy
- self.coordinator = coordinator
- self.actionEngineFactory = actionEngineFactory
- }
-
- public func run(
- plan: DocumentFormFillPlan,
- definition: LocalAppTaskDefinition,
- traceID: String,
- approvedFieldIDs: [String]
- ) async -> DocumentFormFillApprovalRunResult {
- let approval = planner.approval(
- for: plan,
- traceID: traceID,
- approvedFieldIDs: Set(approvedFieldIDs)
- )
- guard !approval.approvedProposals.isEmpty else {
- return DocumentFormFillApprovalRunResult(
- status: .noApprovedFields,
- approval: approval,
- actionTraces: [],
- metadata: ["reason": "noApprovedFields"]
- )
- }
-
- let targetID = LocalAppTaskAdapter(definition: definition).targetID
- await coordinator?.setTraceID(traceID)
- _ = await coordinator?.start(
- RunSession(
- userGoal: "approve document form fill",
- targetID: targetID,
- runtimeProfile: "document-form-fill-approval",
- permissionPolicy: permissionPolicy
- )
- )
-
- let availability = availabilityProvider.availability(for: definition.targetApp)
- await coordinator?.recordToolEvent(
- capability: .input,
- decision: permissionPolicy.decision(for: .input),
- toolName: "mac-launch-focus",
- summary: "Refocusing document app before approved field entry",
- traceID: traceID,
- metadata: [
- "targetApp": definition.targetApp.appName,
- "bundleIdentifier": definition.targetApp.bundleIdentifier ?? ""
- ]
- )
- _ = await appController.launchOrFocus(
- definition: definition,
- availability: availability
- )
-
- let commands = LocalAppAccessibilityActionPlanner().fillCommands(
- approval: approval,
- definition: definition,
- issuedAt: Self.now()
- )
- let engine = actionEngineFactory(definition)
- var traces: [ActionEngineCommandTrace] = []
- for command in commands {
- await coordinator?.recordToolEvent(
- capability: .accessibility,
- decision: permissionPolicy.decision(for: .accessibility),
- toolName: "mac-accessibility-action-engine",
- summary: "Executing approved document field entry",
- traceID: traceID,
- metadata: [
- "commandID": command.id,
- "fieldID": command.metadata["accessibility.nodeID"] ?? ""
- ]
- )
- let trace = await engine.handle(command, permissionPolicy: permissionPolicy)
- traces.append(trace)
- guard trace.executed || trace.decision == .skippedNoLiveInput else {
- break
- }
- }
-
- let executedCount = traces.filter(\.executed).count
- let status: DocumentFormFillApprovalRunStatus
- if executedCount == approval.approvedProposals.count {
- status = .completed
- await coordinator?.complete(reason: "Approved document form fields filled")
- } else if executedCount > 0 {
- status = .partiallyCompleted
- await coordinator?.pause(reason: "Document form fill partially completed")
- } else {
- status = .failedSafe
- await coordinator?.fail(reason: "Document form fill approval was not executed")
- }
-
- return DocumentFormFillApprovalRunResult(
- status: status,
- approval: approval,
- actionTraces: traces,
- metadata: [
- "approvedFieldCount": String(approval.approvedProposals.count),
- "executedCommandCount": String(executedCount)
- ]
- )
- }
-
- private static func now() -> RunTraceTimestamp {
- RunTraceTimestamp(
- wallClock: Date(),
- monotonicUptimeNanoseconds: UInt64(ProcessInfo.processInfo.systemUptime * 1_000_000_000)
- )
- }
-}
diff --git a/apps/Donkey/Sources/DonkeyRuntime/DocumentFormFillPlanner.swift b/apps/Donkey/Sources/DonkeyRuntime/DocumentFormFillPlanner.swift
deleted file mode 100644
index 57480989..00000000
--- a/apps/Donkey/Sources/DonkeyRuntime/DocumentFormFillPlanner.swift
+++ /dev/null
@@ -1,251 +0,0 @@
-import DonkeyContracts
-import Foundation
-
-public enum DocumentFormFillPlanStatus: String, Codable, Equatable, Sendable {
- case readyForReview
- case needsDocumentContext
- case needsStructuredData
- case needsFieldDiscovery
-}
-
-public struct DocumentFormFillProposal: Codable, Equatable, Sendable {
- public var fieldID: String
- public var fieldLabel: String
- public var proposedValue: String
- public var sourceKey: String
- public var confidence: Double
- public var metadata: [String: String]
-
- public init(
- fieldID: String,
- fieldLabel: String,
- proposedValue: String,
- sourceKey: String,
- confidence: Double,
- metadata: [String: String] = [:]
- ) {
- self.fieldID = fieldID
- self.fieldLabel = fieldLabel
- self.proposedValue = proposedValue
- self.sourceKey = sourceKey
- self.confidence = min(max(confidence, 0), 1)
- self.metadata = metadata
- }
-}
-
-public struct DocumentFormFillPlan: Codable, Equatable, Sendable {
- public var status: DocumentFormFillPlanStatus
- public var proposals: [DocumentFormFillProposal]
- public var unmappedRequiredFieldIDs: [String]
- public var unusedDataKeys: [String]
- public var metadata: [String: String]
-
- public init(
- status: DocumentFormFillPlanStatus,
- proposals: [DocumentFormFillProposal] = [],
- unmappedRequiredFieldIDs: [String] = [],
- unusedDataKeys: [String] = [],
- metadata: [String: String] = [:]
- ) {
- self.status = status
- self.proposals = proposals
- self.unmappedRequiredFieldIDs = unmappedRequiredFieldIDs
- self.unusedDataKeys = unusedDataKeys
- self.metadata = metadata
- }
-}
-
-public enum DocumentFormFillApprovalStatus: String, Codable, Equatable, Sendable {
- case approved
- case rejected
- case partiallyApproved
-}
-
-public struct DocumentFormFillApproval: Codable, Equatable, Sendable {
- public var id: String
- public var traceID: String
- public var status: DocumentFormFillApprovalStatus
- public var approvedProposals: [DocumentFormFillProposal]
- public var rejectedFieldIDs: [String]
- public var metadata: [String: String]
-
- public init(
- id: String,
- traceID: String,
- status: DocumentFormFillApprovalStatus,
- approvedProposals: [DocumentFormFillProposal],
- rejectedFieldIDs: [String] = [],
- metadata: [String: String] = [:]
- ) {
- self.id = id
- self.traceID = traceID
- self.status = status
- self.approvedProposals = approvedProposals
- self.rejectedFieldIDs = rejectedFieldIDs
- self.metadata = metadata
- }
-}
-
-public struct DocumentFormFillPlanner: Sendable {
- public init() {}
-
- public func plan(
- intent: TaskIntent,
- definition: LocalAppTaskDefinition,
- context: LocalAppTaskContext
- ) -> DocumentFormFillPlan {
- guard definition.taskType == "document_form_fill" else {
- return DocumentFormFillPlan(
- status: .needsDocumentContext,
- metadata: ["reason": "unsupportedTaskType"]
- )
- }
-
- guard hasDocumentContext(intent: intent, context: context) else {
- return DocumentFormFillPlan(
- status: .needsDocumentContext,
- metadata: ["reason": "missingDocumentContext"]
- )
- }
-
- let data = effectiveStructuredData(intent: intent, context: context)
- guard !data.isEmpty else {
- return DocumentFormFillPlan(
- status: .needsStructuredData,
- metadata: ["reason": "missingStructuredData"]
- )
- }
-
- let fields = context.observedFormFields
- guard !fields.isEmpty else {
- return DocumentFormFillPlan(
- status: .needsFieldDiscovery,
- unusedDataKeys: data.keys.sorted(),
- metadata: [
- "reason": "missingObservedFields",
- "dataKeyCount": String(data.count)
- ]
- )
- }
-
- var usedKeys: Set<String> = []
- let proposals = fields.compactMap { field -> DocumentFormFillProposal? in
- guard let match = bestDataMatch(for: field, data: data, usedKeys: usedKeys) else {
- return nil
- }
- usedKeys.insert(match.key)
- return DocumentFormFillProposal(
- fieldID: field.id,
- fieldLabel: field.label,
- proposedValue: match.value,
- sourceKey: match.key,
- confidence: match.exact ? 0.94 : 0.72,
- metadata: ["match": match.exact ? "exact" : "fuzzy"]
- )
- }
-
- let mappedFieldIDs = Set(proposals.map(\.fieldID))
- let unmappedRequired = fields
- .filter { $0.isRequired && !mappedFieldIDs.contains($0.id) }
- .map(\.id)
- .sorted()
- let unusedKeys = data.keys
- .filter { !usedKeys.contains($0) }
- .sorted()
-
- return DocumentFormFillPlan(
- status: .readyForReview,
- proposals: proposals,
- unmappedRequiredFieldIDs: unmappedRequired,
- unusedDataKeys: unusedKeys,
- metadata: [
- "proposalCount": String(proposals.count),
- "fieldCount": String(fields.count),
- "dataKeyCount": String(data.count),
- "requiresReview": "true"
- ]
- )
- }
-
- public func approval(
- for plan: DocumentFormFillPlan,
- traceID: String,
- approvedFieldIDs: Set<String>
- ) -> DocumentFormFillApproval {
- let approved = plan.proposals.filter { approvedFieldIDs.contains($0.fieldID) }
- let rejected = plan.proposals
- .filter { !approvedFieldIDs.contains($0.fieldID) }
- .map(\.fieldID)
- .sorted()
- let status: DocumentFormFillApprovalStatus
- if approved.isEmpty {
- status = .rejected
- } else if rejected.isEmpty {
- status = .approved
- } else {
- status = .partiallyApproved
- }
-
- return DocumentFormFillApproval(
- id: "document-form-fill-approval-\(traceID)",
- traceID: traceID,
- status: status,
- approvedProposals: approved,
- rejectedFieldIDs: rejected,
- metadata: [
- "requiresUserApproval": "true",
- "approvedProposalCount": String(approved.count),
- "rejectedProposalCount": String(rejected.count)
- ]
- )
- }
-
- private func hasDocumentContext(
- intent: TaskIntent,
- context: LocalAppTaskContext
- ) -> Bool {
- intent.normalizedEntities["document"] != nil
- || context.focusedWindowTitle != nil
- || !context.attachedFileURLs.isEmpty
- }
-
- private func effectiveStructuredData(
- intent: TaskIntent,
- context: LocalAppTaskContext
- ) -> [String: String] {
- if !context.structuredData.isEmpty {
- return context.structuredData
- }
-
- return intent.normalizedEntities
- .filter { key, _ in
- key != "document" && key != "dataSource"
- }
- }
-
- private func bestDataMatch(
- for field: LocalDocumentFormField,
- data: [String: String],
- usedKeys: Set<String>
- ) -> (key: String, value: String, exact: Bool)? {
- let fieldName = normalized(field.label)
- let unused = data.filter { !usedKeys.contains($0.key) }
-
- if let exact = unused.first(where: { normalized($0.key) == fieldName }) {
- return (exact.key, exact.value, true)
- }
-
- if let fuzzy = unused.first(where: { item in
- let key = normalized(item.key)
- return fieldName.contains(key) || key.contains(fieldName)
- }) {
- return (fuzzy.key, fuzzy.value, false)
- }
-
- return nil
- }
-
- private func normalized(_ value: String) -> String {
- LocalAppTextNormalizer.normalizedPhrase(value)
- }
-}
diff --git a/apps/Donkey/Sources/DonkeyRuntime/LocalAppAccessibilityControls.swift b/apps/Donkey/Sources/DonkeyRuntime/LocalAppAccessibilityControls.swift
index 4867cf52..3b0df517 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/LocalAppAccessibilityControls.swift
+++ b/apps/Donkey/Sources/DonkeyRuntime/LocalAppAccessibilityControls.swift
@@ -352,35 +352,6 @@ public struct LocalAppAccessibilityActionPlanner: Sendable {
}
}
- public func fillCommands(
- approval: DocumentFormFillApproval,
- definition: LocalAppTaskDefinition,
- issuedAt: RunTraceTimestamp
- ) -> [ActionEngineCommand] {
- let adapter = LocalAppTaskAdapter(definition: definition)
- return approval.approvedProposals.enumerated().map { index, proposal in
- ActionEngineCommand(
- id: "\(approval.id)-fill-\(index)",
- traceID: approval.traceID,
- targetID: adapter.targetID,
- kind: .key,
- issuedAt: Self.timestamp(issuedAt, advancedByMilliseconds: Double(index) * 60),
- key: proposal.proposedValue,
- metadata: [
- "taskType": definition.taskType,
- "workflowStepRole": "enterText",
- "inputStrategy": "accessibility",
- "accessibility.action": "AXSetValue",
- "accessibility.nodeID": proposal.fieldID,
- "accessibility.value": proposal.proposedValue,
- "documentFormFill.approvalID": approval.id,
- "documentFormFill.sourceKey": proposal.sourceKey,
- "documentFormFill.fieldLabel": proposal.fieldLabel
- ]
- )
- }
- }
-
private func command(
id: String,
traceID: String,
diff --git a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskCatalog.swift b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskCatalog.swift
index a3551fff..13ed01a8 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskCatalog.swift
+++ b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskCatalog.swift
@@ -810,65 +810,4 @@ public enum BuiltInLocalAppTaskDefinitions {
)
]
}
-
- public static var documentFormFill: LocalAppTaskDefinition {
- LocalAppTaskDefinition(
- taskType: "document_form_fill",
- targetApp: LocalAppTarget(
- appName: "Preview",
- bundleIdentifier: "com.apple.Preview",
- titleContains: nil
- ),
- triggerTerms: [],
- entityRules: [
- LocalAppTaskEntityRule(
- name: "document",
- metadata: ["contextRole": "documentTarget"]
- ),
- LocalAppTaskEntityRule(
- name: "dataSource",
- metadata: ["contextRole": "structuredInputData"]
- )
- ],
- workflowSteps: commonWorkflowPrefix + [
- LocalAppTaskWorkflowStepDefinition(
- id: "observe-form-fields",
- role: .custom,
- summary: "Discover fillable fields from Accessibility or bounded local UI understanding",
- metadata: [
- "requiresStructuredDataMapping": "true",
- "preferredObservation": "accessibility,localModel"
- ]
- ),
- LocalAppTaskWorkflowStepDefinition(
- id: "map-data-to-fields",
- role: .custom,
- summary: "Map provided data to detected document fields",
- metadata: [
- "requiresUserData": "true",
- "outputMustBeReviewed": "true"
- ]
- ),
- LocalAppTaskWorkflowStepDefinition(
- id: "verify-filled-document",
- role: .verifyResult,
- summary: "Verify all required fields have a proposed value"
- )
- ],
- observationStrategies: [.accessibility, .screenshotForLocalModel],
- verificationEntityName: "document",
- metadata: [
- "catalogEntry": "built-in-document-form-fill",
- "displayTitle": "document form fill",
- "taskLabelTemplate": "Fill {document}",
- "domain": "document",
- "requiresDocumentContext": "true",
- "requiresStructuredData": "true",
- "guardedLiveDefault": "reviewOnly",
- "screenshotFallback": "missingVerificationOrControls",
- "visualFallback": "localModel",
- "ocrFallbackDefault": "false"
- ]
- )
- }
}
diff --git a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskExecutionSupport.swift b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskExecutionSupport.swift
index ad56877e..8fc7fee8 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskExecutionSupport.swift
+++ b/apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskExecutionSupport.swift
@@ -20,7 +20,6 @@ public struct LocalAppTaskLiveRunResult: Equatable, Sendable {
public var initialActionPlan: LocalAppEvidenceBackedActionPlan?
public var finalActionPlan: LocalAppEvidenceBackedActionPlan?
public var observation: LocalAppTaskObservation?
- public var documentFormFillPlan: DocumentFormFillPlan?
public var actionTraces: [ActionEngineCommandTrace]
public var workflowProgress: LocalAppTaskWorkflowProgress
public var metadata: [String: String]
@@ -33,7 +32,6 @@ public struct LocalAppTaskLiveRunResult: Equatable, Sendable {
initialActionPlan: LocalAppEvidenceBackedActionPlan? = nil,
finalActionPlan: LocalAppEvidenceBackedActionPlan? = nil,
observation: LocalAppTaskObservation? = nil,
- documentFormFillPlan: DocumentFormFillPlan? = nil,
actionTraces: [ActionEngineCommandTrace] = [],
workflowProgress: LocalAppTaskWorkflowProgress = LocalAppTaskWorkflowProgress(),
metadata: [String: String] = [:]
@@ -45,7 +43,6 @@ public struct LocalAppTaskLiveRunResult: Equatable, Sendable {
self.initialActionPlan = initialActionPlan
self.finalActionPlan = finalActionPlan
self.observation = observation
- self.documentFormFillPlan = documentFormFillPlan
self.actionTraces = actionTraces
self.workflowProgress = workflowProgress
self.metadata = metadata
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/LocalAppTaskTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/LocalAppTaskTests.swift
index 88d01f63..0535c293 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/LocalAppTaskTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/LocalAppTaskTests.swift
@@ -21,23 +21,6 @@ struct LocalAppTaskTests {
#expect(intent.metadata["catalogEntry"] == "built-in-weather-lookup")
}
- @Test
- func structuredDocumentFormFillIntentBuildsReviewOnlyTask() throws {
- let intent = documentFormFillIntent()
-
- #expect(intent.taskType == "document_form_fill")
- #expect(intent.targetApp.appName == "Preview")
- #expect(intent.normalizedEntities["document"] == "current PDF")
- #expect(intent.normalizedEntities["dataSource"] == "provided data")
- #expect(intent.metadata["requiresDocumentContext"] == "true")
-
- let plan = LocalAppTaskAdapter(definition: BuiltInLocalAppTaskDefinitions.documentFormFill)
- .evidenceBackedActionPlan(for: intent)
- #expect(plan.canExecuteGuardedActions == false)
- #expect(plan.metadata["guardedLiveDefault"] == "reviewOnly")
- #expect(plan.steps.map(\.role).contains(.custom))
- }
-
@Test
func modelIntentCanRequestConfirmationForMissingRequiredEntity() throws {
let intent = weatherIntent(rawCity: "", city: "", needsConfirmation: true)
@@ -263,75 +246,6 @@ struct LocalAppTaskTests {
])
}
- @Test
- func documentFormFillPlannerMapsStructuredDataToObservedFieldsForReview() throws {
- let intent = documentFormFillIntent()
- let context = LocalAppTaskContext(
- focusedAppName: "Preview",
- focusedBundleIdentifier: "com.apple.Preview",
- focusedWindowTitle: "W-9.pdf",
- structuredData: [
- "Name": "Ada Lovelace",
- "Address": "12 Algorithm Ave"
- ],
- observedFormFields: [
- LocalDocumentFormField(id: "field-name", label: "Name", isRequired: true),
- LocalDocumentFormField(id: "field-address", label: "Mailing Address", isRequired: true)
- ]
- )
-
- let plan = DocumentFormFillPlanner().plan(
- intent: intent,
- definition: BuiltInLocalAppTaskDefinitions.documentFormFill,
- context: context
- )
-
- #expect(plan.status == .readyForReview)
- #expect(plan.proposals.count == 2)
- #expect(plan.proposals.first(where: { $0.fieldID == "field-name" })?.proposedValue == "Ada Lovelace")
- #expect(plan.metadata["requiresReview"] == "true")
- }
-
- @Test
- func documentFormFillApprovalBuildsOnlyApprovedAccessibilityCommands() throws {
- let intent = documentFormFillIntent()
- let context = LocalAppTaskContext(
- focusedWindowTitle: "W-9.pdf",
- structuredData: [
- "Name": "Ada Lovelace",
- "Address": "12 Algorithm Ave"
- ],
- observedFormFields: [
- LocalDocumentFormField(id: "ax-1.1", label: "Name", isRequired: true),
- LocalDocumentFormField(id: "ax-1.2", label: "Address", isRequired: true)
- ]
- )
- let planner = DocumentFormFillPlanner()
- let plan = planner.plan(
- intent: intent,
- definition: BuiltInLocalAppTaskDefinitions.documentFormFill,
- context: context
- )
- let approval = planner.approval(
- for: plan,
- traceID: "trace-approval",
- approvedFieldIDs: ["ax-1.1"]
- )
- let commands = LocalAppAccessibilityActionPlanner().fillCommands(
- approval: approval,
- definition: BuiltInLocalAppTaskDefinitions.documentFormFill,
- issuedAt: timestamp(200)
- )
-
- #expect(approval.status == .partiallyApproved)
- #expect(approval.approvedProposals.map(\.fieldID) == ["ax-1.1"])
- #expect(approval.rejectedFieldIDs == ["ax-1.2"])
- #expect(commands.count == 1)
- #expect(commands.first?.metadata["accessibility.action"] == "AXSetValue")
- #expect(commands.first?.metadata["accessibility.nodeID"] == "ax-1.1")
- #expect(commands.first?.metadata["documentFormFill.approvalID"] == approval.id)
- }
-
@Test
func accessibilityControlDiscoveryIndexesControlsAndFormFields() throws {
let target = MacWindowTargetCandidate(
@@ -572,58 +486,6 @@ struct LocalAppTaskTests {
#expect(groundedMetadata["control.bounds.space"] == HotLoopCoordinateSpace.normalizedTarget.rawValue)
}
- @Test @MainActor
- func documentApprovalRunnerExecutesOnlyApprovedFields() async throws {
- let backend = RecordingLocalAppTaskInputBackend()
- let controller = FakeLocalAppTaskAppController(
- launchObservation: LocalAppTaskObservation(appIsRunning: true, appIsFocused: true),
- finalObservation: LocalAppTaskObservation(appIsRunning: true, appIsFocused: true)
- )
- let plan = DocumentFormFillPlan(
- status: .readyForReview,
- proposals: [
- DocumentFormFillProposal(
- fieldID: "ax-1.1",
- fieldLabel: "Name",
- proposedValue: "Ada Lovelace",
- sourceKey: "Name",
- confidence: 0.94
- ),
- DocumentFormFillProposal(
- fieldID: "ax-1.2",
- fieldLabel: "Address",
- proposedValue: "12 Algorithm Ave",
- sourceKey: "Address",
- confidence: 0.94
- )
- ]
- )
- let coordinator = RunCoordinator()
- let runner = DocumentFormFillApprovalLiveRunner(
- appController: controller,
- availabilityProvider: StaticLocalAppAvailabilityProvider(installedBundleIdentifiers: ["com.apple.Preview"]),
- coordinator: coordinator,
- actionEngineFactory: { _ in
- ActionEngineGuardrail(
- configuration: ActionEngineConfiguration(liveInputEnabled: true),
- inputBackend: backend
- )
- }
- )
-
- let result = await runner.run(
- plan: plan,
- definition: BuiltInLocalAppTaskDefinitions.documentFormFill,
- traceID: "trace-document-approval",
- approvedFieldIDs: ["ax-1.1"]
- )
-
- #expect(result.status == .completed)
- #expect(result.approval.approvedProposals.map(\.fieldID) == ["ax-1.1"])
- #expect(await backend.executedKeys() == ["Ada Lovelace"])
- #expect(controller.launchCount == 1)
- }
-
private func weatherIntent(
rawCity: String,
city: String,
@@ -646,26 +508,6 @@ struct LocalAppTaskTests {
)
}
- private func documentFormFillIntent(confidence: Double = 0.9) -> TaskIntent {
- let definition = BuiltInLocalAppTaskDefinitions.documentFormFill
- return TaskIntent(
- intentID: "document_form_fill-current-pdf",
- taskType: definition.taskType,
- targetApp: definition.targetApp,
- entities: [
- "document": "this PDF",
- "dataSource": "this data"
- ],
- normalizedEntities: [
- "document": "current PDF",
- "dataSource": "provided data"
- ],
- confidence: confidence,
- parserSource: .localModel,
- metadata: definition.metadata
- )
- }
-
private func adapter() -> LocalAppTaskAdapter {
LocalAppTaskAdapter(definition: BuiltInLocalAppTaskDefinitions.weatherLookup)
}
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/TestLocalAppTaskDefinitions.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/TestLocalAppTaskDefinitions.swift
index 1bd35a27..e50dce4b 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/TestLocalAppTaskDefinitions.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/TestLocalAppTaskDefinitions.swift
@@ -83,8 +83,7 @@ extension BuiltInLocalAppTaskDefinitions {
static var testFixtures: [LocalAppTaskDefinition] {
[
genericLocalAppInteraction,
- weatherLookup,
- documentFormFill
+ weatherLookup
]
}
}