Skip to main content

Elements

Wind: Frontend Service Layer

Wind is the Effect-TS service layer for the VS Code workbench, enabling it to function inside a Tauri WebView by recreating the essential VS Code renderer environment through typed error and dependency injection patterns.

Wind: Frontend Service Layer 🍃

Wind is the Effect-TS service layer for the VS Code workbench.

  • Wind enables the workbench to function inside a Tauri WebView.
  • It recreates the essential VS Code renderer environment.
  • It implements core services through Effect-TS typed error and dependency injection patterns.
  • It connects the frontend to Mountain’s Rust backend through Tauri’s invoke() and event system.

Table of Contents

  1. Overview
  2. Architecture
  3. Service Architecture
  4. Layer Composition
  5. Preload Shim Integration
  6. Service Catalog
  7. Mountain IPC Service
  8. Workbench Integration
  9. Related Documentation

graph TB
    subgraph Wind["Wind Frontend Service Layer"]
        PRELOAD["Preload.ts<br/>window.vscode shim"]

        subgraph SERVICES["Effect Services (~40)"]
            CORE["Core<br/>IPC / Config /<br/>Environment / Log"]
            EDITOR["Editor<br/>Editor / Model /<br/>Decorations / History"]
            FS["File System<br/>Files / WorkingCopy<br/>Workspaces"]
            UI["Window / UI<br/>ActivityBar / Sidebar<br/>StatusBar / Panel<br/>Notification / Dialog"]
            MISC["Misc<br/>Clipboard / Terminal<br/>Extensions / Themes<br/>Keybinding / Search"]
        end

        LAYERS["Layer Composition<br/>Function/Install.ts"]
        TLT["TauriLiveLayer<br/>(production)"]
        ELT["ElectronLiveLayer<br/>(compat)"]
        TEST["TestLayer<br/>(mock)"]

        PRELOAD --> SERVICES
        CORE & EDITOR & FS & UI & MISC --> LAYERS
        LAYERS --> TLT
        LAYERS --> ELT
        LAYERS --> TEST
    end

    MOUNTAIN["Mountain<br/>Rust backend"] <-->|"Tauri invoke + events"| CORE
    SKY["Sky<br/>UI Components"] -->|"consumes Runtime"| TLT

Overview 📋

Wind provides the Effect-TS native service layer that Sky consumes.

  • It replaces VS Code’s Electron IPC pipeline with typed Tauri commands.
  • These commands are routed to Rust handlers in Mountain.
  • This eliminates the untyped serialization layer.
  • It preserves full VS Code workbench compatibility.
AttributeValue
LanguageTypeScript (Effect-TS v3.21)
FrameworkVite
IPCTauri invoke() + events
Dependencies@codeeditorland/output, @tauri-apps/api, effect, @effect/platform
Consumed bySky

Architecture 🏗️

+------------------------------------------------------------------+
|                         Wind                                      |
|                                                                   |
|  +------------------+  +------------------+  +------------------+ |
|  | Preload.ts       |  | Effect/          |  | Function/        | |
|  | window.vscode    |  | ~40 service      |  | Install.ts       | |
|  | shim             |  | modules          |  | Layer composition| |
|  +------------------+  +------------------+  +------------------+ |
|                                                                   |
|  +------------------+  +------------------+  +------------------+ |
|  | Workbench/       |  | Telemetry/       |  | IPC/             | |
|  | VS Code workbench|  | PostHog bridge   |  | Tauri event      | |
|  | integration      |  | OTLP bridge      |  | channels         | |
|  +------------------+  +------------------+  +------------------+ |
|                                                                   |
|  +------------------+  +------------------+                       |
|  | Utility/         |  | Types/           |                       |
|  | Tier.ts          |  | Error types,     |                       |
|  | Configuration    |  | interfaces       |                       |
|  +------------------+  +------------------+                       |
+------------------------------------------------------------------+

Module Map 🗺️

PathPurpose
Source/Preload.tsElectron/Node.js API shim (see Polyfills)
Source/Effect/Service implementations (each domain as Define/Implement/Problem)
Source/Function/Install.tsLayer composition and installation entry point
Source/Function/Install/Layer composition details
Source/Workbench/VS Code workbench integration
Source/Telemetry/PostHogBridge.tsIn-webview PostHog client
Source/IPC/Channel.tsTauri event channel definitions
Source/Utility/Tier.tsTier configuration reader
Source/Types/TypeScript type definitions
Source/Bootstrap/Bootstrap type definitions

Service Architecture 🏗️

Each Wind service follows a consistent module structure using the Define/Implement/Problem pattern:

Effect/<Service>/
    +-- Define.ts       - The service Tag (Effect-TS service identifier)
    +-- Implement.ts    - The service implementation (for TauriLiveLayer)
    +-- Problem.ts      - Typed error effects

This pattern provides:

  • Define.ts: Exports the Effect-TS Tag that identifies the service. Functions that depend on the service use Tag for compile-time dependency tracking.
  • Implement.ts: Exports the concrete Layer with the Tauri-backed implementation. Uses @tauri-apps/api/invoke for Mountain communication.
  • Problem.ts: Exports typed error types as Effect-TS Cause subtypes, enabling structured error handling.

Example Service Structure

// Effect/Clipboard/Define.ts
export class Clipboard extends Context.Tag("Clipboard")<
	Clipboard,
	{ readonly readText: Effect<string, ClipboardProblem> }
>() {}

// Effect/Clipboard/Implement.ts
export const ClipboardLive = Layer.succeed(
	Clipboard,
	Clipboard.of({
		readText: Effect.tryPromise({
			try: () => invoke("get_clipboard", { format: "text" }),
			catch: (e) => new ClipboardProblem({ message: String(e) }),
		}),
	}),
);

// Effect/Clipboard/Problem.ts
export class ClipboardProblem extends Data.TaggedError("ClipboardProblem")<{
	message: string;
}> {}

Layer Composition 🧩

Wind services compose into three Layer stacks:

// TauriLiveLayer: All production services for Tauri WebView
export const TauriLiveLayer: Layer<Clipboard | Configuration | Editor | ... > =
    Layer.mergeAll(
        ClipboardLayer,
        ConfigurationLayer,
        EditorLayer,
        TerminalLayer,
        DialogLayer,
        FileServiceLayer,
        WindowLayer,
        // ... all ~40 services
    );

// ElectronLiveLayer: Electron-compatible implementations
export const ElectronLiveLayer: Layer<...> = Layer.mergeAll(
    ElectronClipboardLayer,
    ElectronConfigurationLayer,
    // ... Electron-specific implementations
);

// TestLayer: Mock implementations for extension test runner
export const TestLayer: Layer<...> = Layer.mergeAll(
    MockClipboardLayer,
    MockConfigurationLayer,
    // ... mock implementations
);

Layer Resolution

Sky entry point (index.astro)
    |
    v
Install.installLayer()
    |
    +---> Reads Tier configuration from import.meta.env
    +---> Selects active Layer stack:
    |       - TierWorkbench === "Electron" -> ElectronLiveLayer
    |       - TierWorkbench === "Mountain" -> TauriLiveLayer (default)
    |       - Test mode -> TestLayer
    |
    +---> Layer.toRuntime() converts to Effect-TS Runtime
    +---> Provides Runtime to Sky UI components
    |
    v
Wind services available to Sky via Effect.flatMap

Preload Shim Integration 🔌

Wind’s Preload.ts (see Polyfills.md for full details) runs before the workbench bundle loads:

1. Preload.ts executes (inline, synchronous)
    |
    +---> window.vscode = { ipcRenderer, process }
    +---> window.MonacoEnvironment configured
    +---> window.__CEL_LAND__.polyfills populated
    +---> dispatchEvent("land-preload-ready")
    |
    v
2. Workbench bundle loads from @codeeditorland/output
    |
    v
3. Wind AppLayer created
    +---> composeLayer() creates TauriLiveLayer
    +---> Layer.toRuntime() converts to active Runtime
    |
    v
4. Workbench class instantiated: new Workbench(...)
    - Uses window.vscode for IPC
    - Uses Wind services for state and data

Service Catalog 📋

Core Infrastructure

ServiceModulePurpose
IPCEffect/IPC.tsTauri command invocation and event subscription
ConfigurationEffect/Configuration.tsRead/write settings via Mountain
EnvironmentEffect/Environment.tsOS environment variables and paths
MountainEffect/Mountain.tsgRPC-level communication with Mountain
MountainSyncEffect/MountainSync.tsSynchronous state snapshot from Mountain
LogEffect/LoggingStructured logging

Editor Services

ServiceModulePurpose
EditorEffect/Editor.tsText editor creation, focus, layout
ModelEffect/Model.tsDocument model creation and management
TextModelResolverEffect/TextModelResolver.tsURI-to-model resolution
CodeEditorEffect/WorkbenchEditor/Monaco editor widget
DecorationsEffect/Decorations.tsEditor decoration management
HistoryEffect/History.tsUndo/redo stack management

File System Services

ServiceModulePurpose
FilesEffect/Files.tsFile read/write via Mountain
WorkingCopyEffect/WorkingCopy.tsDirty state and conflict management
WorkspacesEffect/Workspaces.tsWorkspace root resolution

Window and UI Services

ServiceModulePurpose
ActivityBarEffect/ActivityBar.tsActivity bar state
SidebarEffect/Sidebar.tsSide bar visibility and view switching
StatusBarEffect/StatusBar.tsStatus bar items
PanelEffect/Panel.tsBottom panel (terminal, output)
NotificationEffect/Notification.tsToast notifications
ProgressEffect/Progress.tsLong-running operation progress
DialogEffect/WorkbenchDialog/Message boxes and input boxes
QuickInputEffect/QuickInput.tsQuick pick and input box

Clipboard, Terminal, and Extensions

ServiceModulePurpose
ClipboardEffect/Clipboard.tsSystem clipboard via Mountain
TerminalEffect/Terminal.tsIntegrated terminal management
ExtensionsEffect/Extensions.tsExtension install/uninstall/list
LanguageEffect/Language.tsLanguage mode detection
ThemesEffect/Themes.tsColor theme management
KeybindingEffect/Keybinding.tsKeyboard shortcut resolution
SearchEffect/Search.tsFile and text search via Mountain
TelemetryEffect/Telemetry.tsEvent telemetry
StorageEffect/Storage.tsKey-value storage
LifecycleEffect/Lifecycle.tsApplication lifecycle events
HealthEffect/Health.tsService health monitoring

Mountain IPC Service 🔌

The Mountain service (Effect/Mountain.ts) maintains a runtime connection to the Rust backend:

// Wind sends commands to Mountain via Tauri invoke
const fileContent: Uint8Array = await invoke("read_file", {
	path: workspaceFile.fsPath,
});

// Wind listens for Mountain events
await listen("configuration-changed", (event) => {
	syncConfiguration(event.payload);
});

Command Mapping

Wind ServiceTauri CommandMountain Handler
Files.readread_fileFileSystemProvider
Files.writewrite_fileFileSystemProvider
Configuration.getget_configurationConfigurationProvider
Configuration.setset_configurationConfigurationProvider
Terminal.createcreate_terminalTerminalProvider
Terminal.writewrite_terminalTerminalProvider
Dialog.openopen_dialogUserInterfaceProvider
Clipboard.readget_clipboardClipboard
Clipboard.writeset_clipboardClipboard

Workbench Integration 🔌

Wind integrates with the VS Code workbench by providing service implementations that satisfy the workbench’s dependency injection container:

// VS Code workbench expects IFileService
// Wind provides FileService that implements the same interface
const workbench = new Workbench({
	fileService: Wind.FileService,
	configurationService: Wind.Configuration,
	editorService: Wind.Editor,
	notificationService: Wind.Notification,
	// ... all services the workbench expects
});

await workbench.startup();

  • Sky - UI component layer (Wind consumer)
  • Cocoon - Extension host (parallel API surface)
  • Mountain - Backend (IPC target)
  • Output - Compiled workbench consumer
  • Polyfills - Preload.ts shim details
  • EditorCore - Editor workbench adaptation

Project Maintainers: Source Open (Source/[email protected]) | GitHub Repository | Report an Issue


See Also