From e7d511d7c8f6dff704fecb95c0f9c9c5a709e1a3 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 23 Nov 2026 11:31:31 -0600 Subject: [PATCH] docs(id): align web/hosted/MCP docs with the shipped code (WEB-1..WEB-15) Corrects the in-repo documentation disagreements recorded in #13365, where the ID book states the code behaviour and the older docs did not: - WEB.md: full route table (54 paths / 58 method bindings plus the program-only router), replacing the nonexistent /edit/{hash} and /file/{name} spellings with /edit/{*name}, /view/{*name}, /hash/{hash}; crate-split project structure (crates/id-web); hashed asset names (main..js, styles..css) instead of main.js/main.css; lowercase TagEvent wire format with from/to/count; a Security Layer section (Host allow-list, Origin check, token gate); E2E counts and file list as they stand (138 tests across 7 spec files). - web/README: collab wire table completed to tags 0-11 with the Init mode field; connection flow names {doc_id}; empty-text cadence corrected (Ping each 30s idle cycle, every 2nd replaced by empty text); TagEvent format as above; dist/ described as tracked with a .gitkeep (contents ignored), not git-ignored as a directory. - hosted-worker/README: UserDO route list replaced with the implemented surface (13 paths / 15 method routes: state, usage, export, KV PUT/GET/DELETE, blobs, bridge). - README: Project Structure rewritten for the crate split; E2E counts corrected to match. - id-caps mcp_bridge: the v1 surface doc comment now states that presence.set is pinned but always refused (NoFrameMapping). - id-cli server_config: the module doc comment's [budgets] table now lists all five implemented keys, adding app_inbound_bytes_per_second and per_peer_burst_bytes_per_minute. Refs #13365. --- pkgs/id/README.md | 69 +++---- pkgs/id/WEB.md | 180 ++++++++++++++---- pkgs/id/crates/id-caps/src/mcp_bridge.rs | 6 + .../id/crates/id-cli/src/server_config/mod.rs | 2 + pkgs/id/hosted-worker/README.md | 17 +- pkgs/id/web/README.md | 60 +++--- 6 files changed, 232 insertions(+), 102 deletions(-) diff --git a/pkgs/id/README.md b/pkgs/id/README.md index c65ee16757..2554cf5162 100644 --- a/pkgs/id/README.md +++ b/pkgs/id/README.md @@ -345,7 +345,7 @@ just test-rust # Rust tests only (~408 unit + ~93 integration) just test-unit # Unit tests only (fast, ~408 tests) just test-integration # Integration tests only (~93 tests) just test-web-unit # TypeScript unit tests (~304 assertions) -just test-e2e # Playwright E2E (chromium + firefox, 208 tests) +just test-e2e # Playwright E2E (chromium + firefox, 276 tests) just test-nix # nix flake check (27 checks — runs everything) just ci # Full CI check suite just check # Fix + CI (run before committing) @@ -367,50 +367,53 @@ just test-nixos-playwright-e2e # Full Playwright in 4 NixOS VMs See [ARCHITECTURE.md](ARCHITECTURE.md) for detailed system architecture. ``` -src/ +src/ # The `id` facade crate: entry point and node bootstrap, + # plus the surfaces that compose the crates below + # (file ops, currency gateway, hosted binding/export/ingest, + # serve proxy, boards, grants) ├── main.rs # Entry point -├── lib.rs # Library exports, node bootstrap -├── cli.rs # Clap argument definitions -├── protocol.rs # P2P request/response protocol -├── store.rs # Iroh blob store operations -├── tags.rs # Metadata tag system (alpha/omega dual-index) -├── tuple.rs # Sort-preserving binary key encoding -├── helpers.rs # Parsing and formatting utilities -├── discovery.rs # Peer discovery -├── commands/ # Command implementations -│ ├── put.rs, get.rs, find.rs, list.rs, peers.rs, id.rs, tag.rs -│ ├── serve.rs # Server with optional web UI -│ ├── repl.rs # REPL entry point -│ └── client.rs # Remote peer client -├── repl/ # REPL internals -│ ├── runner.rs # Command dispatch and help -│ └── input.rs # Shell preprocessing (pipes, subshells, heredocs) -└── web/ # Web UI (feature-gated) - ├── routes.rs # Axum HTTP handlers - ├── templates.rs # HTML template rendering - ├── collab.rs # WebSocket collaboration server - ├── tags_ws.rs # WebSocket tag updates - ├── assets.rs # rust-embed static asset serving - ├── content_mode.rs # Content type detection - └── markdown.rs # Markdown rendering +└── lib.rs # Library exports, node bootstrap + +crates/ # The workspace crates the facade composes +├── id-cli/ # Clap argument definitions, command implementations, +│ # REPL, server config +├── id-core/ # Core types and abuse/budget policy +├── id-store/ # Blob/content store, metadata tags (alpha/omega dual-index) +├── id-events/ # Signed event store: ingest, chains, forks, range sync +├── id-sync/ # Peer sync +├── id-web/ # Web UI server (routes, collab, tags WS, world bridge, +│ # security layer) +├── id-worlds/ # Worlds: sessions, journal, runtime +├── id-caps/ # Capability surface and the MCP bridge +├── id-groups/ # Groups +├── id-directory/ # Directory +├── id-config/ # Configuration +├── id-currency-registry/ # Currency registry +├── id-render/ # Rendering +├── id-native-shell/ # Native shell +├── id-hw-shell/ # Hardware shell +└── id-import-notion/ # Notion importer web/ # TypeScript frontend -├── src/ # ProseMirror editor, collab, themes, editor features +├── src/ # ProseMirror editor, collab, themes, editor features, +│ # world surface └── dist/ # Built assets (embedded in binary) -e2e/ # Playwright E2E tests (104 tests × 2 browsers = 208) -├── tests/basic.spec.ts # 19 UI fundamental tests -├── tests/editor-features.spec.ts # 31 editor feature tests -├── tests/file-operations.spec.ts # 18 file/tag operation tests +e2e/ # Playwright E2E tests (138 tests × 2 browsers = 276) +├── tests/autosave.spec.ts # 7 autosave tests +├── tests/basic.spec.ts # 20 UI fundamental tests +├── tests/editor-features.spec.ts # 47 editor feature tests +├── tests/file-operations.spec.ts # 20 file/tag operation tests ├── tests/navigation.spec.ts # 17 navigation + SPA tests -├── tests/websocket.spec.ts # 19 WS + collaboration tests +├── tests/websocket.spec.ts # 22 WS + collaboration tests +├── tests/world-surface.spec.ts # 5 world surface tests └── playwright.config.ts # 3-mode config: local / nix sandbox / VM test nix/tests/ # NixOS VM integration tests ├── serve-test.nix # HTTP API test (curl, ~15 assertions) ├── e2e-test.nix # Chromium --dump-dom DOM test (~10 assertions) ├── integration-test.nix # Full cli_integration suite including serve_tests -└── playwright-e2e-test.nix # 4-VM full Playwright (208 interactive tests) +└── playwright-e2e-test.nix # 4-VM full Playwright (276 interactive tests) tests/ └── cli_integration.rs # ~93 integration tests diff --git a/pkgs/id/WEB.md b/pkgs/id/WEB.md index f62f16ff7d..05a3ccf906 100644 --- a/pkgs/id/WEB.md +++ b/pkgs/id/WEB.md @@ -55,8 +55,8 @@ Open http://localhost:3000 in your browser (default port). │ │ └───────────┘ └───────────┘ │ │ ▼ │ │ Embedded Assets (rust-embed) │ -│ - CSS: main.css (DaisyUI + Tailwind v4) │ -│ - JS: main.js (bundled with Bun) │ +│ - CSS: styles..css (DaisyUI + Tailwind v4) │ +│ - JS: main..js (bundled with Bun) │ └─────────────────────────────────────────────────────────────┘ ``` @@ -101,27 +101,45 @@ web/ │ ├── goto-line.ts # Go-to-line dialog (Ctrl+G) │ ├── indent.ts # Tab indentation (2-space) │ ├── active-line.ts # Active line highlight plugin -│ └── wrap.ts # Word wrap toggle (Alt+Z) -└── dist/ # Built assets (embedded in binary) - -src/web/ -├── mod.rs # Module exports, AppState -├── routes.rs # Axum route handlers (file CRUD, tags, rename, copy) +│ ├── wrap.ts # Word wrap toggle (Alt+Z) +│ ├── home.ts # Home page (world list, tagged documents, global chat) +│ ├── navigation.ts # SPA navigation +│ ├── world.ts # World surface (bridge client, forms, records) +│ ├── world-*.ts # World helpers (http, keyboard, seed, surface) +│ └── *.test.ts # Unit tests alongside the modules they cover +└── dist/ # Built assets (embedded in binary; contents git-ignored, + # the directory itself is tracked with a .gitkeep) + +crates/id-web/src/ +├── lib.rs # Router construction (Explorer, per-app, program-only) +├── routes.rs, routes/ # Axum route handlers (file CRUD, tags, rename, copy) +├── security.rs # Host allow-list, Origin check, token gate (every route) ├── collab.rs # WebSocket collaboration server ├── tags_ws.rs # WebSocket tag change broadcast +├── world_ws.rs # World session bridge WebSocket ├── templates.rs # HTML template rendering ├── assets.rs # rust-embed static serving ├── content_mode.rs # Content type detection -└── markdown.rs # Markdown rendering with syntax highlighting +├── markdown.rs, markdown/ # Markdown rendering with syntax highlighting +├── home.rs # Home page and feed +├── explore.rs # Script-free directory explorer (/explore) +├── gallery.rs # Program gallery routes +├── groups.rs # Groups page +├── identity.rs # Web client identity routes +├── seitan.rs # Seitan admission (invite / admit) +├── transport_ad.rs # Transport advertisement document +└── app_interface.rs # Per-app interface surface e2e/ ├── playwright.config.ts # 3-mode config: local / nix sandbox / VM test └── tests/ - ├── basic.spec.ts # 19 UI fundamental tests - ├── editor-features.spec.ts # 31 editor feature tests (syntax, lines, wrap, search, etc.) - ├── file-operations.spec.ts # 18 tag CRUD, rename, copy, delete, search, theme tests + ├── autosave.spec.ts # 7 autosave tests + ├── basic.spec.ts # 20 UI fundamental tests + ├── editor-features.spec.ts # 47 editor feature tests (syntax, lines, wrap, search, etc.) + ├── file-operations.spec.ts # 20 tag CRUD, rename, copy, delete, search, theme tests ├── navigation.spec.ts # 17 settings, peers, SPA nav, browser history tests - └── websocket.spec.ts # 19 WS + collaboration tests + ├── websocket.spec.ts # 22 WS + collaboration tests + └── world-surface.spec.ts # 5 world surface tests ``` ### Justfile Commands @@ -137,6 +155,23 @@ just test-e2e-firefox # Run Playwright tests (firefox only) just test-e2e-report # Show Playwright HTML report ``` +## Security Layer + +Every router is wrapped by the security layer (`crates/id-web/src/security.rs`), +which applies to every route below, in this order: + +1. **Bind**: loopback by default (`--bind` defaults to `127.0.0.1`). +2. **Host allow-list**: on loopback binds, the request `Host` must be + `localhost`, `127.0.0.1` or `::1`, plus any operator-configured extras. +3. **Origin check**: any request carrying an `Origin` header must be + same-origin (scheme, host and port must match). +4. **Token gate**: when a token is configured (`--web-token` or the + `ID_WEB_TOKEN` environment variable), it is accepted as the `id_token` + cookie, an `Authorization: Bearer` header, or a `?token=` query parameter + (the query form sets the cookie and redirects to the clean path). When no + token is configured this gate is open, and `id serve` prints a warning at + startup when a web listener is bound without `--web-token`. + ## Pages ### File List (Home) @@ -209,10 +244,10 @@ Tags are key-value pairs attached to files. The web UI provides: The `/ws/tags` endpoint broadcasts `TagEvent` messages (JSON) when tags change: ```json -{"type": "Set", "ns": "global", "subject": "readme.md", "key": "author", "value": "Jane"} -{"type": "Del", "ns": "global", "subject": "readme.md", "key": "author"} -{"type": "DelAll", "ns": "global", "subject": "readme.md"} -{"type": "Transfer", "ns": "global", "from_subject": "old.md", "to_subject": "new.md"} +{"type": "set", "ns": "global", "subject": "readme.md", "key": "author", "value": "Jane"} +{"type": "del", "ns": "global", "subject": "readme.md", "key": "author"} +{"type": "del_all", "ns": "global", "subject": "readme.md"} +{"type": "transfer", "ns": "global", "from": "old.md", "to": "new.md", "count": 3} ``` ## Themes @@ -236,31 +271,92 @@ Three DaisyUI terminal-inspired themes with `#000000` black backgrounds. Switch ## API Routes +The main router registers 54 paths with 58 method bindings; a second, +program-only router (one listener pinned to one world) registers 10 more. + +### Pages + +| Route | Method | Description | +| --------------------------------------- | ------ | --------------------------------------------------------- | +| `/` | GET | Index / home: world list, tagged documents, global chat | +| `/.well-known/id-transport-advertisement` | GET | Transport advertisement document | +| `/files` | GET | File browser page | +| `/world` | GET | World page (the hosted world's adapter surface) | +| `/settings` | GET | Settings page | +| `/peers` | GET | Discovered peers (auto-refreshes) | +| `/blocks` | GET | Operator block-list page | +| `/groups` | GET | Groups page | +| `/edit/{*name}` | GET | Editor/viewer for a file by name (wildcard) | +| `/hash/{hash}` | GET | Redirect from a content hash to its named file | +| `/view/{*name}` | GET | Read-only view of a file by name | +| `/blob/{hash}` | GET | Raw blob content with Content-Type | + +### HTTP API and partials + +| Route | Method | Description | +| ----------------------- | ------------- | --------------------------------------------------------- | +| `/api/files` | GET | File list (HTML partial) | +| `/api/home/feed` | GET | Home feed partial | +| `/api/peers` | GET | Peers partial | +| `/api/blocks` | GET, POST | List blocks / create a block | +| `/api/blocks/remove` | POST | Remove a block | +| `/api/save` | POST | Save file content | +| `/api/new` | POST | Create new file | +| `/api/rename` | POST | Rename file (with optional archive) | +| `/api/copy` | POST | Copy file to new name | +| `/api/files/send` | POST | Send file to another server (server-side transfer, #5346) | +| `/api/download` | POST | Download file content | +| `/api/delete` | POST | Soft-delete file | +| `/api/restore` | POST | Restore deleted file (404 if missing, 409 if not deleted) | +| `/api/hard-delete` | POST | Permanently delete file | +| `/api/upload` | POST | Image upload (multipart, route-scoped body limit) | +| `/api/images` | GET | Image listing, paged | +| `/api/tags` | GET | Get tags for a file | +| `/api/tags` | POST | Set a tag | +| `/api/tags` | DELETE | Delete a tag | +| `/api/tags/search` | GET | Search tags | +| `/api/identity/register` | POST | Register a web client identity | +| `/api/identity/me` | GET | The current identity | +| `/api/identity/name` | POST | Update the identity display name | +| `/api/seitan/invite` | POST | Seitan admission: create an invite | +| `/api/seitan/admit` | POST | Seitan admission: admit with an invite | +| `/assets/{*path}` | GET | Static assets | + +### World bridge + +| Route | Method | Description | +| ----------------------- | --------- | --------------------------------------------------------- | +| `/api/world/invite` | POST | Mint a world guest invite | +| `/api/world/host-view` | GET | Host view: snapshot, surface, and paged records | +| `/api/world/metrics` | GET | World host metrics | +| `/api/world/directory` | GET, POST | Directory read / signed directory write action | +| `/explore` | GET | Script-free HTML directory explorer (forms only) | +| `/explore/login` | POST | Explorer login (admin token for the `id_explore` cookie) | +| `/explore/act` | POST | Explorer directory action | +| `/invite` | GET | Invite landing page | +| `/ws/world` | WS | World session bridge (default socket path) | + +### Program gallery + +Every gallery route answers 404 unless a gallery was wired in with +`--gallery-dir` or `ID_GALLERY_DIR`. + +| Route | Method | Description | +| ------------------------------------- | ------ | ---------------------------------------------------- | +| `/api/gallery/records` | GET | Signed bundle records list | +| `/api/gallery/bundles/{content_hash}` | GET | Bundle bytes, immutable cache | +| `/api/gallery/search` | GET | Search bundles | +| `/api/gallery/authors/{author}` | GET | Author page by key | +| `/api/gallery/collections` | GET | Operator-signed featured collections | +| `/api/gallery/collections/{operator}/{name}` | GET | One collection | +| `/api/gallery/transparency` | GET | Removals, refusals and reinstatements | + +### WebSocket + | Route | Method | Description | | --------------------- | ------ | --------------------------------------------------------- | -| `/` | GET | File browser (main page) | -| `/peers` | GET | Discovered peers (auto-refreshes) | -| `/settings` | GET | Settings page | -| `/edit/{hash}` | GET | Editor/viewer for file by hash | -| `/file/{name}` | GET | Editor/viewer for file by name | -| `/blob/{hash}` | GET | Raw blob content with Content-Type | -| `/api/files` | GET | File list (HTML partial) | -| `/api/save` | POST | Save file content | -| `/api/new` | POST | Create new file | -| `/api/rename` | POST | Rename file (with optional archive) | -| `/api/copy` | POST | Copy file to new name | -| `/api/files/send` | POST | Send file to another server (server-side transfer, #5346) | -| `/api/download` | POST | Download file content | -| `/api/delete` | POST | Soft-delete file | -| `/api/restore` | POST | Restore deleted file (404 if missing, 409 if not deleted) | -| `/api/hard-delete` | POST | Permanently delete file | -| `/api/tags` | GET | Get tags for a file | -| `/api/tags` | POST | Set a tag | -| `/api/tags` | DELETE | Delete a tag | -| `/api/tags/search` | GET | Search tags | | `/ws/collab/{doc_id}` | WS | Collaboration WebSocket | | `/ws/tags` | WS | Tag change broadcast | -| `/assets/*` | GET | Static assets | ## Configuration @@ -293,12 +389,12 @@ just test-unit ### E2E Tests -Playwright tests run against both Chromium and Firefox (104 tests × 2 browsers = 208 total): +Playwright tests run against both Chromium and Firefox (138 tests × 2 browsers = 276 total): ```bash -just test-e2e # Both browsers (208 tests) -just test-e2e-chromium # Chromium only (104 tests) -just test-e2e-firefox # Firefox only (104 tests) +just test-e2e # Both browsers (276 tests) +just test-e2e-chromium # Chromium only (138 tests) +just test-e2e-firefox # Firefox only (138 tests) ``` Tests cover: home page elements, file creation, editor features (syntax highlighting, line numbers, word wrap, find/replace, go-to-line, active line, tab indentation), navigation, themes, WebSocket connection/disconnect/reconnect, collaborative editing, multi-user scenarios, tag CRUD, file rename/copy/delete, search filtering. diff --git a/pkgs/id/crates/id-caps/src/mcp_bridge.rs b/pkgs/id/crates/id-caps/src/mcp_bridge.rs index 293ad49b41..7225ae7d12 100644 --- a/pkgs/id/crates/id-caps/src/mcp_bridge.rs +++ b/pkgs/id/crates/id-caps/src/mcp_bridge.rs @@ -46,6 +46,12 @@ impl ToolDefinition { } /// The eight approved v1 MCP tools, in their pinned wire order. +/// +/// One entry is pinned but can never succeed: `presence.set` is refused +/// unconditionally by [`BridgeSession::tool_action`] with +/// [`BridgeError::NoFrameMapping`], because presence is the join itself +/// and no presence frame exists. A v1 client must treat `presence.set` +/// as a tool that always fails. #[must_use] pub fn v1_tool_definitions() -> Vec { vec![ diff --git a/pkgs/id/crates/id-cli/src/server_config/mod.rs b/pkgs/id/crates/id-cli/src/server_config/mod.rs index 840ef945c0..435869acc9 100644 --- a/pkgs/id/crates/id-cli/src/server_config/mod.rs +++ b/pkgs/id/crates/id-cli/src/server_config/mod.rs @@ -33,8 +33,10 @@ //! # from there via `id_events::event_store::BlockList`) //! //! [budgets] # absent: the #2247 code defaults apply +//! app_inbound_bytes_per_second = 33554432 # 32 MiB/s app-wide inbound //! app_inbound_bytes_per_hour = 21474836480 # 20 GiB/h app-wide inbound //! per_peer_bytes_per_hour = 104857600 # 100 MiB/h per peer +//! per_peer_burst_bytes_per_minute = 8388608 # 8 MiB/min per-peer burst window //! per_ip_bytes_per_hour = 262144000 # 250 MiB/h per directly observed IP //! //! [[budgets.counterparty]] # an override row for one specific peer; diff --git a/pkgs/id/hosted-worker/README.md b/pkgs/id/hosted-worker/README.md index be6a54a30b..f2b10de084 100644 --- a/pkgs/id/hosted-worker/README.md +++ b/pkgs/id/hosted-worker/README.md @@ -19,10 +19,19 @@ First local-only vertical slice of the hosted data plane (slice 3 of routed request binds the object immutably to its (binding_id, jurisdiction); a common guard runs before every read or write and fails closed on unrouted requests, identity mismatch, or a - runtime-reported jurisdiction mismatch. Routes: `GET /v1/state`, - `PUT|GET /v1/kv/` (a minimal per-user store proving lazy - creation and isolation; R2 blobs, metering and caps are later - #3811 steps and are out of scope here). + runtime-reported jurisdiction mismatch. Routes (13 paths, + 15 method routes): `GET /v1/state`; `GET /v1/usage` (usage, + ceiling, and `at_cap`); `GET /v1/export` (full KV plus blob index; + stays available at cap); `PUT|GET|DELETE /v1/kv/` (per-user + store; the key must match `[A-Za-z0-9._-]{1,128}`); `PUT /v1/blobs`, + `GET|DELETE /v1/blobs/<64-hex>` (content-addressed blobs in R2, + deduplicated across users; DELETE drops only this user's + reference); and the signed-object bridge routes (`GET + /v1/bridge/challenge`, `GET /v1/bridge/heads`, `POST + /v1/bridge/push`, `POST /v1/bridge/pull`, `GET /v1/bridge/export`, + `GET /v1/bridge/ws`), covered in the bridge section below. Storage + metering and the per-user ceiling (`USER_CEILING_BYTES`) are + implemented, not later steps. ## Local reality check (verified 2026-11-03, wrangler dev / workerd) diff --git a/pkgs/id/web/README.md b/pkgs/id/web/README.md index 904ab08ccc..03d9cbec35 100644 --- a/pkgs/id/web/README.md +++ b/pkgs/id/web/README.md @@ -21,15 +21,24 @@ All messages are encoded as MessagePack arrays with a type tag as the first elem ### Message Types -| Tag | Name | Direction | Format | -| --- | ------ | -------------- | ----------------------------------------------- | -| 0 | Init | Server->Client | `[0, version, doc]` | -| 1 | Steps | Client->Server | `[1, version, steps, clientID]` | -| 2 | Update | Server->Client | `[2, steps, clientIDs]` | -| 3 | Ack | Server->Client | `[3, version]` | -| 4 | Cursor | Bidirectional | `[4, clientID, head, anchor, name?, idleSecs?]` | -| 5 | Error | Server->Client | `[5, errorMessage]` | -| - | Empty | Bidirectional | `""` (empty text, see below) | +| Tag | Name | Direction | Format | +| --- | ------------ | -------------- | ----------------------------------------------- | +| 0 | Init | Server->Client | `[0, version, doc, mode]` | +| 1 | Steps | Client->Server | `[1, version, steps, clientID]` | +| 2 | Update | Server->Client | `[2, steps, clientIDs]` | +| 3 | Ack | Server->Client | `[3, version]` | +| 4 | Cursor | Bidirectional | `[4, clientID, head, anchor, name?, idleSecs?]` | +| 5 | Error | Server->Client | `[5, errorMessage]` | +| 6 | CursorRemove | Server->Client | `[6, clientID]` | +| 7 | NewVersion | Server->Client | `[7, hash, name]` | +| 8 | Auth | Client->Server | `[8, token]` (first message after connect) | +| 9 | AuthOk | Server->Client | `[9, client_id, name, token?]` | +| 10 | Checkpoint | Client->Server | `[10, text]` (note sessions only) | +| 11 | Checkpointed | Server->Client | `[11, head]` (hex of the new note head) | +| - | Empty | Bidirectional | `""` (empty text, see below) | + +A legacy Init frame without the `mode` field still decodes; `mode` +defaults to `raw`. ### Field Types @@ -45,7 +54,7 @@ All messages are encoded as MessagePack arrays with a type tag as the first elem ### Connection Flow -1. Client connects to `/ws/collab/{file_path}` +1. Client connects to `/ws/collab/{doc_id}` 2. Server sends `Init` with current version and document 3. Client initializes ProseMirror with received version 4. Client sends `Steps` when user edits @@ -55,7 +64,7 @@ All messages are encoded as MessagePack arrays with a type tag as the first elem ### Empty Text Messages -WebSocket Ping control frames are handled silently by browsers and don't trigger JavaScript's `onmessage`. To allow cursor decoration refresh in inactive tabs (where `setInterval` is throttled), the server sends empty text messages (`""`) every 60 seconds instead of Ping frames. +WebSocket Ping control frames are handled silently by browsers and don't trigger JavaScript's `onmessage`. To allow cursor decoration refresh in inactive tabs (where `setInterval` is throttled), the server sends a Ping frame on each 30-second idle cycle, and every 2nd cycle's Ping is replaced by an empty text message (`""`). Clients must therefore handle both Ping frames and empty text frames on the same socket. When the client receives an empty text message, it: @@ -131,8 +140,8 @@ Cursor behavior changes based on WebSocket connection state: ### Timeouts -- **Ping/Pong**: Server pings after 30s of inactivity; any message resets timer -- **WebSocket**: Server closes connection after 30m of no activity +- **Ping/Pong**: Server sends a Ping after 30s of inactivity (every 2nd cycle's Ping is replaced by an empty text message); any message resets timer +- **WebSocket**: Server closes connection after 30m without a pong or message - **Cursor**: Server removes cursor 5m after WebSocket closes - **Document**: Server cleans up document 1h after no connections @@ -176,8 +185,13 @@ web/ │ ├── goto-line.ts # Go-to-line dialog (Ctrl+G) │ ├── indent.ts # Tab indentation (2-space) │ ├── active-line.ts # Active line highlight plugin -│ └── wrap.ts # Word wrap toggle (Alt+Z) -├── dist/ # Built output (git-ignored) +│ ├── wrap.ts # Word wrap toggle (Alt+Z) +│ ├── home.ts # Home page (world list, tagged documents, global chat) +│ ├── navigation.ts # SPA navigation +│ ├── world.ts # World surface (bridge client, forms, records) +│ ├── world-*.ts # World helpers (http, keyboard, seed, surface) +│ └── *.test.ts # Unit tests alongside the modules they cover +├── dist/ # Built output (contents git-ignored; the directory itself is tracked with a .gitkeep) ├── bun.nix # Offline npm dependency fetching for nix sandbox └── package.json ``` @@ -283,18 +297,18 @@ The `/ws/tags` endpoint provides real-time tag change notifications. Clients rec ### Event Types ```json -{"type": "Set", "ns": "global", "subject": "readme.md", "key": "author", "value": "Jane"} -{"type": "Del", "ns": "global", "subject": "readme.md", "key": "author"} -{"type": "DelAll", "ns": "global", "subject": "readme.md"} -{"type": "Transfer", "ns": "global", "from_subject": "old.md", "to_subject": "new.md"} +{"type": "set", "ns": "global", "subject": "readme.md", "key": "author", "value": "Jane"} +{"type": "del", "ns": "global", "subject": "readme.md", "key": "author"} +{"type": "del_all", "ns": "global", "subject": "readme.md"} +{"type": "transfer", "ns": "global", "from": "old.md", "to": "new.md", "count": 3} ``` | Event | Description | | ---------- | ------------------------------------------- | -| `Set` | A tag was added or updated | -| `Del` | A specific tag was removed | -| `DelAll` | All tags were removed from a subject | -| `Transfer` | Tags were moved from one subject to another | +| `set` | A tag was added or updated | +| `del` | A specific tag was removed | +| `del_all` | All tags were removed from a subject | +| `transfer` | Tags were moved from one subject to another | The `value` field is omitted from `Set` events when the tag has no value (key-only tags). The `ns` field indicates the namespace (`global` for the default namespace).