Initial commit: CodiMD CLI harness
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
This commit is contained in:
157
.gitignore
vendored
Normal file
157
.gitignore
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# pipenv
|
||||
Pipfile.lock
|
||||
|
||||
# poetry
|
||||
poetry.lock
|
||||
|
||||
# pdm
|
||||
.pdm.toml
|
||||
.pdm-python
|
||||
.pdm-build/
|
||||
|
||||
# PEP 582
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# User-specific files
|
||||
.DS_Store
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
|
||||
# CodiMD source (too large)
|
||||
codimd/
|
||||
|
||||
# Session data
|
||||
*.json
|
||||
!setup.json
|
||||
!package.json
|
||||
!package-lock.json
|
||||
116
CODIMD.md
Normal file
116
CODIMD.md
Normal file
@@ -0,0 +1,116 @@
|
||||
# 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 key
|
||||
- `shortid`: Short unique identifier for sharing
|
||||
- `alias`: Custom URL alias
|
||||
- `permission`: One of: freely, editable, limited, locked, protected, private
|
||||
- `viewcount`: Number of views
|
||||
- `title`: Note title (extracted from content)
|
||||
- `content`: Markdown content
|
||||
- `authorship`: JSON array tracking contributions
|
||||
- `lastchangeAt`: Last modification timestamp
|
||||
- `savedAt`: Last save timestamp
|
||||
|
||||
#### User
|
||||
- `id` (UUID): Primary key
|
||||
- `profileid`: External profile ID
|
||||
- `profile`: JSON profile data
|
||||
- `history`: User history
|
||||
- `accessToken`: OAuth access token
|
||||
- `refreshToken`: OAuth refresh token
|
||||
- `deleteToken`: Token for account deletion
|
||||
- `email`: User email
|
||||
- `password`: Hashed password
|
||||
|
||||
#### Revision
|
||||
- `id` (UUID): Primary key
|
||||
- `patch`: Diff-match-patch format
|
||||
- `lastContent`: Previous content snapshot
|
||||
- `content`: Full content at revision time
|
||||
- `length`: Content length
|
||||
- `authorship`: 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 notes
|
||||
- `note get <id>` - Get note content
|
||||
- `note create` - Create new note
|
||||
- `note update <id>` - Update note content
|
||||
- `note delete <id>` - Delete note
|
||||
- `note publish <id>` - Get publish link
|
||||
- `note info <id>` - Get note metadata
|
||||
|
||||
#### 2. User Commands (`user`)
|
||||
- `user me` - Get current user info
|
||||
- `user export` - Export user data
|
||||
- `user delete` - Delete user account
|
||||
|
||||
#### 3. Export Commands (`export`)
|
||||
- `export markdown <id> [file]` - Export as markdown
|
||||
- `export pdf <id> [file]` - Export as PDF (if enabled)
|
||||
- `export html <id> [file]` - Export as HTML
|
||||
|
||||
#### 4. Revision Commands (`revision`)
|
||||
- `revision list <id>` - List note revisions
|
||||
- `revision 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 data
|
||||
- `config.json`: Server configuration
|
||||
- `cache.json`: Cached note metadata
|
||||
|
||||
### Output Formats
|
||||
|
||||
All commands support `--json` flag for machine-readable output:
|
||||
```json
|
||||
{
|
||||
"status": "success|error",
|
||||
"data": {...},
|
||||
"error": "error message if status is error"
|
||||
}
|
||||
```
|
||||
|
||||
### Authentication Flow
|
||||
|
||||
1. Interactive login prompts for credentials
|
||||
2. Supports all auth providers configured on server
|
||||
3. Session token stored for subsequent commands
|
||||
4. Token refresh handled automatically
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
1. **Note ID Encoding**: CodiMD uses base64url-encoded UUIDs. The CLI must handle encoding/decoding.
|
||||
2. **Real-time Limitations**: The CLI cannot participate in real-time editing; it uses the REST API.
|
||||
3. **Permission Checks**: All operations must verify permissions before execution.
|
||||
4. **Update Limitation**: Note updates are only allowed when no users are actively editing via real-time connection.
|
||||
52
setup.py
Normal file
52
setup.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
Setup script for cli-anything-codimd package.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from setuptools import setup, find_packages, find_namespace_packages
|
||||
|
||||
setup(
|
||||
name="cli-anything-codimd",
|
||||
version="0.1.0",
|
||||
description="CLI harness for CodiMD - collaborative markdown notes",
|
||||
long_description=open("README.md").read() if (Path(__file__).parent / "README.md").exists() else "",
|
||||
long_description_content_type="text/markdown",
|
||||
author="cli-anything",
|
||||
url="https://github.com/cli-anything/codimd",
|
||||
package_data={
|
||||
"cli_anything.codimd": ["skills/*.md", "README.md"],
|
||||
},
|
||||
packages=find_namespace_packages(include=["cli_anything.*"]),
|
||||
include_package_data=True,
|
||||
install_requires=[
|
||||
"click>=8.0.0",
|
||||
"requests>=2.33.0",
|
||||
"urllib3>=2.0.0,<3",
|
||||
"charset-normalizer>=3,<4",
|
||||
],
|
||||
extras_require={
|
||||
"dev": [
|
||||
"pytest>=7.0.0",
|
||||
"pytest-cov>=3.0.0",
|
||||
"requests-mock>=1.9.0",
|
||||
"pytest-subprocess>=1.5.0",
|
||||
],
|
||||
},
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"cli-anything-codimd=cli_anything.codimd.codimd_cli:cli",
|
||||
],
|
||||
},
|
||||
python_requires=">=3.7",
|
||||
classifiers=[
|
||||
"Development Status :: 4 - Beta",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user