Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
dist
dist-ssr
*.local
memos-sync-test-graph/
memos-sync-test-graph/
.env
74 changes: 74 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

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.

## Development Commands

```bash
# Install dependencies (enforces pnpm)
pnpm install

# Start development server with hot reload
pnpm dev

# Build the plugin for production
pnpm build

# Run tests
pnpm test

# Tests run automatically on pre-commit via Husky
```

## Architecture

### Plugin Structure
- **Entry Point**: `src/main.tsx` - Registers commands, sets up event handlers, and initializes the plugin
- **Core Logic**: `src/memos.ts` - Handles sync operations between Logseq and Memos
- **API Clients**: `src/memos/impls/` - Supports both Memos API v0 and v1 with abstracted interfaces
- **Settings**: `src/settings.ts` - Defines plugin configuration schema using Logseq's settings system

### Key Patterns
1. **API Version Abstraction**: The plugin uses a factory pattern to create the appropriate API client based on the Memos server version
2. **Sync Modes**:
- Journal: Syncs to daily journal pages
- Custom Page: Syncs to a user-defined page
- Journal Grouped: Groups memos by date in journal
3. **Event-Driven**: Uses Logseq's event system for settings changes and user commands

### Important Files
- `src/memos/client.ts`: Abstract base class for Memos API clients
- `src/memos/type.ts`: TypeScript definitions for Memos data structures
- `src/utils.ts` & `src/memos/utils.ts`: Utility functions for content generation and formatting

## Testing

Tests are located in `src/memos/__tests__/` and focus on content generation logic. The test suite runs automatically before commits.

## Build Process

The plugin uses Vite with a specialized Logseq plugin (`vite-plugin-logseq`) that:
- Bundles the plugin code
- Generates proper module exports for Logseq
- Creates the distribution package

## Release Process

Uses semantic-release with GitHub Actions for automated versioning and releases. The release creates a zip file containing:
- `dist/` folder with built assets
- `readme.md`
- `logo.svg`
- `LICENSE`
- `package.json`

## Important Considerations

1. **Memos API Compatibility**: The plugin supports both v0 and v1 of the Memos API. When making changes, ensure compatibility with both versions.
2. **Logseq API**: Uses `@logseq/libs` v0.0.10. Check Logseq documentation for API usage.
3. **Date Handling**: Uses date-fns for date manipulation. All dates should be handled consistently.
4. **Error Handling**: The plugin includes user-friendly error messages. Maintain clear error reporting for sync failures.
5. **Settings Validation**: Settings changes trigger immediate validation and re-initialization of the Memos client.
42 changes: 42 additions & 0 deletions V1_API_FIXES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Memos V1 API Fixes

This document summarizes the fixes made to support the Memos V1 API in the Logseq plugin.

## Issues Fixed

1. **Incorrect API endpoints**:
- Changed `/api/v1/memo` to `/api/v1/memos` for listing memos
- Changed `/api/v1/memo/{id}` to `/api/v1/memos/{id}` for updates
- Changed `/api/v1/user/me` to `/api/v1/users/me` for user info

2. **Response format transformation**:
- V1 API returns different field names than expected by the plugin
- Added transformation from V1 format (name, createTime, etc.) to V0 format (id, createdTs, etc.)
- Properly extract memo ID from the `name` field (e.g., "memos/123" → 123)

3. **Request parameters**:
- Changed from `limit`/`offset` to `pageSize`/`pageToken`
- Removed incorrect `rowStatus` filter (V1 API doesn't support it)
- Added client-side filtering for archived memos

4. **HTTP headers**:
- Added proper Accept and Content-Type headers
- Ensured proper JSON response handling

## Files Modified

- `src/memos/impls/clientV1.ts`: Main V1 client implementation
- `src/memos.ts`: Fixed typo "fitler" → "filter"

## Testing

The plugin has been tested and can now:
- ✅ Connect to Memos V1 API
- ✅ Fetch memos list
- ✅ Create new memos
- ✅ Update existing memos
- ✅ Get user information

## Build

Run `pnpm build` to build the plugin with these fixes.
Loading
Loading