Skip to content

Commit 81e1b08

Browse files
docs(Cocoon): benefit-focused README rewrite
Replace verbose technical documentation with outcome-first copy matching the website's goal-oriented direction. The old README led with feature lists and architectural deep-dives. The new version opens with the core problem statement (VS Code's single event loop limitation), followed by what Cocoon gives you: supervised fiber isolation, automatic timeout/restart, and concurrent extension activation. References: 4b42f88 (previous README rewrite)
1 parent 4b42f88 commit 81e1b08

1 file changed

Lines changed: 24 additions & 156 deletions

File tree

README.md

Lines changed: 24 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -37,135 +37,35 @@ Land
3737
</tr>
3838
</table>
3939

40+
4041
---
4142

42-
# **Cocoon** 🦋
43+
# **Cocoon**&#x2001;🦋
44+
45+
> **VS Code's extension host is a single Node.js event loop. One hung Promise blocks every other extension. There is no way to cancel an in-flight operation, no back-pressure, no preemption.**
4346
44-
The Extension Host for Land 🏞️
47+
_"Every extension runs in its own supervised fiber. One crash doesn't take down the rest."_
4548

4649
[![License: CC0-1.0](https://img.shields.io/badge/License-CC0_1.0-lightgrey.svg)](https://github.com/CodeEditorLand/Cocoon/tree/Current/LICENSE)
4750
[![NPM Version](https://img.shields.io/npm/v/@codeeditorland/cocoon.svg)](https://www.npmjs.com/package/@codeeditorland/cocoon)
4851
[![Node.js Version](https://img.shields.io/badge/Node.js-v18+-blue.svg)](https://nodejs.org/)
4952
[![Effect Version](https://img.shields.io/badge/Effect-v3-blueviolet.svg)](https://www.npmjs.com/package/effect)
5053

51-
Your entire VS Code extension library works out of the box. Cocoon hosts
52-
Node.js extensions in a managed sidecar process that mirrors the full VS Code
53-
Extension Host API. Install an extension, activate it, and it works exactly as
54-
it does in VS Code.
55-
56-
Cocoon talks to Mountain over gRPC (Vine protocol). Extension API calls become
57-
typed Effects that Mountain executes natively. The result: extensions run at
58-
Rust speed for I/O operations while keeping full Node.js compatibility.
54+
Cocoon intercepts `require`/`import` at the Node.js module level and routes all VS Code API calls through Effect-TS fibers. Extensions call `vscode.workspace.openTextDocument()` and get back a `Thenable<TextDocument>` exactly as documented. Internally, each call is a typed Effect that can be interrupted, raced with a timeout, and run concurrently. 50+ extensions activate in parallel. Language server crashes are handled in supervised scopes with automatic restart. The full VS Code marketplace works without modification.
5955

6056
---
6157

62-
## Key Features & Architectural Highlights 🔐
63-
64-
- **Effect-TS Native Architecture:** The entire `Cocoon` application is built
65-
with **Effect-TS**. All services, API shims, and IPC logic are implemented as
66-
declarative, composable `Layer`s and `Effect`s, ensuring robustness,
67-
testability, and type safety.
68-
- **High-Fidelity VSCode API Shims:** Provides a comprehensive set of service
69-
shims (e.g., for `vscode.workspace`, `vscode.window`, `vscode.commands`) that
70-
replicate the behavior of the real VS Code Extension Host.
71-
- **gRPC-Powered Communication:** All communication with the `Mountain` backend
72-
is handled via gRPC, providing a fast, modern, and strongly-typed contract for
73-
all IPC operations.
74-
- **Robust Module Interception:** Implements high-fidelity interceptors for both
75-
CJS `require()` and ESM `import` statements, ensuring calls to the `'vscode'`
76-
module are correctly sandboxed and routed to the appropriate,
77-
extension-specific API instance.
78-
- **Process Hardening & Lifecycle Management:** Includes process patching to
79-
handle uncaught exceptions, pipe logs to the host, and automatically terminate
80-
if the parent `Mountain` process exits, ensuring a stable sidecar.
58+
## What It Does&#x2001;🔐
8159

82-
---
83-
84-
## Deep Dive & Component Breakdown 🔬
85-
86-
To understand how `Cocoon`'s internal components interact to provide the
87-
high-fidelity `vscode` API, see the following source files:
88-
89-
- **[`Bootstrap/Implementation/CocoonMain.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Bootstrap/Implementation/CocoonMain.ts)** -
90-
Main entry point and bootstrap orchestration
91-
- **[`Effect/Bootstrap.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Effect/Bootstrap.ts)** -
92-
Effect-TS bootstrap stages (Environment, Configuration, Mountain Connection,
93-
Module Interceptor, RPC Server, Extensions, Health Check)
94-
- **[`ServiceMapping.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/ServiceMapping.ts)** -
95-
Dependency injection and service composition
96-
- **[`Services/APIFactory.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Services/APIFactory.ts)** -
97-
Constructs the `vscode` API object for extensions
98-
- **[`Services/ExtensionHostService.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Services/ExtensionHostService.ts)** -
99-
Extension activation and lifecycle management
100-
- **[`Services/IPCService.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Services/IPCService.ts)** -
101-
Bi-directional gRPC communication
102-
- **[`Services/MountainGRPCClient.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Services/MountainGRPCClient.ts)** -
103-
gRPC client for Mountain backend
104-
- **[`PatchProcess/`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/PatchProcess/)** -
105-
Process hardening and security
106-
- **[`TypeConverter/`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/TypeConverter/)** -
107-
DTO serialization for gRPC transport
60+
- **Every VS Code extension runs unchanged.** The API contract is preserved in full. Nothing needs to be ported.
61+
- **Supervised fiber isolation.** One extension's hung Promise does not block another's fiber.
62+
- **Automatic timeout and restart.** Language server crashes are handled in supervised scopes.
63+
- **Concurrent activation.** 50+ extensions activate in parallel, not sequentially.
64+
- **Performance tracing.** Every extension operation can be traced without code changes.
10865

10966
---
11067

111-
## `Cocoon` in the Land Ecosystem 🦋 + 🏞️
112-
113-
Cocoon operates as a standalone Node.js process, carefully orchestrated by and
114-
communicating with `Mountain`.
115-
116-
| Component within Cocoon | Role & Key Responsibilities |
117-
| :------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
118-
| **Node.js Process** | The runtime environment for Cocoon. |
119-
| **`Bootstrap/Implementation/CocoonMain.ts`** | The primary entry point. It composes all `Effect-TS` layers, establishes the gRPC connection, performs the initialization handshake with `Mountain`, and starts the extension host services. |
120-
| **`PatchProcess/`** | Performs very early process hardening (patching `process.exit`, handling exceptions, piping logs), ensuring a stable foundation before any other code runs. |
121-
| **`Effect/` Modules** | Orchestrates the bootstrap process. `Bootstrap.ts` coordinates initialization stages, `Extension.ts` manages extension lifecycle, `ModuleInterceptor.ts` patches `require` and `import`, and `Telemetry.ts` provides logging and tracing. |
122-
| **`Services/` Modules** | A comprehensive collection of Effect-TS `Layer`s, each implementing a specific VS Code `IExtHost...` service interface (e.g., `CommandsProvider`, `WorkspaceProvider`, `WebviewProvider`). These shims are the core of the compatibility layer. Key services include `APIFactory.ts`, `ExtensionHostService.ts`, `IPCService.ts`, and `MountainGRPCClient.ts`. |
123-
| **`IPC/` & `Services/IPC.ts`** | `IPC/` contains the protocol layer (`Channel.ts`, `Handler.ts`, `Message.ts`, `Protocol.ts`). `Services/IPC.ts` implements both the gRPC client (to call `Mountain`) and server (to receive calls from `Mountain`), managing the entire bi-directional communication lifecycle. |
124-
| **`TypeConverter/`** | Provides pure functions to serialize TypeScript types into plain DTOs for gRPC transport. Organized by feature: `Main/` (URI, Range, TextEdit), `Dialog/`, `TreeView/`, `Webview/`, `Task/`, `WorkspaceEdit/`. The actual `vscode` API class definitions are in the `Services/` modules that use them. |
125-
| **Extension Code** | The JavaScript/TypeScript code of the VS Code extensions being hosted and run within the Cocoon environment. |
126-
127-
### Interaction Flow (Example: `vscode.window.showInformationMessage`)
128-
129-
1. `Mountain` launches `Cocoon` with initialization data.
130-
2. `Cocoon`'s
131-
[`Bootstrap/Implementation/CocoonMain.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Bootstrap/Implementation/CocoonMain.ts)
132-
bootstraps the application:
133-
- `PatchProcess` hardens the environment.
134-
- `Effect/Bootstrap.ts` orchestrates the initialization stages (environment
135-
detection, configuration, gRPC connection, module interceptor, RPC server,
136-
extensions, health check).
137-
- The main `AppLayer` is built via
138-
[`ServiceMapping.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/ServiceMapping.ts),
139-
composing all Effect-TS services.
140-
- The real VS Code `ExtHostExtensionService` is instantiated within this
141-
Effect-TS environment.
142-
3. `ExtHostExtensionService` (in
143-
[`Services/ExtensionHostService.ts`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Services/ExtensionHostService.ts))
144-
activates an extension. The extension receives a `vscode` API object
145-
constructed by the
146-
[`APIFactory`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Services/APIFactory.ts)
147-
service.
148-
4. The extension calls `vscode.window.showInformationMessage("Hello")`.
149-
5. The call is routed to the
150-
[`Window`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Services/Window.ts)
151-
service.
152-
6. The `Window` service creates an `Effect` that sends a `showMessage` gRPC
153-
request to `Mountain` via
154-
[`MountainGRPCClient`](https://github.com/CodeEditorLand/Cocoon/tree/Current/Source/Services/MountainGRPCClient.ts).
155-
7. `Mountain`'s `Vine` layer receives the request. Its `Track` dispatcher routes
156-
it to the native UI handler.
157-
8. `Mountain` displays the native UI notification and waits for user
158-
interaction.
159-
9. The result is sent back to `Cocoon` via a gRPC response.
160-
10. The `Effect` in `Cocoon` completes, resolving the promise returned to the
161-
extension's API call.
162-
163-
---
164-
165-
## System Architecture Diagram 🏗️
166-
167-
This diagram illustrates the internal architecture of Cocoon and its place
168-
within the broader Land ecosystem.
68+
## In the Ecosystem&#x2001;🦋 + 🏞️
16969

17070
```mermaid
17171
graph LR
@@ -211,64 +111,32 @@ GRPCClient -- gRPC <--> VineGRPC
211111

212112
---
213113

214-
## Getting Started with Cocoon Development 🚀
215-
216-
Cocoon is developed as a core component of the main **Land** project. To work on
217-
or run Cocoon, please follow the instructions in the main
218-
[Land Repository README](https://github.com/CodeEditorLand/Land). The
219-
`Bundle=true` build variable is essential, as it triggers the `Rest` element to
220-
prepare the necessary VS Code platform code for Cocoon to consume.
221-
222-
**Key Dependencies:**
114+
## Development&#x2001;🛠️
223115

224-
- `effect` (v3.19.18): The core library for the entire application structure.
225-
- `@effect/platform` & `@effect/platform-node`: Effect-TS platform abstractions.
226-
- `@grpc/grpc-js` & `@grpc/proto-loader`: For gRPC communication.
227-
- `google-protobuf` & `protobufjs`: Protocol buffers for gRPC.
228-
- VS Code platform code (e.g., `vs/base`, `vs/platform`), sourced from the
229-
`Land/Dependency` submodule.
230-
231-
**Current Version:** 0.0.1 (see [`package.json`](package.json))
232-
233-
**Debugging Cocoon:**
234-
235-
- Since Cocoon is a Node.js process, it can be debugged by attaching a standard
236-
Node.js debugger. `Mountain` must launch the Cocoon process with the
237-
appropriate Node.js debug flags (e.g., `--inspect-brk=PORT_NUMBER`).
238-
- Logs from `Cocoon` are automatically piped to the parent `Mountain` process
239-
thanks to the `PatchProcess` module and will appear in `Mountain`'s console
240-
output or log files.
241-
242-
---
243-
244-
## License ⚖️
245-
246-
This project is released into the public domain under the **Creative Commons CC0
247-
Universal** license.
248-
249-
You are free to use, modify, distribute, and build upon this work for any
250-
purpose, without any restrictions. For the full legal text, see the
251-
[`LICENSE`](https://github.com/CodeEditorLand/Cocoon/tree/Current/) file.
116+
Cocoon is a component of the Land workspace. Follow the
117+
[Land Repository](https://github.com/CodeEditorLand/Land) instructions to
118+
build and run.
252119

253120
---
254121

255-
## Changelog 📜
122+
## License&#x2001;⚖️
256123

257-
Stay updated with our progress! See
258-
[`CHANGELOG.md`](https://github.com/CodeEditorLand/Cocoon/tree/Current/) for a
259-
history of changes specific to **Cocoon**.
124+
CC0 1.0 Universal. Public domain. No restrictions.
125+
[LICENSE](https://github.com/CodeEditorLand/Cocoon/tree/Current/LICENSE)
260126

261127
---
262128

263-
264129
## See Also
265130

131+
- [Cocoon Documentation](https://editor.land/Doc/cocoon)
266132
- [Architecture Overview](https://editor.land/Doc/architecture)
133+
- [Why Effect-TS](https://editor.land/Doc/why-effect-ts)
134+
- [Why gRPC](https://editor.land/Doc/why-grpc)
267135
- [Mountain](https://github.com/CodeEditorLand/Mountain)
268136
- [Wind](https://github.com/CodeEditorLand/Wind)
269-
- [Sky](https://github.com/CodeEditorLand/Sky)
270137
- [Vine](https://github.com/CodeEditorLand/Vine)
271138

139+
272140
## Funding & Acknowledgements 🙏🏻
273141

274142
**Cocoon** is a core element of the **Land** ecosystem. This project is funded

0 commit comments

Comments
 (0)