|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to AI agents (e.g., Claude Code, Cursor, and other LLM-powered tools) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +tmuxp is a session manager for tmux that allows users to save and load tmux sessions through YAML/JSON configuration files. It's powered by libtmux and provides a declarative way to manage tmux sessions. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Testing |
| 12 | +- `make test` or `uv run py.test` - Run all tests |
| 13 | +- `uv run py.test tests/path/to/test.py::TestClass::test_method` - Run a single test |
| 14 | +- `uv run ptw .` - Continuous test runner with pytest-watcher |
| 15 | +- `uv run ptw . --now --doctest-modules` - Watch tests including doctests |
| 16 | +- `make start` or `make watch_test` - Watch and run tests on file changes |
| 17 | + |
| 18 | +### Code Quality |
| 19 | +- `make ruff` or `uv run ruff check .` - Run linter |
| 20 | +- `uv run ruff check . --fix --show-fixes` - Fix linting issues automatically |
| 21 | +- `make ruff_format` or `uv run ruff format .` - Format code |
| 22 | +- `make mypy` or `uv run mypy` - Run type checking (strict mode enabled) |
| 23 | +- `make watch_ruff` - Watch and lint on changes |
| 24 | +- `make watch_mypy` - Watch and type check on changes |
| 25 | + |
| 26 | +### Documentation |
| 27 | +- `make build_docs` - Build documentation |
| 28 | +- `make serve_docs` - Serve docs locally at http://localhost:8013 |
| 29 | +- `make dev_docs` - Watch and serve docs with auto-reload |
| 30 | +- `make start_docs` - Alternative to dev_docs |
| 31 | + |
| 32 | +### CLI Commands |
| 33 | +- `tmuxp load <config>` - Load a tmux session from config |
| 34 | +- `tmuxp load -d <config>` - Load session in detached state |
| 35 | +- `tmuxp freeze <session-name>` - Export running session to config |
| 36 | +- `tmuxp convert <file>` - Convert between YAML and JSON |
| 37 | +- `tmuxp shell` - Interactive Python shell with tmux context |
| 38 | +- `tmuxp debug-info` - Collect system info for debugging |
| 39 | + |
| 40 | +## Architecture |
| 41 | + |
| 42 | +### Core Components |
| 43 | + |
| 44 | +1. **CLI Module** (`src/tmuxp/cli/`): Entry points for all tmuxp commands |
| 45 | + - `load.py`: Load tmux sessions from config files |
| 46 | + - `freeze.py`: Export live sessions to config files |
| 47 | + - `convert.py`: Convert between YAML/JSON formats |
| 48 | + - `shell.py`: Interactive Python shell with tmux context |
| 49 | + |
| 50 | +2. **Workspace Module** (`src/tmuxp/workspace/`): Core session management |
| 51 | + - `builder.py`: Builds tmux sessions from configuration |
| 52 | + - `loader.py`: Loads and validates config files |
| 53 | + - `finders.py`: Locates workspace config files |
| 54 | + - `freezer.py`: Exports running sessions to config |
| 55 | + |
| 56 | +3. **Plugin System** (`src/tmuxp/plugin.py`): Extensibility framework |
| 57 | + - Plugins extend `TmuxpPlugin` base class |
| 58 | + - Hooks: `before_workspace_builder`, `on_window_create`, `after_window_finished`, `before_script`, `reattach` |
| 59 | + - Version constraint checking for compatibility |
| 60 | + |
| 61 | +### Configuration Flow |
| 62 | + |
| 63 | +1. Load YAML/JSON config via `ConfigReader` (handles includes, environment variables) |
| 64 | +2. Expand inline shorthand syntax |
| 65 | +3. Trickle down default values (session → window → pane) |
| 66 | +4. Validate configuration structure |
| 67 | +5. Build tmux session via `WorkspaceBuilder` |
| 68 | + |
| 69 | +### Key Patterns |
| 70 | + |
| 71 | +- **Type Safety**: All code uses type hints with mypy strict mode |
| 72 | +- **Error Handling**: Custom exception hierarchy based on `TmuxpException` |
| 73 | +- **Testing**: Pytest with fixtures for tmux server/session/window/pane isolation |
| 74 | +- **Future Imports**: All files use `from __future__ import annotations` |
| 75 | + |
| 76 | +## Configuration Format |
| 77 | + |
| 78 | +```yaml |
| 79 | +session_name: my-session |
| 80 | +start_directory: ~/project |
| 81 | +windows: |
| 82 | + - window_name: editor |
| 83 | + layout: main-vertical |
| 84 | + panes: |
| 85 | + - shell_command: |
| 86 | + - vim |
| 87 | + - shell_command: |
| 88 | + - git status |
| 89 | +``` |
| 90 | +
|
| 91 | +## Environment Variables |
| 92 | +
|
| 93 | +- `TMUXP_CONFIGDIR`: Custom directory for workspace configs |
| 94 | +- `TMUX_CONF`: Path to tmux configuration file |
| 95 | +- `TMUXP_DEFAULT_COLUMNS/ROWS`: Default session dimensions |
| 96 | + |
| 97 | +## Testing Guidelines |
| 98 | + |
| 99 | +- Use pytest fixtures from `tests/fixtures/` for tmux objects |
| 100 | +- Test plugins using mock packages in `tests/fixtures/pluginsystem/` |
| 101 | +- Use `retry_until` utilities for async tmux operations |
| 102 | +- Run single tests with: `uv run py.test tests/file.py::TestClass::test_method` |
| 103 | +- **Use libtmux fixtures**: Prefer `server`, `session`, `window`, `pane` fixtures over manual setup |
| 104 | +- **Avoid mocks when fixtures exist**: Use real tmux fixtures instead of `MagicMock` |
| 105 | +- **Use `tmp_path`** fixture instead of Python's `tempfile` |
| 106 | +- **Use `monkeypatch`** fixture instead of `unittest.mock` |
| 107 | + |
| 108 | +## Code Style |
| 109 | + |
| 110 | +- Follow NumPy-style docstrings (pydocstyle convention) |
| 111 | +- Use ruff for formatting and linting |
| 112 | +- Maintain strict mypy type checking |
| 113 | +- Keep imports organized with future annotations at top |
| 114 | +- **Prefer namespace imports**: Use `import enum` and `enum.Enum` instead of `from enum import Enum` |
| 115 | +- **Type imports**: Use `import typing as t` and access via namespace (e.g., `t.Optional`) |
| 116 | +- **Development workflow**: Format → Test → Commit → Lint/Type Check → Test → Final Commit |
| 117 | + |
| 118 | +## Important Notes from Cursor Rules |
| 119 | + |
| 120 | +- **QA every edit**: Run formatting and tests before committing |
| 121 | +- **Doctest format**: Use narrative descriptions with blank lines between sections |
| 122 | +- **Complex examples**: Move to `tests/examples/<path>/test_<example>.py` |
| 123 | +- **Minimum Python**: 3.9+ (as per README) |
| 124 | +- **Minimum tmux**: 1.8+ (as per README) |
0 commit comments