|
| 1 | +# Contributing to LogSeq CLI |
| 2 | + |
| 3 | +Thank you for your interest in contributing to LogSeq CLI! This document provides guidelines and information for contributors. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +1. Fork the repository |
| 8 | +2. Clone your fork locally |
| 9 | +3. Install dependencies: `bun install` |
| 10 | +4. Set up your environment: `cp .env.template .env` and configure your LogSeq API token |
| 11 | +5. Run tests to verify your setup: `bun test` |
| 12 | + |
| 13 | +## Development Workflow |
| 14 | + |
| 15 | +### Making Changes |
| 16 | + |
| 17 | +1. Create a branch for your changes: `git checkout -b feature/your-feature-name` |
| 18 | +2. Make your changes |
| 19 | +3. Add tests for new functionality |
| 20 | +4. Ensure all tests pass: `bun test` |
| 21 | +5. Commit your changes with a descriptive message |
| 22 | +6. Push to your fork and submit a pull request |
| 23 | + |
| 24 | +### Code Style |
| 25 | + |
| 26 | +- Use TypeScript for all new code |
| 27 | +- Follow existing patterns in the codebase |
| 28 | +- Keep functions focused and single-purpose |
| 29 | +- Add JSDoc comments for public APIs |
| 30 | + |
| 31 | +### Testing |
| 32 | + |
| 33 | +Tests are written using Bun's built-in test runner. Run the test suite with: |
| 34 | + |
| 35 | +```bash |
| 36 | +bun test |
| 37 | +``` |
| 38 | + |
| 39 | +When adding new commands or features: |
| 40 | +- Add unit tests that mock the LogSeq API client |
| 41 | +- Test both success and error cases |
| 42 | +- Test all flag combinations |
| 43 | +- Verify edge cases (empty results, missing arguments, invalid input) |
| 44 | + |
| 45 | +#### Manual Testing with LogSeq |
| 46 | + |
| 47 | +For manual testing against a running LogSeq instance: |
| 48 | + |
| 49 | +1. Ensure LogSeq is running with HTTP API enabled |
| 50 | +2. Set your API token in `.env` |
| 51 | +3. Run commands directly: `bun logseq.ts <command> [options]` |
| 52 | + |
| 53 | +**Note:** Use `bun logseq.ts` directly rather than `bun run logseq` for proper argument handling with spaces and special characters. |
| 54 | + |
| 55 | +## AI-Assisted Development |
| 56 | + |
| 57 | +This project welcomes contributions made in collaboration with AI coding assistants such as Claude, GitHub Copilot, or similar tools. |
| 58 | + |
| 59 | +### Pairing with AI Assistants |
| 60 | + |
| 61 | +When working with an AI assistant: |
| 62 | + |
| 63 | +1. **Provide context**: Share relevant files and documentation with your AI assistant |
| 64 | +2. **Iterate on solutions**: Use the AI to explore different approaches before committing |
| 65 | +3. **Review generated code**: Always review and understand AI-generated code before committing |
| 66 | +4. **Test thoroughly**: AI-generated code should pass all existing tests and include new tests for new functionality |
| 67 | + |
| 68 | +### Guidelines for AI Assistants |
| 69 | + |
| 70 | +If you are an AI assistant helping a contributor with this project: |
| 71 | + |
| 72 | +#### Environment Setup |
| 73 | + |
| 74 | +- The project uses Bun as its runtime and package manager |
| 75 | +- Environment variables are stored in `.env` (copy from `.env.template`) |
| 76 | +- The main entry point is `logseq.ts` |
| 77 | + |
| 78 | +#### Testing Commands |
| 79 | + |
| 80 | +When testing CLI commands that interact with LogSeq: |
| 81 | + |
| 82 | +1. **Use tmux for interactive testing**: Create a tmux session to test commands against a running LogSeq instance: |
| 83 | + ```bash |
| 84 | + tmux new-session -d -s logseq-test -c /path/to/logseq-cli |
| 85 | + ``` |
| 86 | + |
| 87 | +2. **Load environment variables**: Before running commands, load the environment: |
| 88 | + ```bash |
| 89 | + export $(grep -v '^#' .env | xargs) |
| 90 | + ``` |
| 91 | + |
| 92 | +3. **Run commands directly**: Use `bun logseq.ts` (not `bun run logseq`) for proper argument parsing: |
| 93 | + ```bash |
| 94 | + bun logseq.ts list-pages |
| 95 | + bun logseq.ts get-page "Page Name" |
| 96 | + bun logseq.ts search "query" --limit 10 |
| 97 | + ``` |
| 98 | + |
| 99 | +4. **Test systematically**: For each command, test: |
| 100 | + - Basic functionality with positional arguments |
| 101 | + - Alternative flag syntax (e.g., `--name` vs positional) |
| 102 | + - All optional flags |
| 103 | + - Error cases (missing required args, invalid input) |
| 104 | + - Edge cases (empty results, special characters) |
| 105 | + |
| 106 | +5. **Create regression tests**: After manual testing, add unit tests to `cli/commands.test.ts` that mock the API client and verify behavior. |
| 107 | + |
| 108 | +#### Project Structure |
| 109 | + |
| 110 | +``` |
| 111 | +logseq-cli/ |
| 112 | +├── logseq.ts # CLI entry point |
| 113 | +├── cli/ |
| 114 | +│ ├── arg_parser.ts # Argument parsing |
| 115 | +│ ├── arg_parser.test.ts # Argument parser tests |
| 116 | +│ ├── commands.ts # Command implementations |
| 117 | +│ ├── commands.test.ts # Command tests |
| 118 | +│ └── help.ts # Help text |
| 119 | +├── logseq/ |
| 120 | +│ └── http_client.ts # LogSeq API client |
| 121 | +├── .env.template # Environment template |
| 122 | +└── CONTRIBUTING.md # This file |
| 123 | +``` |
| 124 | + |
| 125 | +#### Common Patterns |
| 126 | + |
| 127 | +- Commands are exported functions in `cli/commands.ts` |
| 128 | +- Each command parses args with `parseArgs()` from `cli/arg_parser.ts` |
| 129 | +- The LogSeq client is instantiated via `getClient()` which reads from environment variables |
| 130 | +- Tests mock the LogSeq client methods and capture console output |
| 131 | + |
| 132 | +## Reporting Issues |
| 133 | + |
| 134 | +When reporting bugs, please include: |
| 135 | + |
| 136 | +- Your operating system and version |
| 137 | +- Bun version (`bun --version`) |
| 138 | +- LogSeq version |
| 139 | +- Steps to reproduce the issue |
| 140 | +- Expected vs actual behavior |
| 141 | +- Any error messages |
| 142 | + |
| 143 | +## Pull Request Process |
| 144 | + |
| 145 | +1. Update documentation if you're changing functionality |
| 146 | +2. Add or update tests as needed |
| 147 | +3. Ensure the test suite passes |
| 148 | +4. Update the README if adding new commands or options |
| 149 | +5. Request review from maintainers |
| 150 | + |
| 151 | +## License |
| 152 | + |
| 153 | +By contributing to this project, you agree that your contributions will be licensed under the same license as the project (MIT). |
0 commit comments