Open source CapCut alternative.
TypeScript
Document SQLite agent memory architecture
David Le7f5e162467ca
diff --git a/docs/architecture.md b/docs/architecture.mdindex 0dcf96cd..03952f28 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -34,12 +34,12 @@ source of truth for behavior and boundaries remains| +----------+-----------+ +----------------------+ +-------+-------+ || | ^ || v | |-| +----------------------+ +----------------------+ | |-| | Agent Harness |<---->| Per-Task Coordinator |--------------+ |-| | context + routing | | lifecycle + policy | |-| +----------+-----------+ +----------+-----------+ |-| | | |-| v v |+| +----------------------+ +----------------------+ +---------------+ |+| | Agent Harness |<---->| Agent Memory Store |<---->| Per-Task Coord | |+| | context + routing | | SQLite FTS/vector | | lifecycle | |+| +----------+-----------+ +----------+-----------+ +-------+-------+ |+| | | | |+| v v v || +----------------------+ +----------------------+ +---------------+ || | Local App Runner |----->| Capture/Observation |----->| Action Engine | || | dry-run or guarded | | AX/window/screenshot | | keyboard/AX | |@@ -48,9 +48,9 @@ source of truth for behavior and boundaries remains+--------------------------------------------------------------------------------+```-The app shell owns entrypoints, durable task threads, setup, and per-task runtime-coordination. Capture, observation, model sidecars, task adaptation, and input-execution stay behind narrow runtime boundaries.+The app shell owns entrypoints, durable task threads, setup, shared agent+memory, and per-task runtime coordination. Capture, observation, model sidecars,+task adaptation, and input execution stay behind narrow runtime boundaries.## Pointer Prompt Task Threads@@ -104,14 +104,20 @@ execution stay behind narrow runtime boundaries.| | | || v v || +----------------------+ +----------------------+ +---------------+ |-| | Catalog Resolution |----->| Local App Adapter |----->| Task Run | |-| | app/task available | | steps + verification | | per-task coord| |+| | Agent Memory |----->| Catalog Resolution |----->| Local App | |+| | task defs/local item | | app/task available | | Adapter | |+| +----------+-----------+ +----------------------+ +-------+-------+ |+| | | |+| v v |+| +----------------------+ +----------------------+ +---------------+ |+| | Launch / Focus |----->| Observation |----->| Task Run | |+| | target app/window | | AX + metadata + UI | | per-task coord| || +----------------------+ +----------+-----------+ +-------+-------+ || | | || v v || +----------------------+ +----------------------+ +---------------+ |-| | Launch / Focus |----->| Observation |----->| World State | |-| | target app/window | | AX + metadata + UI | | typed compact | |+| | Local Item Validate |----->| World State |----->| Reflex Trace | |+| | path/bundle exists | | typed compact | | source-linked | || +----------------------+ +----------+-----------+ +-------+-------+ || | | || v v |@@ -143,6 +149,46 @@ must keep working without a remote model call. Local model output is validatedinto typed contracts before execution, controller output is semantic, and theaction engine is the only boundary allowed to issue guarded OS input.+## Agent Memory System++```text++--------------------------------------------------------------------------------++| Agent Memory Store |++--------------------------------------------------------------------------------++| |+| +----------------------+ +----------------------+ +---------------+ |+| | Runtime Writes |----->| Approval / Validate |----->| SQLite Store | |+| | lookup/task/provider | | source/privacy/ttl | | records | |+| +----------+-----------+ +----------------------+ +-------+-------+ |+| | | |+| v v |+| +----------------------+ +----------------------+ +---------------+ |+| | Negative Lookups | | FTS5 Index |<-----| Vector Blobs | |+| | expiry required | | lexical candidates | | Float32 local | |+| +----------------------+ +----------+-----------+ +-------+-------+ |+| | | |+| v v |+| +----------------------+ +----------------------+ +---------------+ |+| | Scoped Query |----->| Rank + Budget |----->| Harness Hints | |+| | target/kind/text | | FTS/vector/recency | | bounded text | |+| +----------+-----------+ +----------------------+ +-------+-------+ |+| | | |+| v v |+| +----------------------+ +----------------------+ +---------------+ |+| | Local Item Check | | Task Definitions | | JSONL Export | |+| | path/bundle exists | | generated/reviewed | | debug only | |+| +----------------------+ +----------------------+ +---------------+ |+| |++--------------------------------------------------------------------------------++```++Agent memory is the durable store for local item records, negative lookups,+runtime task definitions, target facts, user instructions, safety stops, and+workflow memory. SQLite is the source of truth; JSONL is only an explicit export+format for support and debugging. Retrieval always applies scope/kind filters,+prompt budgets, and availability validation before a record influences planning+or execution.+## Local Stack And Model Sidecars```text@@ -203,8 +249,8 @@ command parser LLM currently uses Ollama as a documented local prerequisite.| | | || | v || | +----------------------+ +---------------+ |-| | | Run Memory |----->| Redaction | |-| | | bounded/source-linked| | remote-bound | |+| | | Agent Memory |----->| Redaction | |+| | | SQLite FTS/vector | | remote-bound | || | +----------+-----------+ +-------+-------+ || | | | || | v v |@@ -230,5 +276,5 @@ command parser LLM currently uses Ollama as a documented local prerequisite.Slow models can help with ambiguous commands, recovery, planner hints, memoryproposals, and observability. Their outputs remain advisory: planner hints expire-and are validated, memory writes pass deterministic approval, and provider-failure leaves the fast local loop running on existing state.+and are validated, memory writes pass deterministic approval into agent memory,+and provider failure leaves the fast local loop running on existing state.diff --git a/docs/guides/agent-harness.md b/docs/guides/agent-harness.mdindex 88ff6a41..7dad931f 100644--- a/docs/guides/agent-harness.md+++ b/docs/guides/agent-harness.md@@ -142,9 +142,9 @@ text as an implicit action signal.User intent must not be inferred with ad hoc phrase, prefix, suffix, substring,or regex checks against natural-language command text. Donkey has local LLMs,-task definitions, runtime catalogs, and cache context for this job. Use them.+task definitions, runtime catalogs, and agent memory context for this job. Use them.The fast classifier may know typed capability buckets such as task ids,-capability ids, cache entry kinds, and model output statuses. It must not+capability ids, agent memory entry kinds, and model output statuses. It must notrecover those buckets by reading natural-language words out of the user'sprompt.@@ -173,7 +173,7 @@ Generic local-item lookup must follow the same rule. Do not add static commandverb, lookup prefix, or lookup suffix arrays to guess that text means "open thisapp/file/folder." A typed model or catalog artifact selects the local-itemlookup capability and extracts the requested item name; after that, the runtime-may normalize that item name and resolve it through the cache, Spotlight, and+may normalize that item name and resolve it through agent memory, Spotlight, andbounded filesystem lookup.Instructional visual coaching is the canonical example. The harness may show an@@ -199,8 +199,8 @@ the same fields.Remote-bound context must be redacted before provider calls. Local-only contextcan include richer app and observation facts, but should still stay bounded and-inspectable. Memory retrieval should use target/scope filters, relevance-thresholds, and prompt-character budgets before summaries are added.+inspectable. Memory retrieval should use target/scope/kind filters, FTS/vector+relevance thresholds, and prompt-character budgets before summaries are added.Context compaction is typed and inspectable. Current turns, policy, activetarget state, runtime capabilities, and trace identifiers are preserved first.@@ -228,8 +228,8 @@ model classifier or explicit runtime metadata produces a `TaskIntent`. Executionmay only continue after catalog validation confirms the target app/task,required entities, app availability, and safety policy. Weather lookup, mediaplayback, and document form-fill are benchmark fixtures for tests and replay-evaluation, not runtime defaults. Runtime defaults come from the local-resolution cache, which is seeded with generic capabilities and enriched by+evaluation, not runtime defaults. Runtime defaults come from the SQLite-backed+agent memory store, which is seeded with generic capabilities and enriched bymodel-generated or user-reviewed task definition files.Review is required when the harness can propose work but should not perform it@@ -270,9 +270,9 @@ workflow scripts to Swift as static strings. The harness may keep genericrendering/execution utilities such as string escaping, template interpolation,schema validation, AppleScript syntax/language validation, and guarded backenddispatch. The actual app-control script for a task must come from a typed-model/script-generation step, cached resolution metadata, or a user-reviewed-task definition, and it must be logged with the model/schema/action metadata-that produced it.+model/script-generation step, agent memory metadata, or a user-reviewed task+definition, and it must be logged with the model/schema/action metadata that+produced it.If an app task needs AppleScript, the supported shape is: classify the task,resolve the target app and entities, ask the model or task-definition layer for@@ -291,8 +291,8 @@ metadata and runtime item metadata, not one-off branches for individual apps.The fast local path must keep working without remote model calls. Local sidecarscan classify actionable turns, transcribe voice, segment screenshots, orsummarize UI observations. Provider-backed planners and memory proposals remain-slow-path helpers and must fail without stopping local control on existing-validated state.+slow-path helpers that write through deterministic approval into agent memory+and must fail without stopping local control on existing validated state.Local model work that shares the same runtime capacity should enter a priorityworker. Interactive task-intent parsing runs at user-interactive priority anddiff --git a/docs/guides/pointer-prompt-overlay.md b/docs/guides/pointer-prompt-overlay.mdindex ad3284bf..1272417c 100644--- a/docs/guides/pointer-prompt-overlay.md+++ b/docs/guides/pointer-prompt-overlay.md@@ -9,10 +9,10 @@ quick local-app actions:- Double-tap Command and hold the second press to open the prompt in voice mode.- Show a top-center notch status surface for task progress, recent tasks, follow-up input, file drops, updates, and per-task pause/resume.- Keep prompt submissions, voice transcripts, and follow-ups on the same agent-harness path: task-thread routing, context assembly, conversational response, clarification, review, catalog-backed action parsing, task validation, and guarded local-app execution when a turn is actionable.-- Resolve model-classified local-item requests against local apps, files, and folders by querying the current Mac with Spotlight/`mdfind`, bounded filesystem fallback, and a grep-friendly local resolution cache. 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.+- 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 local item cache in Application Support. The cache records resolved and missing lookups, prewarms apps plus common user file folders, stores runtime task definitions, keeps metadata such as kind/path/bundle ID/source/task/action, 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.- 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.@@ -25,7 +25,7 @@ quick local-app actions:- `PointerPromptNotchLayout` is the shared source for notch surface frames, content frames, corner radii, and notch-safe offsets. `canRenderTextInTopRow` describes whether text can draw in the top row, not whether that row exists.- The prompt is a compact black composer: single-line text is pill-shaped, multiline text becomes a bounded rounded rectangle, Return submits, Shift-Return inserts a newline, Escape and outside clicks dismiss, and non-input capsule areas can drag the modal.- Voice capture and transcription remain separate. The controller records bounded local audio and publishes levels; transcription uses the Parakeet-only adapter before submitting transcript text through the agent-harness turn path.-- Local item cache prewarming must run off the main actor. The cache file is JSONL so it remains inspectable and searchable with tools such as `grep`, but cache hits must still point to an existing path or bundle before they are used as an execution target. Runtime task definitions are loaded from this cache; Weather, Music, and Preview definitions are benchmark fixtures unless a generated/user-reviewed definition for them is present in the cache.+- Local item prewarming must run off the main actor. Agent memory is stored in SQLite under Application Support and uses FTS5 plus deterministic local embeddings for retrieval; JSONL is only an explicit export/debug format. Cached local-item hits must still point to an existing path or bundle before they are used as an execution target. Runtime task definitions are loaded from agent memory; Weather, Music, and Preview definitions are benchmark fixtures unless a generated/user-reviewed definition for them is present in memory.- For scriptable apps, prefer app-native AppleScript task commands before falling back to Accessibility or keyboard input. Bounded screenshots and local UI understanding may supplement observation/verification according to task metadata, but screenshots remain context evidence and do not directly drive input.- Visual coaching overlays are non-interactive, non-activating panels. They may point and explain, but they do not synthesize mouse movement, keyboard input, or Accessibility actions.- Task actions in the notch, including follow-up submission and pause/resume, must cross the model/controller command boundary with the selected task ID.