|
| 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 | +ZSM (Zoxide Session Manager) is a Zellij plugin written in Rust that integrates zoxide (smart directory navigation) with Zellij session management. It compiles to WebAssembly and runs inside Zellij. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build for development (debug mode) |
| 13 | +cargo build --target wasm32-wasip1 |
| 14 | + |
| 15 | +# Build for release |
| 16 | +cargo build --target wasm32-wasip1 --release |
| 17 | + |
| 18 | +# Add WASM target if not installed |
| 19 | +rustup target add wasm32-wasip1 |
| 20 | +``` |
| 21 | + |
| 22 | +Output locations: |
| 23 | +- Debug: `target/wasm32-wasip1/debug/zsm.wasm` |
| 24 | +- Release: `target/wasm32-wasip1/release/zsm.wasm` |
| 25 | + |
| 26 | +## Development Workflow |
| 27 | + |
| 28 | +Start the plugin development layout (includes hot-reload keybinding): |
| 29 | +```bash |
| 30 | +zellij -l zellij.kdl |
| 31 | +``` |
| 32 | +- Press `Alt+R` to reload the plugin after rebuilding |
| 33 | +- Re-launch plugin manually: `zellij action launch-or-focus-plugin file:target/wasm32-wasip1/debug/zsm.wasm` |
| 34 | + |
| 35 | +Alternative with watchexec: |
| 36 | +```bash |
| 37 | +watchexec --exts rs -- 'cargo build --target wasm32-wasip1; zellij action start-or-reload-plugin file:target/wasm32-wasip1/debug/zsm.wasm' |
| 38 | +``` |
| 39 | + |
| 40 | +## Architecture |
| 41 | + |
| 42 | +### Core Modules |
| 43 | + |
| 44 | +- **`main.rs`** - Plugin entry point. Implements `ZellijPlugin` trait, handles Zellij events (key input, permissions, session updates), and processes zoxide output. Contains smart session naming logic. |
| 45 | + |
| 46 | +- **`state.rs`** - `PluginState` struct holds all plugin state: config, session manager, zoxide directories, search engine, and UI state. Orchestrates key handling between screens (Main vs NewSession). |
| 47 | + |
| 48 | +- **`config.rs`** - Plugin configuration parsed from Zellij layout options (default_layout, session_separator, show_resurrectable_sessions, show_all_sessions, base_paths). |
| 49 | + |
| 50 | +### Session Module (`session/`) |
| 51 | + |
| 52 | +- **`manager.rs`** - `SessionManager` handles session operations: tracking existing/resurrectable sessions, generating incremented names (e.g., `project.2`), and executing actions (switch/delete sessions). |
| 53 | + |
| 54 | +- **`types.rs`** - `SessionItem` enum (ExistingSession, ResurrectableSession, Directory) and `SessionAction` enum for session operations. |
| 55 | + |
| 56 | +### Zoxide Module (`zoxide/`) |
| 57 | + |
| 58 | +- **`directory.rs`** - `ZoxideDirectory` struct: ranking score, directory path, generated session name. |
| 59 | + |
| 60 | +- **`search.rs`** - `SearchEngine` for fuzzy-finding directories/sessions using `fuzzy-matcher` crate. |
| 61 | + |
| 62 | +### UI Module (`ui/`) |
| 63 | + |
| 64 | +- **`renderer.rs`** - `PluginRenderer` handles all terminal rendering. Renders main list, new session screen, search results, and deletion confirmations. |
| 65 | + |
| 66 | +- **`components.rs`** - UI color utilities. |
| 67 | + |
| 68 | +- **`theme.rs`** - Theme/palette handling. |
| 69 | + |
| 70 | +### Other |
| 71 | + |
| 72 | +- **`new_session_info.rs`** - State for new session creation screen (name input, folder selection, layout selection). |
| 73 | + |
| 74 | +## Key Concepts |
| 75 | + |
| 76 | +**Smart Session Naming**: The plugin generates session names from directory paths, handling conflicts (adds parent context), nested directories, and truncation (max 29 chars due to Unix socket path limits). |
| 77 | + |
| 78 | +**Two-Screen UI**: Main screen shows directory list with fuzzy search; NewSession screen handles session name/folder/layout configuration. |
| 79 | + |
| 80 | +**Filepicker Integration**: Communicates with Zellij's filepicker plugin via `pipe_message_to_plugin` for folder selection. |
| 81 | + |
| 82 | +**Session Stability**: Zellij sends inconsistent `SessionUpdate` events that can omit sessions temporarily. The `SessionManager` uses stability tracking with a missing-count threshold (3 updates) before removing sessions from the UI, preventing flickering. |
| 83 | + |
| 84 | +## Testing |
| 85 | + |
| 86 | +Tests must run on the **native target**, not WASM (WASM binaries can't execute directly): |
| 87 | + |
| 88 | +```bash |
| 89 | +# Run tests (uses native target automatically when not cross-compiling) |
| 90 | +cargo test |
| 91 | + |
| 92 | +# Or explicitly specify target |
| 93 | +cargo test --target aarch64-apple-darwin |
| 94 | +``` |
| 95 | + |
| 96 | +Note: `SessionInfo` from `zellij-tile` has many required fields. See `manager.rs` test helper `make_session()` for how to construct test instances. |
| 97 | + |
| 98 | +## CI |
| 99 | + |
| 100 | +GitHub Actions workflow (`.github/workflows/ci.yml`) runs on PRs and pushes to main: |
| 101 | +- `test` - Runs unit tests on native target |
| 102 | +- `build-wasm` - Verifies WASM compilation |
| 103 | +- `clippy` - Lints with `-D warnings` |
| 104 | +- `fmt` - Checks formatting |
0 commit comments