본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)7.6k · #13174

real-time-collab

하는 일

이 스킬은 Yjs와 TipTap을 써서 편집 내용이 깔끔하게 병합되는 실시간 공동 편집을 만드는 방법을 설명합니다. 공유 문서를 추가하거나 동기화 문제를 디버깅하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓앱의 문서에 실시간 공동 편집을 추가할 때.
  • ✓두 사람이나 에이전트가 같은 문서를 편집해서 변경이 사라질 때.
  • ✓사용자와 에이전트 사이의 동기화 문제를 디버깅해야 할 때.

스킬 링크

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/real-time-collab/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/real-time-collab/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“두 사람이 같은 문서를 동시에 편집하게 하고, AI의 편집도 두 사람 모두에게 보이게 해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

편집 내용은 변경을 자동으로 병합하는 공유 문서로 저장됩니다. 업데이트는 사용자에게 푸시되며, 실시간 연결이 끊기면 몇 초마다 확인하는 방식으로 대체됩니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Real-Time Collaboration

Rule

Collaborative editing uses Yjs CRDT via TipTap. The agent and human users are equal participants — both edit the same Y.Doc and changes merge cleanly without conflicts. Always choose an explicit access mode on createCollabPlugin.

How It Works

  • Y.Doc stores the document as a Y.XmlFragment (ProseMirror node tree)
  • TipTap's Collaboration extension binds the editor to the Y.XmlFragment via ySyncPlugin
  • CollaborationCaret extension renders remote users' cursors with names and colors
  • SSE fast-path — /_agent-native/poll-events EventSource delivers collab events push-style; while SSE is healthy the collab poll interval relaxes to ~12 s
  • Polling fallback — /_agent-native/poll is polled every 2 s when SSE drops mid-session. On serverless, /events answers 204 up front (poll-live) and this client relaxes to ~12 s, because /poll is the only channel.
  • Collab poll boost — while the awareness set shows another visible human on the doc (agent and hidden tabs do not count), the connection holds acquireCollabPollBoost() and the shared transport polls every 2.5 s whenever no stream is connected: a no-op while SSE or the hosted gateway is live. A joiner is noticed on the existing user's next ~12 s collab poll (the joiner sees them at once), a leaver within one poll plus the 30 s awareness TTL. The boost lapses after 3 minutes with no input and no remote events. Lone tabs pay nothing extra. Events under the request source a connection posts with (any app-chosen tab id, not only getBrowserTabId()) are this tab's own and never count. A read-only viewer must join the doc too (Design's useViewerPresence; it never uses the ydoc), or it never sees an editor and stays on the idle cadence. A viewer on a different screen than the editor shares no doc with them; its own collab poll sees the design's resource-scoped events from other tabs and starts the boost (60 s) itself.
  • Update batching — local Yjs updates are debounced ~80 ms and coalesced with Y.mergeUpdates before sending; flushed immediately on visibilitychange / pagehide
  • SQL _collab_docs table persists Yjs state as base64 in Postgres. Tombstone compaction fires automatically when the stored blob exceeds 4× the fresh encoded size.

Agent + Human Editing

  1. Human edits → TipTap → ySyncPlugin → Y.XmlFragment → POST /_agent-native/collab/:docId/update
  2. Agent edits → action edits canonical SQL content + bumps updatedAt → change-sync refetch → the open editor reconciles the new content into the live Y.Doc (see below) → poll update → all clients

Both produce Yjs operations that merge cleanly. Agent edits appear without destroying cursor position, selection, or undo history.

The agent does not push edits into Yjs in-process and does not call any localhost probe — those approaches silently no-op on serverless (the action runs in a different process). The peer-editor model below replaced them.

Agent Edits As A Real-Time Peer Editor

SQL is the durable source of truth for document body content. The agent action edits the canonical content column and bumps updatedAt. No localhost calls, no in-process Yjs mutation.

The open editor reconciles authoritative external content into the live Y.Doc. The updatedAt bump flows through change-sync, which refetches the record. The lead client applies the new content via setContent, producing Yjs operations that merge with concurrent human edits. Every connected client receives the result through normal Yjs sync.

The updatedAt gate

// In the editor's reconcile effect
if (loaded.updatedAt > lastAppliedUpdatedAt.current) {
  applyAuthoritativeContent(loaded.content); // adopt
  lastAppliedUpdatedAt.current = loaded.updatedAt;
}
// else: lagging poll / stale snapshot → ignore

Without the gate, a slightly-behind poll response re-applies old content and the edit "reverts on next poll". A fresh mount always adopts whatever content it loaded.

Lead-client election

Exactly ONE connected client applies the authoritative snapshot; the rest receive it through Yjs sync:

import { isReconcileLeadClient } from "@agent-native/core/client/collab";

if (
  loaded.updatedAt > lastAppliedUpdatedAt.current &&
  isReconcileLeadClient(awareness, ydoc.clientID)
) {
  applyAuthoritativeContent(loaded.content);
}

The agent's awareness entry (`AGENT

자주 묻는 질문

에이전트와 사람이 함께 편집할 수 있나요?

네. 이 스킬은 에이전트와 사람 사용자를 같은 문서의 동등한 참여자로 취급합니다.

다른 사용자의 커서는 어떻게 표시되나요?

커서 확장 기능이 원격 사용자의 커서를 이름과 색상과 함께 표시합니다.

실시간 연결이 끊기면 어떻게 되나요?

앱은 몇 초마다 서버를 확인하는 폴링 방식으로 돌아갑니다.

상세 정보

작성자의 원본 설명

Multi-user collaborative editing with Yjs CRDT, SSE fast-path transport, and granular server-side merge. Use when adding real-time collaborative editing to a template, debugging sync issues, or understanding how the agent and humans edit documents simultaneously.

repo: BuilderIO/agent-native

인기도

GitHub 스타
7.6k
순위
#13174
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬