Thank you for your interest in contributing to LogSeq CLI! This document provides guidelines and information for contributors.
- Fork the repository
- Clone your fork locally
- Install dependencies:
bun install - Set up your environment:
cp .env.template .envand configure your LogSeq API token - Run tests to verify your setup:
bun test
- Create a branch for your changes:
git checkout -b feature/your-feature-name - Make your changes
- Add tests for new functionality
- Ensure all tests pass:
bun test - Commit your changes with a descriptive message
- Push to your fork and submit a pull request
- Use TypeScript for all new code
- Follow existing patterns in the codebase
- Keep functions focused and single-purpose
- Add JSDoc comments for public APIs
Tests are written using Bun's built-in test runner. Run the test suite with:
bun testWhen adding new commands or features:
- Add unit tests that mock the LogSeq API client
- Test both success and error cases
- Test all flag combinations
- Verify edge cases (empty results, missing arguments, invalid input)
For manual testing against a running LogSeq instance:
- Ensure LogSeq is running with HTTP API enabled
- Set your API token in
.env - Run commands directly:
bun logseq.ts <command> [options]
Note: Use bun logseq.ts directly rather than bun run logseq for proper argument handling with spaces and special characters.
This project welcomes contributions made in collaboration with AI coding assistants such as Claude, GitHub Copilot, or similar tools.
When working with an AI assistant:
- Provide context: Share relevant files and documentation with your AI assistant
- Iterate on solutions: Use the AI to explore different approaches before committing
- Review generated code: Always review and understand AI-generated code before committing
- Test thoroughly: AI-generated code should pass all existing tests and include new tests for new functionality
If you are an AI assistant helping a contributor with this project:
- The project uses Bun as its runtime and package manager
- Environment variables are stored in
.env(copy from.env.template) - The main entry point is
logseq.ts
When testing CLI commands that interact with LogSeq:
-
Use tmux for interactive testing: Create a tmux session to test commands against a running LogSeq instance:
tmux new-session -d -s logseq-test -c /path/to/logseq-cli
-
Load environment variables: Before running commands, load the environment:
export $(grep -v '^#' .env | xargs)
-
Run commands directly: Use
bun logseq.ts(notbun run logseq) for proper argument parsing:bun logseq.ts list-pages bun logseq.ts get-page "Page Name" bun logseq.ts search "query" --limit 10
-
Test systematically: For each command, test:
- Basic functionality with positional arguments
- Alternative flag syntax (e.g.,
--namevs positional) - All optional flags
- Error cases (missing required args, invalid input)
- Edge cases (empty results, special characters)
-
Create regression tests: After manual testing, add unit tests to
cli/commands.test.tsthat mock the API client and verify behavior.
logseq-cli/
├── logseq.ts # CLI entry point
├── cli/
│ ├── arg_parser.ts # Argument parsing
│ ├── arg_parser.test.ts # Argument parser tests
│ ├── commands.ts # Command implementations
│ ├── commands.test.ts # Command tests
│ └── help.ts # Help text
├── logseq/
│ └── http_client.ts # LogSeq API client
├── .env.template # Environment template
└── CONTRIBUTING.md # This file
- Commands are exported functions in
cli/commands.ts - Each command parses args with
parseArgs()fromcli/arg_parser.ts - The LogSeq client is instantiated via
getClient()which reads from environment variables - Tests mock the LogSeq client methods and capture console output
When reporting bugs, please include:
- Your operating system and version
- Bun version (
bun --version) - LogSeq version
- Steps to reproduce the issue
- Expected vs actual behavior
- Any error messages
- Update documentation if you're changing functionality
- Add or update tests as needed
- Ensure the test suite passes
- Update the README if adding new commands or options
- Request review from maintainers
By contributing to this project, you agree that your contributions will be licensed under the same license as the project (MIT).