Features: - Note operations (list, get, create, update, delete) - User authentication (login, logout, status) - Export operations (markdown, PDF, HTML, slide) - Revision history - JSON output mode - REPL interactive mode - 46 tests passing (100%) - Python 3.7+ support
3.7 KiB
3.7 KiB
CodiMD CLI Harness - Standard Operating Procedure
Overview
CodiMD is a collaborative markdown editor built on Node.js with real-time collaboration via Socket.IO. This document defines the standard operating procedure for building a CLI harness for CodiMD.
Architecture Summary
Technology Stack
- Backend: Node.js with Express
- Real-time: Socket.IO
- Database: Sequelize ORM (supports PostgreSQL, MySQL, MariaDB, SQLite, MSSQL)
- Authentication: Multiple providers (Facebook, Google, GitHub, Dropbox, Twitter, GitLab, LDAP, SAML, OAuth2, Email)
Data Models
Note
id(UUID): Primary keyshortid: Short unique identifier for sharingalias: Custom URL aliaspermission: One of: freely, editable, limited, locked, protected, privateviewcount: Number of viewstitle: Note title (extracted from content)content: Markdown contentauthorship: JSON array tracking contributionslastchangeAt: Last modification timestampsavedAt: Last save timestamp
User
id(UUID): Primary keyprofileid: External profile IDprofile: JSON profile datahistory: User historyaccessToken: OAuth access tokenrefreshToken: OAuth refresh tokendeleteToken: Token for account deletionemail: User emailpassword: Hashed password
Revision
id(UUID): Primary keypatch: Diff-match-patch formatlastContent: Previous content snapshotcontent: Full content at revision timelength: Content lengthauthorship: Authorship tracking
Permission Model
| Permission | Description |
|---|---|
freely |
Anyone can view and edit |
editable |
Anyone can view, logged-in users can edit |
limited |
Logged-in users can view and edit |
locked |
Anyone can view, only owner can edit |
protected |
Logged-in users can view, only owner can edit |
private |
Only owner can view and edit |
CLI Architecture
Command Groups
1. Note Commands (note)
note list- List user's notesnote get <id>- Get note contentnote create- Create new notenote update <id>- Update note contentnote delete <id>- Delete notenote publish <id>- Get publish linknote info <id>- Get note metadata
2. User Commands (user)
user me- Get current user infouser export- Export user datauser delete- Delete user account
3. Export Commands (export)
export markdown <id> [file]- Export as markdownexport pdf <id> [file]- Export as PDF (if enabled)export html <id> [file]- Export as HTML
4. Revision Commands (revision)
revision list <id>- List note revisionsrevision get <id> <time>- Get note at specific time
State Management
The CLI maintains session state in ~/.config/cli-anything-codimd/:
session.json: Auth tokens and session dataconfig.json: Server configurationcache.json: Cached note metadata
Output Formats
All commands support --json flag for machine-readable output:
{
"status": "success|error",
"data": {...},
"error": "error message if status is error"
}
Authentication Flow
- Interactive login prompts for credentials
- Supports all auth providers configured on server
- Session token stored for subsequent commands
- Token refresh handled automatically
Implementation Notes
- Note ID Encoding: CodiMD uses base64url-encoded UUIDs. The CLI must handle encoding/decoding.
- Real-time Limitations: The CLI cannot participate in real-time editing; it uses the REST API.
- Permission Checks: All operations must verify permissions before execution.
- Update Limitation: Note updates are only allowed when no users are actively editing via real-time connection.