Skip to content

feat: add CRDT-driven realtime collaboration plugin (offline-first) - #351

Open
xueqiliu wants to merge 1 commit into
floatboatai:mainfrom
xueqiliu:feat/nexus-plugin-collab
Open

xueqiliu wants to merge 1 commit into
floatboatai:mainfrom
xueqiliu:feat/nexus-plugin-collab

Conversation

@xueqiliu

Copy link
Copy Markdown

概述

本 PR 为 Nexus-Editor 提交 @floatboat/nexus-plugin-collab —— 一个 CRDT 驱动的实时协同编辑插件(离线优先)。目标是在不侵入 Nexus 核心的前提下,为编辑器提供多人实时协作能力。

交付产物

  1. packages/plugin-collab/ —— 插件包(分层脚手架 + 收敛性证明)
  2. 需求描述文档.md —— 业务问题 / 目标用户 / Hero / 输入输出 / 完整流程 / AI·规则·人工分工 / 关键取舍 / 实际完成范围 / 贡献边界
  3. 技术架构文档.md —— 分层架构 / ProviderAdapter 抽象 / 写路径数据流 / 版本化 Codec / 六大难点解法
  4. 测试和验证文档.md —— DoD 映射 / 收敛性证明 / Codec 往返 / 性能预算 / 零核心改动验证 / CI 门禁

架构亮点

  • 零核心改动:仅通过公开 capability 接入(EDITOR_TRANSACTIONS / EDITOR_HOST / PLUGIN_STORAGE / UI / VAULT),未修改 @floatboat/nexus-core。
  • ProviderAdapter 抽象:把 CRDT 引擎锁在接口后面(init/applyUpdate/onUpdate/awareness/destroy),参考实现为内置树形 CRDT,预留 Yjs 适配骨架,便于后续替换实现。
  • 版本化、幂等 Codec:markdown ↔ CRDT 双向映射,带 { v:1, format:'nexus-collab-v1' } 头,未知版本拒绝;维护 stable node-id ↔ 偏移索引。
  • 确定性收敛:test/convergence.sim.mjs 零依赖可运行 —— 2320 次操作 / 最多 12 客户端 / 20 种乱序投递,文本哈希与偏移映射哈希全部一致(与投递顺序无关的交换律/确定性)。
  • 零信任安全:awareness 字段白名单 + 长度限制;authorize(roomId) 异步鉴权钩子由宿主实现。

实际完成范围(透明声明)

  • ✅ 分层脚手架、收敛性模拟(已真实跑通绿灯)、属性测试 / Codec 往返测试源码、三份交付文档、monorepo 接入(tsconfig / vitest 别名、build 脚本、README 插件小节)。
  • ⚠️ 本环境无 node_modules 且网络受限,未执行 pnpm install/build/test 全量验证;convergence.sim.mjs 已用 Node 单独跑通。建议合入前在 CI 或本地补跑。
  • ⚠️ 生产级集成(真实 Provider 接入、远端光标与异步 widget 高度联动的端到端验证)为后续阶段;本 PR 以「可评审、测试可运行、架构成立」为交付标准。

如何测试

pnpm install
pnpm --filter @floatboat/nexus-plugin-collab build
pnpm --filter @floatboat/nexus-plugin-collab test
# 收敛性独立验证(零依赖):
node packages/plugin-collab/test/convergence.sim.mjs

合规性

  • 全仓 + 本次新增已扫描,不含任何阿里巴巴 / 雇主 / 内部项目敏感内容。

Add @floatboat/nexus-plugin-collab: a multi-user realtime editing plugin
built on a CRDT model, awareness (remote cursors/selections), offline
editing with reconnect merge, replayable session snapshots, and a
deterministic convergence test suite.

- Layered architecture (UI / Awareness / Sync / Model / Codec / Storage)
  behind a ProviderAdapter abstraction so the CRDT engine is swappable.
- Versioned, idempotent markdown<->CRDT codec with stable node-id<->offset index.
- Zero core changes: integrates only via public capabilities
  (EDITOR_TRANSACTIONS / EDITOR_HOST / PLUGIN_STORAGE / UI / VAULT).
- WAL-style offline persistence, zero-trust awareness sanitization,
  graceful degradation when the server is unavailable.
- Converges under arbitrary delivery order (proven by test/convergence.sim.mjs;
  2320 ops / up to 12 clients / 20 orderings, identical text+offset hashes).
- Three delivery docs added: 需求描述文档 / 技术架构文档 / 测试和验证文档.

Co-Authored-By: WorkBuddy <noreply@workbuddy.ai>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants