|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a Logseq plugin that syncs notes between Logseq and Memos (a self-hosted memo hub). The project is currently archived as the author no longer uses Memos, but the codebase remains functional. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Install dependencies (enforces pnpm) |
| 13 | +pnpm install |
| 14 | + |
| 15 | +# Start development server with hot reload |
| 16 | +pnpm dev |
| 17 | + |
| 18 | +# Build the plugin for production |
| 19 | +pnpm build |
| 20 | + |
| 21 | +# Run tests |
| 22 | +pnpm test |
| 23 | + |
| 24 | +# Tests run automatically on pre-commit via Husky |
| 25 | +``` |
| 26 | + |
| 27 | +## Architecture |
| 28 | + |
| 29 | +### Plugin Structure |
| 30 | +- **Entry Point**: `src/main.tsx` - Registers commands, sets up event handlers, and initializes the plugin |
| 31 | +- **Core Logic**: `src/memos.ts` - Handles sync operations between Logseq and Memos |
| 32 | +- **API Clients**: `src/memos/impls/` - Supports both Memos API v0 and v1 with abstracted interfaces |
| 33 | +- **Settings**: `src/settings.ts` - Defines plugin configuration schema using Logseq's settings system |
| 34 | + |
| 35 | +### Key Patterns |
| 36 | +1. **API Version Abstraction**: The plugin uses a factory pattern to create the appropriate API client based on the Memos server version |
| 37 | +2. **Sync Modes**: |
| 38 | + - Journal: Syncs to daily journal pages |
| 39 | + - Custom Page: Syncs to a user-defined page |
| 40 | + - Journal Grouped: Groups memos by date in journal |
| 41 | +3. **Event-Driven**: Uses Logseq's event system for settings changes and user commands |
| 42 | + |
| 43 | +### Important Files |
| 44 | +- `src/memos/client.ts`: Abstract base class for Memos API clients |
| 45 | +- `src/memos/type.ts`: TypeScript definitions for Memos data structures |
| 46 | +- `src/utils.ts` & `src/memos/utils.ts`: Utility functions for content generation and formatting |
| 47 | + |
| 48 | +## Testing |
| 49 | + |
| 50 | +Tests are located in `src/memos/__tests__/` and focus on content generation logic. The test suite runs automatically before commits. |
| 51 | + |
| 52 | +## Build Process |
| 53 | + |
| 54 | +The plugin uses Vite with a specialized Logseq plugin (`vite-plugin-logseq`) that: |
| 55 | +- Bundles the plugin code |
| 56 | +- Generates proper module exports for Logseq |
| 57 | +- Creates the distribution package |
| 58 | + |
| 59 | +## Release Process |
| 60 | + |
| 61 | +Uses semantic-release with GitHub Actions for automated versioning and releases. The release creates a zip file containing: |
| 62 | +- `dist/` folder with built assets |
| 63 | +- `readme.md` |
| 64 | +- `logo.svg` |
| 65 | +- `LICENSE` |
| 66 | +- `package.json` |
| 67 | + |
| 68 | +## Important Considerations |
| 69 | + |
| 70 | +1. **Memos API Compatibility**: The plugin supports both v0 and v1 of the Memos API. When making changes, ensure compatibility with both versions. |
| 71 | +2. **Logseq API**: Uses `@logseq/libs` v0.0.10. Check Logseq documentation for API usage. |
| 72 | +3. **Date Handling**: Uses date-fns for date manipulation. All dates should be handled consistently. |
| 73 | +4. **Error Handling**: The plugin includes user-friendly error messages. Maintain clear error reporting for sync failures. |
| 74 | +5. **Settings Validation**: Settings changes trigger immediate validation and re-initialization of the Memos client. |
0 commit comments