How winrisef/ctxrun works
1. Overall shape
- CtxRun is a Tauri 2 desktop application: a React/TypeScript frontend runs inside multiple WebView windows, while a Rust backend owns system access, local services, persistence, and privileged operations.
- The repository is split into a frontend app under src/ and a Rust/Tauri workspace under src-tauri/, with feature-heavy domains implemented as separate Rust crates.
2. Windowed desktop shell
- The frontend is organized around distinct windows and UI shells: main, spotlight, peek, and guard.
- src/windows/main is the primary workspace shell; spotlight is the global command/chat surface; peek is a standalone preview window; guard is the idle-lock screen.
- Shared layout pieces like title bar, workspace switcher, and view switcher live in src/components/layout, while app-wide state is managed with Zustand stores in src/store.
3. Feature-oriented frontend
- Each major capability is isolated in src/components/features/* with its own view layer and supporting hooks.
- The frontend feature set matches the product areas in the README: Context Forge, Spotlight, Prompt Verse, Patch Weaver, Refinery, Automator, Model Miner, Transfer, Guard, Peek, monitoring, and settings.
- The frontend also includes reusable infrastructure for i18n, markdown rendering, previewing, code editing, AI/LLM interactions, and local storage abstractions in src/lib.
4. Rust backend as domain services
- The backend is not a single monolith; it is split into focused crates under src-tauri/crates/.
- Most crates expose Tauri commands and have their own permission manifests, showing a clear boundary between UI requests and privileged OS/file/network operations.
- This structure makes it straightforward to draw the backend as multiple domain services behind the Tauri bridge.
5. Local persistence layer
- The db crate owns SQLite persistence and schema migrations.
- It stores application data such as app metadata, project config, prompts, secrets, shell history, and URL history.
- Migrations are managed separately, so the database is an explicit subsystem rather than an incidental cache.
6. Context assembly and secret scanning
- The context crate handles project tree scanning, ignore-file awareness, tokenization, content assembly, and sensitive-data detection.
- It includes gitleaks-inspired rules and allowlists, so its data flow is: project filesystem → scanner/tokenizer → filtered context output → UI preview/export.
- This is the core engine behind Context Forge and the security scan features.
7. AI tool and command execution
- The tool-runtime crate provides a sandboxed AI tool environment for filesystem, web, and patch-related actions.
- The exec-runtime crate is the command-execution counterpart: it manages request/approval, terminal interaction, resizing, termination, and safety policy enforcement.
- On the frontend, src/lib/agent and the Spotlight UI coordinate these capabilities, so AI conversations can invoke tools or launch shell actions only through approved runtime boundaries.
8. Git and patch workflow
- The git crate exposes commit/diff/export commands, while frontend patch components provide diff viewing, workspace comparison, and export flows.
- Patch-related logic is therefore split between Rust for Git data extraction and React for visualization and editing assistance.
- This is a distinct pipeline from plain text context assembly: source tree/diff data is transformed into reviewable patch views.
9. Clipboard history and cleanup subsystem
- The refinery crate manages clipboard history, notes, pinning, cleanup, statistics, and Spotlight quick-paste integration.
- It includes worker and cleanup worker components, which implies background processing rather than purely UI-driven behavior.
- The frontend RefineryView and related sidebar/feed components are the presentation layer for this locally persisted activity stream.
10. Web mining and preview pipeline
- The miner crate performs crawl/extraction work using Readability-style processing and Markdown conversion, with queue/scope/storage separation.
- The frontend MinerView drives search, start/stop, and result presentation.
- Related to this, the hyperview and ocr crates support rich file preview and OCR recognition, feeding preview panels and standalone preview windows.
11. Network and device transfer
- The transfer crate exposes a local LAN transfer service: device discovery, QR pairing, file/message exchange, WebSocket chat, and server lifecycle control.
- The frontend TransferView becomes a control panel over a backend-local HTTP/WebSocket service.
- This subsystem is explicitly networked, unlike most of the app, but still remains local-first and peer-to-peer over the LAN.
12. System monitoring and environment probing
- env-probe collects machine, browser, SDK, IDE, binary, and network metadata.
- monitor-related frontend views surface this information as system dashboards, port/process tools, network diagnostics, and environment fingerprints.
- This subsystem is read-heavy and diagnostic, feeding observability-style views rather than core editing workflows.
13. Guard and input interception
- The guard window and backend support idle detection, low-level input monitoring, long-press unlock, and sleep-prevention behavior.
- This is a separate security/usability boundary because it needs global input and OS-level hooks, unlike normal in-app UI state.
14. Build, assets, and generated data
- Build-time content is significant: build/ generates prompt packs, and models/ contains OCR model metadata.
- GitHub Actions workflows cover CI, releases, prompt updates, and OCR model sync, so some runtime assets are produced from external sources and then bundled locally.
- The repo also contains generated Tauri schemas and permissions manifests, reinforcing that capabilities are intentionally constrained and surfaced per crate.
15. Key architectural boundary for a diagram
- The cleanest mental model is: React/Tauri UI windows on the left, Rust domain crates and local services on the right, with SQLite and local OS/network resources underneath.
- Most user actions start in a feature view, cross the Tauri command boundary, hit a dedicated Rust crate, and then return structured results to the UI for rendering or storage.
Main entry points: features Feature views · main.rs Tauri bridge · src SQLite DB · layout App shell
Components 24
React/Tauri UI
WebView windows, views, shared components, and client-side orchestration.
- Main window · Primary workspace window for the app's main flows.
src/windows/main/MainWindowApp.tsx - Spotlight · Global search, chat, and approval-driven action surface.
src/windows/spotlight/SpotlightWindowApp.tsx - Peek · Standalone preview window for rich file and media inspection.
src/windows/peek/PeekWindowApp.tsx - Guard · Idle-lock and unlock window for guarded sessions.
src/windows/guard/GuardWindowApp.tsx - App shell · Title bar, workspace switching, and view switching across windows.
src/components/layout - Feature views · Primary product areas exposed as React feature panels and dialogs.
src/components/features - Stores · Zustand stores and cross-window state synchronization.
src/store - Agent client · Frontend agent runtime, tool registry, and approval-aware execution wiring.
src/lib/agent - Preview stack · Hyperview preview, OCR, and renderer components for rich content display.
src/components/features/hyperview - Context Forge · Project scanning, token dashboard, filtering, and secret-scan presentation.
src/components/features/context - Spotlight UI · Chat, search, trace, and approval UI for the Spotlight window.
src/components/features/spotlight - Patch tools · Commit selection, diff viewing, workspace comparison, and export dialogs.
src/components/features/patch
Rust services
Tauri backend workspace with domain crates and privileged commands.
- Tauri bridge · Main Tauri application entry and command surface exposed to the frontend.
src-tauri/src/main.rs - Context service · Filesystem scanning, tokenization, ignore handling, and secret detection.
src-tauri/crates/context/src - Tool runtime · Sandboxed AI tools for filesystem, patch, web, and workspace operations.
src-tauri/crates/tool-runtime/src - Exec runtime · Approved shell execution, terminal I/O, resizing, and safety policy enforcement.
src-tauri/crates/exec-runtime/src - Git service · Commit, diff, and export operations used by patch workflows.
src-tauri/crates/git/src - Refinery · Clipboard history, notes, pinning, cleanup, statistics, and worker processing.
src-tauri/crates/refinery/src - Miner · Web crawl, extraction, and search pipeline with queue and storage stages.
src-tauri/crates/miner/src/core - Transfer · Local device discovery, pairing, messaging, file exchange, and WebSocket server lifecycle.
src-tauri/crates/transfer/src - Env probe · System, browser, SDK, binary, and network metadata collection for monitoring views.
src-tauri/crates/env-probe/src/env_probe - Guard service · Idle detection, input monitoring, sleep prevention, and unlock support.
src-tauri/src/guard.rs
Local data
Persistence and generated assets used across the app.
- SQLite DB · Application database and migrations for prompts, history, secrets, and configs.
src-tauri/crates/db/src - Build assets · Prompt packs, OCR model metadata, and bundled generated data used at runtime.
build/dist/packs
Connections 34
- Main window → App shell: uses · Main shell composes shared navigation and chrome.
- Spotlight → App shell: uses · Spotlight window reuses shared title and switching controls.
- Peek → App shell: uses · Peek relies on the same app shell patterns.
- Guard → App shell: uses · Guard window is styled through shared window chrome.
- Main window → Feature views: hosts · Primary workspace window embeds major feature panels.
- Spotlight → Spotlight UI: hosts · Spotlight window renders chat, search, and trace flows.
- Peek → Preview stack: hosts · Peek window is driven by the preview pipeline.
- Guard → Guard service: drives · Guard UI depends on idle and unlock behavior from the backend.
- Feature views → Context Forge: includes · Context Forge is one of the major feature areas.
- Feature views → Patch tools: includes · Patch workflow views are part of the feature set.
- Feature views → Preview stack: includes · Preview-oriented features share the hyperview stack.
- Feature views → Agent client: includes · Features coordinate with the local agent/tool layer.
- Feature views → Refinery: includes · Clipboard history and cleanup are surfaced in the UI.
- Feature views → Miner: includes · Web mining has its own feature view.
- Feature views → Transfer: includes · LAN transfer is presented as a dedicated feature.
- Feature views → Env probe: includes · System monitoring views present probe results.
- Feature views → Build assets: uses · UI consumes generated prompt packs and model metadata.
- Spotlight UI → Agent client: calls · Chat and trace flows invoke tools through the agent runtime.
- Agent client → Tauri bridge: routes through · Frontend tool calls cross the Tauri bridge.
- Tauri bridge → Context service: exposes · Tauri commands publish context scanning operations.
- Tauri bridge → SQLite DB: exposes · Commands persist and read app data via SQLite.
- Tauri bridge → Tool runtime: exposes · Tool execution is mediated by the backend runtime.
- Tauri bridge → Exec runtime: exposes · Shell execution commands are surfaced through Tauri.
- Tauri bridge → Git service: exposes · Git inspection and export commands are routed here.
- Tauri bridge → Refinery: exposes · Clipboard history and cleanup commands are routed here.
- Tauri bridge → Miner: exposes · Mining search and extraction commands are routed here.
- Tauri bridge → Transfer: exposes · Transfer service lifecycle and messaging are bridged here.
- Tauri bridge → Env probe: exposes · Environment probe data is requested through Tauri commands.
- Context service → SQLite DB: reads/writes · Context and secret data can be stored or referenced in SQLite.
- Git service → SQLite DB: reads/writes · Patch workflows can store related metadata and history.
- Refinery → SQLite DB: reads/writes · Clipboard items, notes, and cleanup state are persisted.
- Miner → SQLite DB: reads/writes · Mining results and queue state are stored locally.
- Transfer → SQLite DB: reads/writes · Device and chat state are persisted locally.
- Env probe → Build assets: uses · Monitoring and OCR-related features depend on bundled assets.