How osaurus-ai/osaurus works
1. Top-level shape
- This is a macOS-native Swift system with one app target (App/osaurus), one command-line entrypoint (Packages/OsaurusCLI), and a large shared core library (Packages/OsaurusCore). Most runtime behavior lives in the core package and is reused by both the GUI and CLI.
2. User-facing entry points
- The macOS app is the primary interactive shell: SwiftUI views, app intents, management panels, and system-wide integrations.
- The CLI exposes operational commands like serve, ui, status, mcp, and tools ...; it is the operational gateway for headless/server use and for external harnesses.
3. Core runtime boundary
- OsaurusCore is the main architecture boundary. It contains models, services, managers, storage, networking, tools, identity, sandbox, memory, privacy filtering, and views.
- The codebase is organized so “services” hold business logic, “managers” hold UI-facing state, and “views” render feature surfaces on top of them.
4. Conversation and agent loop
- Chat is the central orchestration flow. A session collects user messages, attachments, tool results, memory, and model responses.
- The agent loop composes prompts, selects tools, streams model output, handles tool calls, and persists the resulting transcript/state. This loop is reused across the UI, server API, and evaluation harnesses.
5. Model/inference subsystem
- Model access is abstracted behind ModelService / Inference services and supports several backends: local MLX, Apple Foundation Models, and remote providers such as OpenAI-compatible, Anthropic, Gemini, xAI/OpenRouter/Ollama-like endpoints.
- The model layer is not just transport: it also handles model selection, runtime policy, token budgeting, batching, residency/lease management, and capability-specific routing.
6. Tooling and plugin system
- Tools are a first-class layer beneath the agent loop. Core tool types include built-ins, folder tools, sandbox tools, database tools, capability tools, and MCP/provider-backed tools.
- There is a plugin ABI plus a repository/install layer (OsaurusRepository) for native plugins and Claude-style plugin bundles. The tool registry decides exposure, permissions, and routing into these capabilities.
7. Sandbox execution boundary
- The sandbox is a hard trust boundary: agents can run code in an isolated Linux VM managed by Apple Containerization, with host/guest communication via vsock and shared workspace mounts.
- Host-side sandbox services provision the VM, register tools, stream logs, enforce security policies, and mediate file/artifact access. This is where “real code execution” is kept separate from the macOS host.
8. Identity and secure communication
- Identity is cryptographic and per-participant: master keys, agent keys, pairing keys, revocation, and secure session stores live in Identity.
- This supports local access keys, pairings, and secure channel connections. The secure-channel layer encrypts agent-to-agent or relay-mediated traffic end to end, while the relay itself stays blind to plaintext.
9. Networking and server surfaces
- Networking contains the local HTTP server, request parsing/validation, OpenAI/Anthropic/Ollama-compatible endpoints, MCP endpoints, relay tunneling, Bonjour discovery, and auth gates.
- The same server layer powers local API consumption, remote exposure, and the stdio MCP bridge used by external MCP clients.
10. Storage and persistence
- State is persisted through multiple SQLite-backed stores: chat history, agents, tools, plugins, schedules, memory, billing/credits, and server/runtime settings.
- There is also encrypted storage for secrets and sensitive per-agent data. Storage is a shared persistence layer underneath chat, identity, memory, plugins, and tooling.
11. Memory and privacy
- Memory is a distinct subsystem with embeddings, search, consolidation, relevance gating, and per-session context assembly.
- Privacy filtering sits on the outbound path to cloud models: content is redacted, reviewed, then streamed back with placeholders unscrubbed for display. The design is fail-closed, so leakage blocks send.
12. Knowledge and reuse layers
- Skills, methods, slash commands, watchers, schedules, themes, and document adapters are all separate feature layers that feed into the agent experience.
- These are discovered and selected through search/routing services rather than manual wiring, which means the agent can dynamically pick relevant capability bundles.
13. Document and attachment pipeline
- File attachments are not treated as plain blobs when structure matters. Dedicated adapters parse CSV, XLSX, PPTX, PDF, and rich documents into structured representations before they reach the model.
- This keeps the agent’s context higher-fidelity and lets tools operate on structured content instead of only raw text.
14. Observability, quality, and release plumbing
- Telemetry and crash reporting are optional, privacy-conscious, and separated from product data. The repo also contains extensive test suites, eval harnesses, live-proof scripts, benchmark scripts, and CI/release workflows.
- These don’t drive runtime behavior, but they strongly shape the architecture by enforcing stability across inference, sandboxing, privacy, plugin ABI, and provider compatibility.
Main entry points: ChatEngine.swift Chat Engine · Serve.swift CLI Commands · SandboxManager.swift Sandbox · ToolRegistry.swift Tool Registry
Components 24
macOS App
SwiftUI shell and app-intents entrypoint.
- App Shell · Primary macOS interactive entrypoint and lifecycle host.
App/osaurus/osaurusApp.swift - App Intents · Shortcuts and app-intent integrations for macOS control.
App/osaurus/AppIntents/OsaurusIntents.swift
CLI
Headless operational commands and server bootstrap.
- CLI Entry · Command-line front door for server and operations.
Packages/OsaurusCLI/Sources/OsaurusCLI/OsaurusCLI.swift - CLI Commands · serve, ui, status, mcp, tools, and related operations.
Packages/OsaurusCLI/Sources/OsaurusCLICore/Commands/Serve.swift
OsaurusCore
Shared runtime boundary used by app, CLI, and server.
- Chat Engine · Core agent loop that composes prompts, streams output, and handles tool calls.
Packages/OsaurusCore/Services/Chat/ChatEngine.swift - Chat Models · Session turns, attachments, transcripts, and chat configuration state.
Packages/OsaurusCore/Models/Chat/ChatSessionData.swift - Prompt Builder · System prompt composition, tool resolution, and token budgeting.
Packages/OsaurusCore/Services/Chat/SystemPromptComposer.swift - Model Service · Backend-agnostic model access and selection boundary.
Packages/OsaurusCore/Services/Inference/ModelService.swift - Model Runtime · Residency, leases, batching, load coordination, and runtime validation.
Packages/OsaurusCore/Services/ModelRuntime/ModelResidencyManager.swift - Tool Registry · Exposure, permissions, discovery, and routing for tools.
Packages/OsaurusCore/Tools/ToolRegistry.swift - Tool Layers · Built-ins, folder, database, sandbox, capability, and MCP-backed tools.
Packages/OsaurusCore/Tools/AgentLoopTools.swift - Sandbox · Host-side provisioning and isolated execution for real code execution.
Packages/OsaurusCore/Services/Sandbox/SandboxManager.swift - Networking · Local HTTP server, compatible APIs, relay tunneling, and MCP bridges.
Packages/OsaurusCore/Networking/OsaurusServer.swift - Identity · Keys, pairing, secure sessions, revocation, and access-key management.
Packages/OsaurusCore/Identity/OsaurusIdentity.swift - Storage · SQLite-backed stores, encrypted files, and mutation gates.
Packages/OsaurusCore/Storage/StorageDatabaseCatalog.swift - Memory · Embeddings, relevance gating, consolidation, and context assembly.
Packages/OsaurusCore/Services/Memory/MemoryService.swift - Privacy Filter · Outbound scrubbing, review, placeholders, and fail-closed leakage prevention.
Packages/OsaurusCore/PrivacyFilter/Core/PrivacyFilterPipeline.swift - Documents · Structured parsing and emission for PDF, CSV, XLSX, PPTX, and rich documents.
Packages/OsaurusCore/Services/Documents/DocumentFileInspector.swift - Managers · UI-facing state, windows, model selection, plugins, schedules, and orchestration helpers.
Packages/OsaurusCore/Managers/ManagementStateManager.swift - Views · SwiftUI and representable feature surfaces over the shared managers/services.
Packages/OsaurusCore/Views/Chat/ChatView.swift - Computer Use · macOS perception, control, policy, and loop for GUI automation.
Packages/OsaurusCore/ComputerUse/Loop/ComputerUseLoop.swift
Evals
Regression and capability harnesses for core flows.
- Eval Harness · Agent-loop, computer-use, and capability regression suites.
Packages/OsaurusEvals/Sources/OsaurusEvalsKit/EvalRunner.swift
Plugins
Native plugin packaging and installation boundary.
- Plugin Repo · Native plugin repository, install flow, and manifest verification.
Packages/OsaurusRepository/PluginInstallManager.swift - Plugin ABI · Shared host/plugin ABI and test kit used by plugin packages.
Packages/OsaurusCore/Tools/PluginABI/osaurus_plugin.h
Connections 29
- App Shell → Managers: uses · The app shell hosts the shared UI state and windows.
- App Shell → Chat Engine: drives · Interactive chat ultimately flows through the shared agent loop.
- App Intents → Chat Engine: invokes · App intents route into the same core chat orchestration.
- CLI Entry → CLI Commands: dispatches · The CLI entrypoint exposes command families.
- CLI Commands → Networking: boots · serve and mcp commands expose the server surfaces.
- CLI Commands → Tool Registry: manages · tool subcommands inspect and modify tool exposure.
- CLI Commands → Chat Engine: uses · ui/status/serve flows share the core agent runtime.
- Chat Engine → Prompt Builder: composes · The agent loop builds prompts and resolves tool context.
- Chat Engine → Model Service: calls · Chat delegates generation and streaming to model backends.
- Chat Engine → Tool Registry: selects · Tool calls are routed through the registry and permissions layer.
- Chat Engine → Memory: retrieves · Session context can be assembled from long-term memory.
- Chat Engine → Privacy Filter: filters · Outbound cloud traffic is redacted before sending.
- Chat Engine → Chat Models: persists · The loop writes session turns, attachments, and transcript state.
- Model Service → Model Runtime: governs · Backends share runtime policy, residency, and batching control.
- Model Service → Privacy Filter: streams through · Remote-provider output passes through privacy safeguards.
- Tool Registry → Tool Layers: exposes · The registry surfaces built-in and provider-backed tools.
- Tool Layers → Sandbox: executes in · Shell and code-execution tools are mediated by the sandbox.
- Sandbox → Storage: reads/writes · Workspace artifacts and logs are persisted through storage.
- Sandbox → Networking: serves · Sandbox bridge and stdio/host communication connect to server surfaces.
- Identity → Networking: authenticates · Secure channels and access keys gate local and remote traffic.
- Identity → Storage: stores · Keys, revocations, and secure session state are persisted.
- Documents → Chat Engine: feeds · Structured attachments are normalized before prompting.
- Managers → Views: renders · Managers supply state used by SwiftUI and representable views.
- Computer Use → Chat Engine: extends · Desktop automation is coordinated by the same agent loop.
- Plugin Repo → Plugin ABI: conforms to · Repository installs are validated against the shared plugin ABI.
- Plugin Repo → Tool Registry: registers · Installed plugins become tool-capable surfaces in the registry.
- Eval Harness → Chat Engine: regresses · Evals exercise the agent loop across scenarios and budgets.
- Eval Harness → Computer Use: regresses · Evals also cover computer-use behavior and policies.
- Eval Harness → Sandbox: regresses · Sandbox scenarios are validated by the harness.