|
| 1 | +# FineCode WM-ER Protocol |
| 2 | + |
| 3 | +This document describes the communication protocol between the FineCode Workspace |
| 4 | +Manager (WM) and Extension Runners (ER). WM is the JSON-RPC client; each ER is a |
| 5 | +JSON-RPC server implemented via the LSP stack (`finecode_extension_runner/lsp_server.py`). |
| 6 | +The protocol is LSP-shaped with a small set of custom commands. |
| 7 | + |
| 8 | +## Transport |
| 9 | + |
| 10 | +- JSON-RPC 2.0 |
| 11 | +- LSP-style framing over stdio: `Content-Length: N\r\nContent-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n{json}` |
| 12 | +- WM spawns ER processes with: |
| 13 | + - `python -m finecode_extension_runner.cli start --project-path=... --env-name=...` |
| 14 | + - `--debug` enables a debugpy attach flow before WM connects |
| 15 | +- Field names are camelCase for standard LSP params, but command arguments are |
| 16 | + passed verbatim (snake_case is common in FineCode payloads). |
| 17 | + |
| 18 | +## Lifecycle |
| 19 | + |
| 20 | +1. WM starts the ER process (per project + env). |
| 21 | +2. WM sends `initialize` and waits for the ER response. |
| 22 | +3. WM sends `initialized`. |
| 23 | +4. WM sends `finecodeRunner/updateConfig` to bootstrap handlers and services. |
| 24 | +5. On shutdown: WM sends `shutdown` then `exit`. |
| 25 | + |
| 26 | +## Message Catalog |
| 27 | + |
| 28 | +### WM -> ER |
| 29 | + |
| 30 | +**Requests** |
| 31 | + |
| 32 | +- `initialize` |
| 33 | + - Standard LSP initialize request. |
| 34 | + - Example params (trimmed): |
| 35 | + ```json |
| 36 | + { |
| 37 | + "processId": 12345, |
| 38 | + "clientInfo": {"name": "FineCode_WorkspaceManager", "version": "0.1.0"}, |
| 39 | + "capabilities": {}, |
| 40 | + "workspaceFolders": [{"uri": "file:///path/to/project", "name": "project"}], |
| 41 | + "trace": "verbose" |
| 42 | + } |
| 43 | + ``` |
| 44 | + |
| 45 | +- `shutdown` |
| 46 | + - Standard LSP shutdown request. |
| 47 | + |
| 48 | +- `workspace/executeCommand` |
| 49 | + - Used for all FineCode WM → ER commands. The `arguments` array is passed to |
| 50 | + the handler verbatim. |
| 51 | + |
| 52 | + **Commands** |
| 53 | + |
| 54 | + - `finecodeRunner/updateConfig` |
| 55 | + - Arguments: |
| 56 | + 1. `working_dir` (string path) |
| 57 | + 2. `project_name` (string) |
| 58 | + 3. `project_def_path` (string path) |
| 59 | + 4. `config` (object) |
| 60 | + - Config shape (top-level): |
| 61 | + - `actions`: list of action objects (`name`, `handlers`, `source`, `config`) |
| 62 | + - `action_handler_configs`: map of handler source → config |
| 63 | + - `services`: list of service declarations (optional) |
| 64 | + - `handlers_to_initialize`: map of action name → handler names (optional) |
| 65 | + - Result: `{}` (empty object) |
| 66 | + |
| 67 | + - `actions/run` |
| 68 | + - Arguments: |
| 69 | + 1. `action_name` (string) |
| 70 | + 2. `params` (object) |
| 71 | + 3. `options` (object, optional) |
| 72 | + - Options (snake_case keys are expected): |
| 73 | + - `meta`: `{ "trigger": "user|system|unknown", "dev_env": "ide|cli|ai|precommit|ci" }` |
| 74 | + - `partial_result_token`: `int | string` (used to correlate `$/progress`) |
| 75 | + - `result_formats`: `["json", "string"]` (defaults to `["json"]`) |
| 76 | + - Result (success): |
| 77 | + ```json |
| 78 | + { |
| 79 | + "status": "success", |
| 80 | + "result_by_format": "{\"json\": {\"...\": \"...\"}}", |
| 81 | + "return_code": 0 |
| 82 | + } |
| 83 | + ``` |
| 84 | + - Result (stopped): |
| 85 | + ```json |
| 86 | + { |
| 87 | + "status": "stopped", |
| 88 | + "result_by_format": "{\"json\": {\"...\": \"...\"}}", |
| 89 | + "return_code": 1 |
| 90 | + } |
| 91 | + ``` |
| 92 | + - Result (error): |
| 93 | + ```json |
| 94 | + {"error": "message"} |
| 95 | + ``` |
| 96 | + - Note: `result_by_format` is a JSON string (not a JSON object) due to |
| 97 | + LSP serialization constraints in the runner. |
| 98 | + |
| 99 | + - `actions/mergeResults` |
| 100 | + - Arguments: `[action_name, results]` |
| 101 | + - Result: `{ "merged": ... }` or `{ "error": "..." }` |
| 102 | + |
| 103 | + - `actions/reload` |
| 104 | + - Arguments: `[action_name]` |
| 105 | + - Result: `{}` |
| 106 | + |
| 107 | + - `packages/resolvePath` |
| 108 | + - Arguments: `[package_name]` |
| 109 | + - Result: `{ "packagePath": "/abs/path/to/package" }` |
| 110 | + |
| 111 | +**Notifications** |
| 112 | + |
| 113 | +- `initialized` (standard LSP) |
| 114 | +- `textDocument/didOpen` |
| 115 | +- `textDocument/didChange` |
| 116 | +- `textDocument/didClose` |
| 117 | +- `$/cancelRequest` |
| 118 | + - Sent by WM when an in-flight request should be cancelled. |
| 119 | + |
| 120 | +### ER -> WM |
| 121 | + |
| 122 | +**Requests** |
| 123 | + |
| 124 | +- `workspace/applyEdit` |
| 125 | + - Standard LSP request for applying workspace edits. |
| 126 | + - WM forwards this to its active client (IDE) if available. |
| 127 | + |
| 128 | +- `projects/getRawConfig` |
| 129 | + - Params: `{ "projectDefPath": "/abs/path/to/project/finecode.toml" }` |
| 130 | + - Result: `{ "config": "<stringified JSON config>" }` |
| 131 | + - Used by ER during `finecodeRunner/updateConfig` to resolve project config. |
| 132 | + |
| 133 | +**Notifications** |
| 134 | + |
| 135 | +- `$/progress` |
| 136 | + - Params: `{ "token": <token>, "value": "<stringified JSON partial result>" }` |
| 137 | + - The `token` must match `partial_result_token` from `actions/run`. |
| 138 | + - `value` is a JSON string produced by the ER from a partial run result. |
| 139 | + |
| 140 | +## Error Handling and Cancellation |
| 141 | + |
| 142 | +- JSON-RPC errors are used for protocol-level failures. |
| 143 | +- Command-level errors are returned via `{ "error": "..." }` in command results. |
| 144 | +- WM cancels in-flight requests by sending `$/cancelRequest` with the request id. |
| 145 | + |
| 146 | +## Document Sync Notes |
| 147 | + |
| 148 | +WM forwards open-file events to ER so actions can operate on in-memory document |
| 149 | +state. ER may send `workspace/applyEdit` when handlers modify files; WM applies |
| 150 | +these edits via its active client when possible. |
0 commit comments