Skip to content

Open source CapCut alternative.

TypeScript

Document Donkey decision system

David Le03d9ca74e995
diff --git a/docs/guides/agent-harness.md b/docs/guides/agent-harness.md
index 7dad931f..bb23f95d 100644
--- a/docs/guides/agent-harness.md
+++ b/docs/guides/agent-harness.md
@@ -226,7 +226,10 @@ Action execution is for validated, supported tasks. The fast turn classifier can
answer narrow non-semantic turns such as numeric arithmetic; otherwise the local
model classifier or explicit runtime metadata produces a `TaskIntent`. Execution
may only continue after catalog validation confirms the target app/task,
-required entities, app availability, and safety policy. Weather lookup, media
+required entities, app availability, and safety policy. The default runtime
+capabilities are generic local-item open plus generic model-planned local-app
+interaction; the latter materializes a transient task definition from an
+allowlisted typed `actionPlan` before execution. Weather lookup, media
playback, and document form-fill are benchmark fixtures for tests and replay
evaluation, not runtime defaults. Runtime defaults come from the SQLite-backed
agent memory store, which is seeded with generic capabilities and enriched by
diff --git a/docs/guides/decision-system.md b/docs/guides/decision-system.md
new file mode 100644
index 00000000..54da6c43
--- /dev/null
+++ b/docs/guides/decision-system.md
@@ -0,0 +1,84 @@
+# Decision System
+
+## What It Decides
+
+Donkey treats every prompt, voice transcript, file drop, and follow-up as a task-thread turn first. The decision system chooses what the turn should do next:
+
+- respond conversationally
+- ask for a specific missing detail
+- open a review flow
+- run a guarded local-app action
+- do nothing for empty or already-handled input
+
+Action is not the default. A local action only starts after a typed model or runtime artifact says the turn is actionable and the runtime validates the target, plan, permissions, and available control surface.
+
+## Decision Flow
+
+The pointer prompt records the user-visible turn, builds a bounded context packet, and routes it through the harness. Narrow non-semantic primitives, such as empty input and numeric arithmetic, can be handled directly. Semantic decisions go through typed model boundaries.
+
+For local app work, the model receives:
+
+- the current command
+- supported runtime task definitions
+- relevant agent-memory snippets, such as installed local apps, files, folders, and learned task definitions
+- safety and execution expectations encoded in task metadata
+
+The model returns strict JSON, not free-form instructions. The result is decoded into a `TaskIntent`. If the intent names an existing task definition, the catalog validates that definition. If it names the generic local-app interaction capability, the catalog resolves the requested app from local memory and app lookup, then materializes a transient task definition from the typed `actionPlan`.
+
+For dynamic local-item and local-app interaction capabilities, the app or item name may be directly stated, retrieved from memory snippets, or inferred as the likely default local app for the user's goal. That inference is not execution authority; the catalog still resolves and verifies the target before any action runs.
+
+The `TaskIntent` wire format always includes an `actionPlan` object. Non-planned task types must return an empty `actionPlan.tools` array; non-empty action plans are accepted only for task definitions that explicitly opt into model-planned local-app interaction.
+
+## Generic Local-App Interaction
+
+`local_app_interaction` is the default model-planned app capability. It exists for requests like "play some Justin Bieber" where the user is not asking to merely open an app, and no durable app-specific task definition has been learned yet.
+
+For this capability the model must provide:
+
+- `targetAppName`, such as `Music`
+- `entities.appName`
+- `entities.goal`
+- `entities.query` when text needs to be entered
+- `actionPlan.tools`, a typed sequence of allowed local tools
+- `actionPlan.inputEntity`, usually `query` when `ui.setText` is present
+- `actionPlan.controlID`, `actionPlan.focusKey`, and `actionPlan.verification` for the guarded UI strategy
+
+The supported plan tools are intentionally small:
+
+```text
+app.openOrFocus
+app.observe
+ui.focusSearch
+ui.setText
+ui.pressReturn
+app.verifyCommand
+app.verifyVisibleText
+```
+
+The model may choose tools, entities, target app, and confidence. It may not invent arbitrary automation APIs, shell commands, hidden AppleScript, or unbounded UI actions. Unsupported tool names fail model-output validation or block before execution and become clarification/review instead of input.
+
+## Runtime Validation
+
+The catalog resolves dynamic targets through the agent memory store, Spotlight/app lookup, and bounded filesystem lookup. A planned action only proceeds when:
+
+- model confidence is high enough
+- the target app or item is available
+- required entities are present
+- every planned tool is in the allowlist
+- the plan can be represented as guarded workflow steps
+
+The live runner then owns launch/focus, observation, dry-run projection, guarded execution, and verification. Accessibility and keyboard input run through action-engine guardrails. AppleScript may be used only when supplied by typed task metadata or validated generated artifacts; free-form planner text is never direct input.
+
+## Learning Boundary
+
+Successful or reviewed plans can be stored as runtime task definitions in agent memory. That lets Donkey turn a one-off generic plan into a reusable supported capability without adding app-specific Swift fixtures or keyword lists.
+
+Weather, Music, and document form-fill fixtures remain useful for tests and replay. The supported runtime path is generic: local app/item lookup, model-selected intent or plan, catalog validation, guarded execution, verification, and optional memory-backed learning.
+
+## Source Entry Points
+
+- Prompt command handling starts in `apps/Donkey/Sources/Donkey/PointerPromptCommandHandler.swift`.
+- Harness routing and context packet assembly live in `apps/Donkey/Sources/DonkeyRuntime/AppHarnessTurnRouter.swift`.
+- Task-intent model adapters live in `apps/Donkey/Sources/DonkeyAI/OllamaTaskIntentAdapter.swift`.
+- Catalog validation and generic local-app interaction materialization live in `apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskCatalog.swift`.
+- Guarded execution lives in `apps/Donkey/Sources/DonkeyRuntime/LocalAppTaskLiveRunner.swift` and the action-engine backends.
diff --git a/docs/guides/pointer-prompt-overlay.md b/docs/guides/pointer-prompt-overlay.md
index 1272417c..9cbc45fc 100644
--- a/docs/guides/pointer-prompt-overlay.md
+++ b/docs/guides/pointer-prompt-overlay.md
@@ -12,7 +12,7 @@ quick local-app actions:
- Resolve model-classified local-item requests against local apps, files, and folders by querying the current Mac with the SQLite-backed agent memory store, Spotlight/`mdfind`, and bounded filesystem fallback. If the requested local item cannot be found, keep the task safe and report that it was not found instead of falling back to a vague clarification.
- Handle scriptable app tasks as guarded AppleScript automation when possible. Commands may use task metadata, generated source, or compact templates; completion is verified through generic task verification policy instead of requiring visible result text for every app.
- Handle instructional demonstration turns as visual coaching instead of failed app actions when the local LLM classifies the turn as a guide request and returns structured cursor steps. Donkey presents a transparent overlay with an animated agent cursor, moves it along a curved path, and types short guidance in a label next to the cursor while keeping the real mouse and app input untouched.
-- Maintain a background agent memory store in Application Support. The store records resolved and missing local-item lookups, prewarms apps plus common user file folders, stores runtime task definitions, keeps metadata such as kind/path/bundle ID/source/task/action, indexes records with SQLite FTS5 plus local vectors, and passes a bounded set of matching hints into the agent harness memory section for classifier and model consideration.
+- Maintain a background agent memory store in Application Support. The store records resolved and missing local-item lookups, prewarms apps plus common user file folders, stores runtime task definitions, keeps metadata such as kind/path/bundle ID/source/task/action, indexes records with SQLite FTS5 plus local vectors, and passes a bounded set of matching hints into the agent harness memory section for classifier and model consideration. See `docs/guides/decision-system.md` for how those hints feed typed model decisions and guarded local-app plans.
- Persist task threads as searchable Core Data conversations with event history, task assets, and per-run runtime coordination for any action work attached to the thread.
- Keep the overlay non-invasive. It may request microphone permission for local waveform capture and voice commands, but it must not capture the screen, synthesize input directly, or require Accessibility permission.