vde-layout 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,211 +1,167 @@
1
1
  # vde-layout
2
2
 
3
- A CLI tool for easily reproducing tmux pane layouts
3
+ vde-layout is a CLI that reproduces terminal layouts (tmux or WezTerm) from YAML presets. Define the panes you need once, then bring them back with a single command.
4
4
 
5
- ## Overview
6
-
7
- vde-layout is a tool that allows you to define tmux pane layouts in YAML configuration files and reproduce them with a single command. You can manage multiple layouts as presets for different purposes such as development environments, monitoring, and test execution.
8
-
9
- ## Features
10
-
11
- - Define layouts in YAML format
12
- - Reproduce layouts with a single command
13
- - Manage presets for different use cases
14
- - Flexible pane settings (commands, working directories, environment variables, etc.)
15
- - Freely combine horizontal and vertical splits
16
-
17
- ## Architecture
18
-
19
- vde-layout follows a functional-core/imperative-shell approach:
20
-
21
- - Functional Core compiles presets into immutable layout plans and deterministic tmux command sequences.
22
- - CLI adapters reuse the same plan for dry-run and real execution, ensuring matching plan hashes.
23
- - Plan Runner validates tmux prerequisites, applies each plan step, and reports structured diagnostics when a step fails.
24
-
25
- This separation allows the Functional Core to remain pure and fully testable while the boundary layer coordinates I/O with tmux.
26
-
27
- ## Development Notes
28
-
29
- - Runtime modules are authored in ESM with explicit `.ts` extensions, and `src/core/` exposes the canonical functional services directly.
30
- - Boundary adapters (`src/cli`, `src/executor`, `src/tmux`) remain factory-based; avoid新たなクラス導入は避けてください。
31
- - `npm run build` uses tsdown to emit ESM bundles into `dist/`. `npm test` automatically rebuilds before executing the Vitest suite.
32
- - Run `npm run typecheck` to validate the TypeScript sources without emitting artifacts.
5
+ ## Key Capabilities
6
+ - Keep reusable presets for development, monitoring, reviews, and more.
7
+ - Build nested horizontal/vertical splits with ratio-based sizing.
8
+ - Launch commands in each pane with custom working directories, environment variables, delays, and titles.
9
+ - Preview every tmux step in dry-run mode before you apply a preset.
10
+ - Target tmux or WezTerm backends with the same preset definitions.
11
+ - Switch between configuration files by flag or environment variables.
33
12
 
34
13
  ## Installation
35
-
36
14
  ```bash
37
15
  npm install -g vde-layout
38
- ```
39
-
40
- or
41
-
42
- ```bash
16
+ # or
43
17
  pnpm add -g vde-layout
44
- ```
45
-
46
- or
47
-
48
- ```bash
18
+ # or
49
19
  bun add -g vde-layout
50
20
  ```
51
21
 
52
- ## Usage
53
-
54
- ### Creating a Configuration File
55
-
56
- Create a configuration file at `~/.config/vde/layout.yml`:
57
-
22
+ ## Quick Start
23
+ 1. Create a YAML file at `~/.config/vde/layout.yml` (or any supported location; see “Configuration Search Order”).
24
+ 2. Paste a preset definition:
25
+ ```yaml
26
+ presets:
27
+ web-dev:
28
+ name: Web Development
29
+ description: Editor, server, and logs
30
+ layout:
31
+ type: horizontal
32
+ ratio: [3, 2]
33
+ panes:
34
+ - name: editor
35
+ command: nvim
36
+ focus: true
37
+ - type: vertical
38
+ ratio: [7, 3]
39
+ panes:
40
+ - name: server
41
+ command: npm run dev
42
+ cwd: ~/projects/app
43
+ env:
44
+ NODE_ENV: development
45
+ - name: logs
46
+ command: tail -f logs/app.log
47
+ title: Logs
48
+ delay: 500
49
+ monitor:
50
+ name: Monitor
51
+ command: htop
52
+ ```
53
+ 3. Start tmux and run:
54
+ ```bash
55
+ vde-layout web-dev
56
+ ```
57
+
58
+ ## CLI Commands
59
+ - `vde-layout [preset]` – Apply the named preset. When omitted, vde-layout uses the `default` preset; if none exists it lists available presets and exits.
60
+ - `vde-layout list` – Show available presets with descriptions.
61
+ - `vde-layout dev --dry-run` – Display the tmux steps without executing them.
62
+ - `vde-layout dev --verbose` – Print informational logs, including resolved presets and plan details.
63
+ - `vde-layout dev --backend wezterm` – Use the WezTerm backend (defaults to `tmux` when omitted).
64
+ - `vde-layout dev --current-window` – Reuse the current tmux window (or active WezTerm tab) after confirming that other panes can be closed.
65
+ - `vde-layout dev --new-window` – Force creation of a new tmux window or WezTerm tab even when presets or defaults request reuse.
66
+ - `vde-layout --config /path/to/layout.yml` – Load presets from a specific file.
67
+ - `vde-layout --help` – Show usage.
68
+ - `vde-layout --version` / `vde-layout -v` – Print package version (`-V` is kept for compatibility).
69
+
70
+ > **Note:** Applying a preset (without `--dry-run`) must be done inside an active tmux session when using the tmux backend. For the WezTerm backend, ensure a WezTerm window is running and focused so the CLI can discover it.
71
+
72
+ ## Terminal Backends
73
+ vde-layout resolves backends in the following order: CLI flag (`--backend`), preset configuration, then defaults to `tmux`.
74
+
75
+ - **tmux (default)** – Requires an active tmux session for non-dry runs. `--current-window` closes other panes in the selected window after confirmation; `--new-window` always creates a new tmux window.
76
+ - **WezTerm** – Requires the `wezterm` CLI to be available (nightly channel recommended). Start WezTerm beforehand so at least one window exists.
77
+ - `--current-window` targets the active tab and confirms before closing other panes.
78
+ - `--new-window` spawns a new tab in the active window when one is available, otherwise creates a fresh window.
79
+
80
+ ## Configuration Search Order
81
+ When no `--config` flag is provided, vde-layout searches for configuration files in the following order:
82
+ 1. `$VDE_CONFIG_PATH/layout.yml` (if `VDE_CONFIG_PATH` is set).
83
+ 2. `$XDG_CONFIG_HOME/vde/layout.yml` or `~/.config/vde/layout.yml` when `XDG_CONFIG_HOME` is unset.
84
+ 3. `<project-root>/.vde/layout.yml` (discovered by walking up from the current directory).
85
+
86
+ All existing files are merged, with project-specific definitions taking precedence over shared ones.
87
+
88
+ ## Preset Structure
89
+ Each preset is an object under the `presets` key:
58
90
  ```yaml
59
91
  presets:
60
- # Development environment layout
61
- dev:
62
- name: Development Environment
63
- description: 3-pane configuration with editor, server, and log monitoring
64
- layout:
65
- type: horizontal
66
- ratio: [3, 2] # 60:40 ratio (automatically normalized)
67
- panes:
68
- - name: editor
69
- command: nvim
70
- focus: true
71
- - type: vertical
72
- ratio: [7, 3] # 70:30 ratio
73
- panes:
74
- - name: server
75
- command: npm run dev
76
- - name: logs
77
- command: tail -f logs/app.log
78
-
79
- # Simple 2-pane layout
80
- simple:
81
- name: Simple Layout
82
- description: 2-pane configuration with editor and terminal
83
- layout:
84
- type: vertical
85
- ratio: [7, 3] # 70:30 ratio
86
- panes:
87
- - name: editor
88
- command: vim
89
- - name: terminal
90
- # Omitting command launches the default shell
91
-
92
- # Single pane preset (without layout)
93
- monitor:
94
- name: System Monitor
95
- description: System monitoring tool
96
- command: htop
92
+ preset-key:
93
+ name: "Display Name" # required
94
+ description: "Summary" # optional
95
+ windowMode: new-window # optional; "new-window" (default) or "current-window"
96
+ layout: # optional; omit for single command presets
97
+ # see Layout Structure
98
+ command: "htop" # optional; used when layout is omitted
97
99
  ```
98
100
 
99
- ### Commands
100
-
101
- #### List Presets
102
-
103
- ```bash
104
- vde-layout list
105
- ```
106
-
107
- #### Execute a Preset
108
-
109
- ```bash
110
- # Execute a specific preset
111
- vde-layout dev
112
-
113
- # Execute the default preset
114
- vde-layout
115
- ```
116
-
117
- #### Options
118
-
119
- ```bash
120
- # dry-run mode (doesn't actually execute)
121
- vde-layout dev --dry-run
122
-
123
- # Show verbose logs
124
- vde-layout dev --verbose
125
-
126
- # Show help
127
- vde-layout --help
128
- ```
129
-
130
- ## Configuration File Structure
131
-
132
- ### Presets
133
-
134
- Each preset is defined as an object with the following fields:
135
-
136
- ```yaml
137
- presets:
138
- preset-name:
139
- name: "Preset Name" # Required
140
- description: "Description" # Optional
141
- layout: # Optional (single pane when omitted)
142
- # Layout definition
143
- command: "Command" # Optional (only when layout is absent)
144
- ```
145
-
146
- ### Layout Definition
147
-
148
- Layouts define horizontal or vertical splits:
149
-
101
+ ### Layout Structure
150
102
  ```yaml
151
103
  layout:
152
- type: horizontal # horizontal or vertical
153
- ratio: [3, 2] # Split ratio (automatically normalized)
154
- panes: # Array of panes
155
- - name: "Pane Name" # Required (for pane identification)
156
- command: "Command" # Optional (default shell when omitted)
157
- cwd: "~/project" # Working directory (optional)
158
- env: # Environment variables (optional)
159
- NODE_ENV: development
160
- focus: true # Focus setting (optional)
161
- # Or nested layout
162
- - type: vertical
104
+ type: horizontal | vertical # required
105
+ ratio: [3, 2] # required; positive numbers, auto-normalized
106
+ panes: # required
107
+ - name: "left" # required for terminal panes
108
+ command: "npm run start" # optional
109
+ cwd: "~/project" # optional
110
+ env: # optional
111
+ API_BASE_URL: http://localhost:3000
112
+ focus: true # optional; only one pane should be true
113
+ delay: 500 # optional; wait (ms) before running command
114
+ title: "Server" # optional; tmux pane title
115
+ - type: vertical # nested split
163
116
  ratio: [1, 1]
164
117
  panes:
165
- - name: "Child Pane 1"
166
- - name: "Child Pane 2"
118
+ - name: "tests"
119
+ - name: "shell"
167
120
  ```
168
121
 
169
- ### Automatic Ratio Normalization
170
-
171
- You can specify any positive numbers for ratio, which are automatically normalized to 100%:
172
-
173
- - `[1, 1]` → `[50, 50]` (50% each)
174
- - `[2, 3]` → `[40, 60]` (40%, 60%)
175
- - `[1, 2, 1]` → `[25, 50, 25]` (25%, 50%, 25%)
176
-
177
- ### Single Pane Presets
178
-
179
- When layout is omitted, it operates as a single pane:
122
+ ### Ratio Normalization
123
+ Ratios can be any set of positive integers. vde-layout normalizes them to percentages:
124
+ - `[1, 1]` `[50, 50]`
125
+ - `[2, 3]` → `[40, 60]`
126
+ - `[1, 2, 1]` → `[25, 50, 25]`
180
127
 
128
+ ### Single Command Presets
129
+ If you omit `layout`, the preset runs a single command in one pane (or opens the default shell when `command` is omitted):
181
130
  ```yaml
182
131
  presets:
183
- simple-command:
184
- name: "Single Command"
185
- command: "htop" # Execute a single command
186
-
187
- default-shell:
188
- name: "Default Shell"
189
- # Omitting command also launches the default shell
132
+ shell:
133
+ name: Default Shell
134
+ build:
135
+ name: Build Script
136
+ command: npm run build
190
137
  ```
191
138
 
192
- ### Environment Variables
139
+ ### Window Mode Selection
140
+ - `defaults.windowMode` sets the default behavior for presets that omit `windowMode`. Allowed values are `new-window` (default) and `current-window`.
141
+ - Each preset may override the default by specifying its own `windowMode`.
142
+ - CLI flags (`--current-window` / `--new-window`) take highest precedence and override both presets and defaults.
143
+ - When `current-window` mode is used during an actual run, vde-layout prompts for confirmation before closing panes other than the pane running the command. Dry-run mode prints the intended closures without prompting.
193
144
 
194
- The configuration file location can be changed using environment variables:
195
145
 
196
- - `XDG_CONFIG_HOME`: Follows the XDG Base Directory specification
197
- - `VDE_CONFIG_PATH`: Directly specify the configuration file directory
146
+ ## Runtime Behavior
147
+ - Dry-run mode prints every tmux command and preserves the execution order you would see in a real run.
148
+ - Applying a preset creates (or reuses) a tmux window, splits panes according to the plan, sets environment variables, changes directories, and runs commands sequentially.
149
+ - If an error occurs (for example, a tmux command fails or the configuration is invalid), vde-layout returns a structured error with the failing step and guidance.
198
150
 
199
- ## Requirements
151
+ ## Environment Variables
152
+ - `VDE_CONFIG_PATH` – Override the base directory for configuration files.
153
+ - `XDG_CONFIG_HOME` – XDG base directory root; defaults to `~/.config` when unset.
154
+ - `VDE_DEBUG=true` – Enable debug-level logs (includes stack traces).
155
+ - `VDE_VERBOSE=true` – Enable info-level logs without full debug output.
156
+ - `TMUX` – Automatically set by tmux. vde-layout checks this to ensure execution happens inside a session.
200
157
 
158
+ ## Requirements
201
159
  - Node.js 22 or higher
202
- - tmux 2.0 or higher
203
- - Must be executed within a tmux session
204
-
205
- ## License
206
-
207
- MIT
160
+ - tmux 2.0 or higher (required for the tmux backend)
161
+ - WezTerm nightly build with `wezterm` on `$PATH` (required for the WezTerm backend)
208
162
 
209
163
  ## Contributing
164
+ Please submit bug reports and feature requests through [GitHub Issues](https://github.com/yuki-yano/vde-layout/issues).
210
165
 
211
- Please submit bug reports and feature requests to [GitHub Issues](https://github.com/yuki-yano/vde-layout/issues).
166
+ ## License
167
+ MIT