Skip to main content
Glama
README.md
# Doco

> πŸ“– [δΈ­ζ–‡η‰ˆ](README.zh-CN.md)

**The document space where humans and AI agents write together.** An open-source rich-text
collaborative editor that puts your data back in your hands β€” and treats your AI agents with
the same care: block-level stable addressing, optimistic concurrency control, and a 29-tool
MCP server, so agents read and write your knowledge base as safely as a careful human editor.

- **Hosted:** [doco.page](https://doco.page/) β€” free during beta
- **Connect your agent:** `claude mcp add doco -- npx -y --package doco-agent-cli doco mcp`
- **CLI:** `npm i -g doco-agent-cli && doco login`
- **npm:** [doco-agent-cli](https://www.npmjs.com/package/doco-agent-cli) Β· **API docs:** [doco.page/api-docs](https://doco.page/api-docs/)

### Claude Code Plugin Marketplace

```text
/plugin marketplace add songofhawk/doco
/plugin install doco@doco
```

The marketplace bundles the Doco MCP server and the safe read β†’ version β†’ protected-write
operating protocol. Tokens remain in Claude Code's local configuration and are never included
in the plugin repository.

![Doco editor showing a live block-level Agent update in an English demo document](docs/assets/readme/product-editor-en.png)

## Why agents are safe here

| Capability | What it means |
|---|---|
| Block-level stable addressing | Every paragraph has a `block_<ULID>` id β€” position-independent, survives drags and folds |
| Optimistic concurrency | Reads return a `sha256` version; writes require `If-Match`; on 409 the agent re-reads, merges, retries β€” blind overwrites are impossible |
| Markdown round-trip | Export with `?annotate=anchors`; write the whole document back and block ids are preserved |
| Human–agent co-editing | Agent writes flow through the same Yjs document β€” changes appear live in the browser |
| Transactions & idempotency | Batch operations commit atomically; `Idempotency-Key` makes retries side-effect-free |

## Features

### Editing Experience

- **Rich text editing**: headings, lists, blockquotes, task lists, code blocks (syntax highlighting), tables, images, links, text styling, and more
- **`/` slash command**: type `/` to open the command palette with fuzzy search β€” supports pinyin abbreviations for Chinese users
- **Floating toolbar**: auto-appears on text selection, all formatting actions within two centimeters of your cursor
- **Block drag-and-drop**: hover the left edge of any paragraph to reveal a drag handle β€” reorder content like building blocks
- **Collapsible sections**: fold away sections you're not working on; collapse state persists across sessions
- **Auto heading numbering**: one-click toggle β€” H1–H4 headings automatically maintain hierarchical numbering (`1.` `1.1` `1.1.1`)
- **Keyboard shortcuts**: `βŒ₯↑/↓` move blocks, `⌘D` duplicate blocks, `⌘βŒ₯1/2/3/0` switch heading levels

### Text-to-Diagram

Write Mermaid or PlantUML source code directly in your document. Diagrams render in place. Double-click to edit, fullscreen view, pinch-to-zoom β€” no more export-import-replace cycles with draw.io.

- **Mermaid**: flowcharts, sequence diagrams, class diagrams, Gantt charts, state diagrams, and more
- **PlantUML**: sequence diagrams, class diagrams, use case diagrams, component diagrams, and more

### Spreadsheet

A full spreadsheet engine embedded in your documents:
- Formula evaluation, cell formatting
- Freeze panes, sort & filter
- Cell merge / split
- CSV import / export

Use it inline as a content block, or pop it out as a standalone full-screen spreadsheet.

### Knowledge Base

- Knowledge Base β†’ Folders (nestable) β†’ Documents β€” a three-level structure
- Drag-and-drop reordering, renaming, and moving in the sidebar
- Whole-KB ZIP export preserving folder hierarchy, with bundled images
- Lossless native `.doco.zip` transfer for a document, folder, or whole knowledge base

### Real-time Collaboration

Built on the Yjs CRDT algorithm:
- No save button β€” changes sync automatically
- Offline-first: browser IndexedDB is the primary store; the server holds a snapshot. Edit without a network, merge automatically when reconnected
- Seamless device switching: close your laptop, pick up your phone, keep writing

### Import / Export

| Format | Import | Export |
|--------|--------|--------|
| Doco native package | βœ… Document / folder / KB | βœ… Lossless document / folder / KB |
| Markdown | βœ… Paste / file upload | βœ… Single doc & KB bundle |
| Word (DOCX) | βœ… | βœ… |
| PDF | βœ… | βœ… |
| HTML | βœ… | β€” |
| WeChat Official Account | β€” | βœ… (with theme preview) |
| Images (in-document) | βœ… (paste / drag-drop) | βœ… (bundled in ZIP) |

### API Β· MCP Β· CLI

Three channels, one contract:

- **REST API**: OpenAPI 3.1 spec, Bearer Token auth, ETag versioning, cursor pagination, idempotency keys
- **MCP server**: `doco mcp` (ships inside `doco-agent-cli`) β€” 29 tools plus `doco://` resources
- **doco CLI**: `login / whoami / docs / blocks / edit / mcp`, global `--json`, writes internalize ETag/If-Match

Turn your docs into programmable assets β€” script your own backups, let an agent organize your
knowledge base, pipe docs from your publishing workflow to your blog. Built-in API
documentation page, ready to use out of the box.

## Tech Stack

| Layer | Technology |
|---|---|
| Frontend Framework | React 18 + Vite + TypeScript |
| CSS | Tailwind CSS v4 |
| Editor | Tiptap v3 (ProseMirror) |
| Collaboration | Yjs (CRDT) + Hocuspocus |
| Diagrams | Mermaid + PlantUML |
| Backend | Node.js + Express + Hocuspocus Server |
| Database | better-sqlite3 (SQLite, WAL mode) |
| UI Components | Radix UI, Lucide React, Tippy.js |

## Quick Start

### Prerequisites

- Node.js >= 22
- pnpm

### Install & Run

```bash
# Install frontend dependencies
pnpm install

# Install backend dependencies
cd backend && npm install && cd ..

# Start the frontend dev server (Vite, default :5173)
pnpm run dev

# In another terminal, start the backend (Express + WebSocket, default :8000)
cd backend
npm run dev
```

Open `http://localhost:5173` β€” it will auto-connect to the backend WebSocket service.

## Docker Deployment (recommended)

The complete self-hosted package includes a Caddy frontend, Node.js collaboration backend, persistent SQLite storage, health checks, and a same-origin WebSocket proxy. The public images support both `linux/amd64` and `linux/arm64`.

```bash
git clone https://github.com/songofhawk/doco.git
cd doco
cp .env.docker.example .env.docker

# Review .env.docker first, then start with prebuilt Docker Hub images
docker compose --env-file .env.docker up -d

# Verify the deployment
docker compose --env-file .env.docker ps
curl --fail http://localhost:8080/healthz
```

Open `http://localhost:8080` by default. Set `ALLOWED_ORIGINS`, `COOKIE_SECURE`, Google OAuth, and SMTP values in `.env.docker` for your environment. These values are injected when the containers start and are not baked into the images. Application data is stored in the `doco-data` named volume.

Docker Hub: [`songofhawkg/doco-frontend`](https://hub.docker.com/r/songofhawkg/doco-frontend) Β· [`songofhawkg/doco-backend`](https://hub.docker.com/r/songofhawkg/doco-backend)

To build the same images from source instead:

```bash
docker compose --env-file .env.docker up -d --build
```

See the [Docker deployment guide](docs/Docker部署.md) for all configuration options, HTTPS, logs, backup, restore, and upgrades. Do not run `docker compose down -v` unless you intend to delete the database and attachments.

## Manual Build & Deployment

```bash
# Frontend build
pnpm run build          # output β†’ dist/
pnpm run deploy         # deploy to Cloudflare Pages

# Backend (production)
cd backend
npm start
```

## Project Structure

```
doco/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.tsx                      # App entry point
β”‚   β”œβ”€β”€ App.tsx                       # Root component, routing, import/export
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── Sidebar.tsx               # KB sidebar (document tree)
β”‚   └── editor/                       # Editor module
β”‚       β”œβ”€β”€ index.ts                  # Entry, exports DocoEditor component
β”‚       β”œβ”€β”€ DocoEditor.tsx            # Editor core (Yjs/Hocuspocus init, extension registration)
β”‚       β”œβ”€β”€ types.ts                  # DocoEditor Props/Ref type definitions
β”‚       └── components/
β”‚           β”œβ”€β”€ BubbleMenu.tsx        # Selection floating toolbar
β”‚           β”œβ”€β”€ BlockHandle.tsx       # Block drag handle
β”‚           β”œβ”€β”€ SlashCommand.ts       # / command palette
β”‚           β”œβ”€β”€ CommandList.tsx       # Command palette UI
β”‚           β”œβ”€β”€ suggestions.ts        # Command menu data
β”‚           β”œβ”€β”€ CollapseExtension.ts  # Block collapse extension
β”‚           β”œβ”€β”€ DocSettings.tsx       # Document settings (heading numbering, background)
β”‚           β”œβ”€β”€ MermaidBlock.ts       # Mermaid node definition
β”‚           β”œβ”€β”€ MermaidComponent.tsx  # Mermaid renderer
β”‚           β”œβ”€β”€ PlantUMLBlock.ts      # PlantUML node definition
β”‚           β”œβ”€β”€ PlantUMLComponent.tsx # PlantUML renderer
β”‚           β”œβ”€β”€ CalloutBlock.ts       # Callout block definition
β”‚           β”œβ”€β”€ CalloutComponent.tsx  # Callout renderer
β”‚           β”œβ”€β”€ SpreadsheetBlock.ts   # Spreadsheet node definition
β”‚           β”œβ”€β”€ SpreadsheetComponent.tsx  # Spreadsheet renderer
β”‚           β”œβ”€β”€ spreadsheetEngine.ts  # Spreadsheet calculation engine
β”‚           β”œβ”€β”€ WeChatExportDialog.tsx # WeChat Official Account export
β”‚           β”œβ”€β”€ KeyboardShortcuts.ts  # Keyboard shortcuts
β”‚           β”œβ”€β”€ TableOfContents.tsx   # Table of contents
β”‚           β”œβ”€β”€ CodeBlockComponent.tsx # Code block (highlight + copy)
β”‚           └── ImageComponent.tsx    # Image renderer
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ server.js                     # Entry: Express + Hocuspocus + export routes
β”‚   β”œβ”€β”€ database.js                   # better-sqlite3 init & schema
β”‚   β”œβ”€β”€ api.js                        # KB / folder / document REST API
β”‚   β”œβ”€β”€ auth.js                       # Auth (OAuth + Email + API Token)
β”‚   β”œβ”€β”€ markdown.js                   # YDoc β†’ Markdown server-side export
β”‚   β”œβ”€β”€ permissions.js                # Permission management
β”‚   β”œβ”€β”€ quota.js                      # Quota management
β”‚   β”œβ”€β”€ openapi.js                    # OpenAPI spec definition
β”‚   └── tests/                        # Backend tests
└── docs/                             # Design docs & proposals
```

## Standalone Frontend Component

The editor core is also published as [`doco-text-editor`](https://www.npmjs.com/package/doco-text-editor). It contains the full Doco editing experience and built-in styles, but has no dependency on Doco authentication, REST APIs, collaboration services, or IndexedDB. The host application decides whether content lives in memory, browser storage, its own backend, or an external system such as ClickUp.

```bash
npm install doco-text-editor
```

```tsx
import { useRef } from 'react'
import {
  DocoTextEditor,
  type DocoTextEditorRef,
} from 'doco-text-editor'
import 'doco-text-editor/style.css'

const editorRef = useRef<DocoTextEditorRef>(null)

<DocoTextEditor
  ref={editorRef}
  defaultValue="# Browser-only draft"
  format="markdown"
  onChange={({ steps }) => {
    // Only the ProseMirror steps changed by this transaction.
    queueIncrementalChanges(steps)
  }}
/>

// Read the complete document only when needed.
const json = editorRef.current?.getContent('tiptap-json')
const markdown = editorRef.current?.getContent('markdown')
const html = editorRef.current?.getContent('html')
const text = editorRef.current?.getContent('text')
```

The package includes headings, inline formatting, blockquotes, ordered/unordered/task lists, code blocks, images, tables, callouts, Mermaid, optional PlantUML rendering, and embedded spreadsheets. See [`src/editor/README.md`](src/editor/README.md) for the complete API and integration notes.

## Full Doco Editor Component Usage

```tsx
import { DocoEditor } from './editor'
import type { DocoEditorRef } from './editor/types'

const editorRef = useRef<DocoEditorRef>(null)

<DocoEditor
  ref={editorRef}
  docId="doc-001"
  userId="user-001"
  collaboration={{
    websocketUrl: 'ws://localhost:8000',
  }}
  onTitleChange={(docId, title) => console.log('Title changed:', title)}
  placeholder="Start writing…"
/>

{/* Call export methods via ref */}
<button onClick={() => editorRef.current?.exportMarkdown()}>Export MD</button>
```

## Collaboration Architecture

```
Browser IndexedDB (y-indexeddb)  ← local primary store
       ↕
Browser Y.Doc  ← @hocuspocus/provider (WebSocket)
       ↕  Yjs binary delta messages
Server @hocuspocus/server  β†’  SQLite ydoc_state (one merged snapshot per doc)
```

- The browser IndexedDB is the primary store; the server snapshot is auxiliary. If the server snapshot is lost, simply open the document in the browser to repopulate it.
- Offline editing works seamlessly; changes sync automatically when the network returns.
- Collaborative cursors: supported by the framework, not enabled by default.

## Markdown Export

Both single documents and KB bundles support Markdown export, generated on-the-fly from YDoc on the server:

```bash
# Single document export
curl http://localhost:8000/api/docs/{id}/export.md

# KB ZIP bundle
curl http://localhost:8000/api/kb/{id}/export.zip
```

Custom nodes (Mermaid, PlantUML, Callout, etc.) have corresponding serialization rules in `backend/markdown.js`. When adding new custom nodes, update the server-side serializer accordingly.

## Lossless Doco Transfer

Use **Export Doco File** in a document, folder, or knowledge-base menu. The resulting `.doco.zip` contains the original Yjs state, hierarchy, document settings, standalone spreadsheets, and attachments. Importing always creates a copy with fresh resource and attachment IDs, so it can safely move between independent Doco deployments without colliding with existing data.

Use the upload button beside the knowledge-base heading to import a whole knowledge base. To import a document or folder package, choose **Import Doco File** from the destination knowledge base or folder menu.

## License

MIT

TDQS

A3.6/5.0

Scored across 29 tools

Disambiguation4/5

Most tools map to a distinct resource and action (documents, blocks, translations, relations, concepts, summaries), so an agent can generally pick the right one. The main ambiguities are doco_search vs. doco_search_v2 and the easily confused doco_translations vs. doco_translation_units, though the descriptions give enough detail to resolve them.

Naming Consistency4/5

The doco_ prefix, snake_case, and familiar verb_noun forms (list_, get_, create_, update_, delete_, insert_, patch_) give the set a strong, predictable pattern. A few noun-only readers (doco_changes, doco_outline, doco_concepts, doco_summary) and the doco_search_v2 suffix are minor deviations.

Tool Count3/5

29 tools is a large surface, but the server covers many distinct subdomains: knowledge-base navigation, document/block editing, search, translations, relations, concepts, summaries, and attachments. Still, the count is heavy and some functions (search_v2, separate block readers) could plausibly be merged, so the set is borderline rather than tightly scoped.

Completeness3/5

The tool set covers document create/read/update, block-level editing, search, summaries, concepts, and translations, so most core workflows are supported. Notable gaps are the lack of document deletion, relation deletion, and attachment lifecycle operations (list/download/delete), which agents cannot work around easily.

Maintenance

ActivityMaintained
ResponsivenessNo issues