devports 0.0.1 → 1.0.1

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.
Files changed (151) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/LICENSE +21 -0
  3. package/README.md +810 -29
  4. package/dist/cli.d.ts +7 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +329 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/commands/allocate.command.d.ts +8 -0
  9. package/dist/commands/allocate.command.d.ts.map +1 -0
  10. package/dist/commands/allocate.command.js +84 -0
  11. package/dist/commands/allocate.command.js.map +1 -0
  12. package/dist/commands/base-command.d.ts +28 -0
  13. package/dist/commands/base-command.d.ts.map +1 -0
  14. package/dist/commands/base-command.js +33 -0
  15. package/dist/commands/base-command.js.map +1 -0
  16. package/dist/commands/check.command.d.ts +7 -0
  17. package/dist/commands/check.command.d.ts.map +1 -0
  18. package/dist/commands/check.command.js +44 -0
  19. package/dist/commands/check.command.js.map +1 -0
  20. package/dist/commands/completion.command.d.ts +7 -0
  21. package/dist/commands/completion.command.d.ts.map +1 -0
  22. package/dist/commands/completion.command.js +116 -0
  23. package/dist/commands/completion.command.js.map +1 -0
  24. package/dist/commands/gitignore.command.d.ts +7 -0
  25. package/dist/commands/gitignore.command.d.ts.map +1 -0
  26. package/dist/commands/gitignore.command.js +61 -0
  27. package/dist/commands/gitignore.command.js.map +1 -0
  28. package/dist/commands/index.d.ts +7 -0
  29. package/dist/commands/index.d.ts.map +1 -0
  30. package/dist/commands/index.js +35 -0
  31. package/dist/commands/index.js.map +1 -0
  32. package/dist/commands/info.command.d.ts +7 -0
  33. package/dist/commands/info.command.d.ts.map +1 -0
  34. package/dist/commands/info.command.js +40 -0
  35. package/dist/commands/info.command.js.map +1 -0
  36. package/dist/commands/list.command.d.ts +8 -0
  37. package/dist/commands/list.command.d.ts.map +1 -0
  38. package/dist/commands/list.command.js +165 -0
  39. package/dist/commands/list.command.js.map +1 -0
  40. package/dist/commands/release.command.d.ts +8 -0
  41. package/dist/commands/release.command.d.ts.map +1 -0
  42. package/dist/commands/release.command.js +89 -0
  43. package/dist/commands/release.command.js.map +1 -0
  44. package/dist/commands/render.command.d.ts +7 -0
  45. package/dist/commands/render.command.d.ts.map +1 -0
  46. package/dist/commands/render.command.js +53 -0
  47. package/dist/commands/render.command.js.map +1 -0
  48. package/dist/commands/reserve.command.d.ts +7 -0
  49. package/dist/commands/reserve.command.d.ts.map +1 -0
  50. package/dist/commands/reserve.command.js +42 -0
  51. package/dist/commands/reserve.command.js.map +1 -0
  52. package/dist/commands/setup.command.d.ts +7 -0
  53. package/dist/commands/setup.command.d.ts.map +1 -0
  54. package/dist/commands/setup.command.js +43 -0
  55. package/dist/commands/setup.command.js.map +1 -0
  56. package/dist/commands/status.command.d.ts +7 -0
  57. package/dist/commands/status.command.d.ts.map +1 -0
  58. package/dist/commands/status.command.js +41 -0
  59. package/dist/commands/status.command.js.map +1 -0
  60. package/dist/commands/unreserve.command.d.ts +7 -0
  61. package/dist/commands/unreserve.command.d.ts.map +1 -0
  62. package/dist/commands/unreserve.command.js +38 -0
  63. package/dist/commands/unreserve.command.js.map +1 -0
  64. package/dist/commands/worktree-add.command.d.ts +7 -0
  65. package/dist/commands/worktree-add.command.d.ts.map +1 -0
  66. package/dist/commands/worktree-add.command.js +68 -0
  67. package/dist/commands/worktree-add.command.js.map +1 -0
  68. package/dist/commands/worktree-remove.command.d.ts +7 -0
  69. package/dist/commands/worktree-remove.command.d.ts.map +1 -0
  70. package/dist/commands/worktree-remove.command.js +33 -0
  71. package/dist/commands/worktree-remove.command.js.map +1 -0
  72. package/dist/completion/bash-completion-template.d.ts +5 -0
  73. package/dist/completion/bash-completion-template.d.ts.map +1 -0
  74. package/dist/completion/bash-completion-template.js +14 -0
  75. package/dist/completion/bash-completion-template.js.map +1 -0
  76. package/dist/completion/bash.sh +208 -0
  77. package/dist/completion/completion-data.d.ts +16 -0
  78. package/dist/completion/completion-data.d.ts.map +1 -0
  79. package/dist/completion/completion-data.js +38 -0
  80. package/dist/completion/completion-data.js.map +1 -0
  81. package/dist/completion/index.d.ts +24 -0
  82. package/dist/completion/index.d.ts.map +1 -0
  83. package/dist/completion/index.js +30 -0
  84. package/dist/completion/index.js.map +1 -0
  85. package/dist/completion/shell-config.d.ts +27 -0
  86. package/dist/completion/shell-config.d.ts.map +1 -0
  87. package/dist/completion/shell-config.js +243 -0
  88. package/dist/completion/shell-config.js.map +1 -0
  89. package/dist/completion/zsh-completion-template.d.ts +5 -0
  90. package/dist/completion/zsh-completion-template.d.ts.map +1 -0
  91. package/dist/completion/zsh-completion-template.js +14 -0
  92. package/dist/completion/zsh-completion-template.js.map +1 -0
  93. package/dist/completion/zsh.sh +164 -0
  94. package/dist/config.d.ts +6 -0
  95. package/dist/config.d.ts.map +1 -0
  96. package/dist/config.js +111 -0
  97. package/dist/config.js.map +1 -0
  98. package/dist/devports-1.0.1.tgz +0 -0
  99. package/dist/execution.d.ts +31 -0
  100. package/dist/execution.d.ts.map +1 -0
  101. package/dist/execution.js +110 -0
  102. package/dist/execution.js.map +1 -0
  103. package/dist/gitignore.d.ts +22 -0
  104. package/dist/gitignore.d.ts.map +1 -0
  105. package/dist/gitignore.js +142 -0
  106. package/dist/gitignore.js.map +1 -0
  107. package/dist/index.d.ts +7 -0
  108. package/dist/index.d.ts.map +1 -0
  109. package/dist/index.js +6 -0
  110. package/dist/index.js.map +1 -0
  111. package/dist/port-manager.d.ts +33 -0
  112. package/dist/port-manager.d.ts.map +1 -0
  113. package/dist/port-manager.js +169 -0
  114. package/dist/port-manager.js.map +1 -0
  115. package/dist/port-utils.d.ts +9 -0
  116. package/dist/port-utils.d.ts.map +1 -0
  117. package/dist/port-utils.js +38 -0
  118. package/dist/port-utils.js.map +1 -0
  119. package/dist/render.d.ts +54 -0
  120. package/dist/render.d.ts.map +1 -0
  121. package/dist/render.js +286 -0
  122. package/dist/render.js.map +1 -0
  123. package/dist/services/lock-manager.d.ts +46 -0
  124. package/dist/services/lock-manager.d.ts.map +1 -0
  125. package/dist/services/lock-manager.js +118 -0
  126. package/dist/services/lock-manager.js.map +1 -0
  127. package/dist/services/response-formatter.d.ts +45 -0
  128. package/dist/services/response-formatter.d.ts.map +1 -0
  129. package/dist/services/response-formatter.js +102 -0
  130. package/dist/services/response-formatter.js.map +1 -0
  131. package/dist/services/validation-service.d.ts +109 -0
  132. package/dist/services/validation-service.d.ts.map +1 -0
  133. package/dist/services/validation-service.js +267 -0
  134. package/dist/services/validation-service.js.map +1 -0
  135. package/dist/setup.d.ts +20 -0
  136. package/dist/setup.d.ts.map +1 -0
  137. package/dist/setup.js +245 -0
  138. package/dist/setup.js.map +1 -0
  139. package/dist/types.d.ts +29 -0
  140. package/dist/types.d.ts.map +1 -0
  141. package/dist/types.js +18 -0
  142. package/dist/types.js.map +1 -0
  143. package/dist/validation.d.ts +69 -0
  144. package/dist/validation.d.ts.map +1 -0
  145. package/dist/validation.js +344 -0
  146. package/dist/validation.js.map +1 -0
  147. package/dist/worktree.d.ts +24 -0
  148. package/dist/worktree.d.ts.map +1 -0
  149. package/dist/worktree.js +245 -0
  150. package/dist/worktree.js.map +1 -0
  151. package/package.json +90 -6
package/README.md CHANGED
@@ -1,45 +1,826 @@
1
- # devports
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="./logo-dark.svg">
4
+ <source media="(prefers-color-scheme: light)" srcset="./logo-light.svg">
5
+ <img src="./logo.svg" alt="devports" width="200"/>
6
+ </picture>
7
+ </p>
2
8
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
9
+ <h1 align="center">devports</h1>
4
10
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
11
+ <p align="center">
12
+ <em>Automatic port allocation for multi-project development</em>
13
+ </p>
6
14
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
15
+ Stop manually tracking port numbers across projects, Docker containers, and git worktrees. `devports` automatically manages port allocations so you never have conflicts.
8
16
 
9
- ## Purpose
17
+ [![npm version](https://img.shields.io/npm/v/devports)](https://www.npmjs.com/package/devports)
18
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
19
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `devports`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
20
+ ## Why?
15
21
 
16
- ## What is OIDC Trusted Publishing?
22
+ When working on multiple projects:
17
23
 
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
24
+ - Project A wants PostgreSQL on port 5432
25
+ - ❌ Project B also wants PostgreSQL on port 5432
26
+ - ❌ Manually tracking free ports is tedious and error-prone
27
+ - ❌ Git worktrees need unique ports but remembering which is hard
28
+ - ❌ Team members use different ports causing confusion
19
29
 
20
- ## Setup Instructions
30
+ **devports solves this:**
21
31
 
22
- To properly configure OIDC trusted publishing for this package:
32
+ - Automatically allocates the next available port
33
+ - ✅ Tracks all allocations in one place
34
+ - ✅ Type-aware (postgres, mysql, api, app, etc.)
35
+ - ✅ Works great with git worktrees
36
+ - ✅ Scriptable for automation
37
+ - ✅ Team-friendly with shared configuration
23
38
 
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
39
+ ## Installation
28
40
 
29
- ## DO NOT USE THIS PACKAGE
41
+ ```bash
42
+ npm install -g devports
43
+ ```
30
44
 
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
45
+ Verify:
36
46
 
37
- ## More Information
47
+ ```bash
48
+ devports --version
49
+ ```
38
50
 
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
51
+ ### Platform Support
42
52
 
43
- ---
53
+ devports works on all major platforms:
44
54
 
45
- **Maintained for OIDC setup purposes only**
55
+ - ✅ **macOS** - Full support including shell completion (zsh/bash)
56
+ - ✅ **Linux** - Full support including shell completion (bash/zsh)
57
+ - ✅ **Windows (WSL)** - Full support when running under WSL (recommended)
58
+ - ⚠️ **Windows (native)** - Core functionality works, but shell completion is not yet supported
59
+ - PowerShell completion support is planned for a future release
60
+ - Use WSL for the best experience on Windows
61
+
62
+ **Windows users:** We recommend using [WSL (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/install) for full feature support including shell completion.
63
+
64
+ ## Quick Start
65
+
66
+ ```bash
67
+ # Allocate a PostgreSQL port
68
+ devports allocate myproject postgres --type postgres
69
+ # → ✅ Allocated port 5432 for myproject/postgres
70
+
71
+ # Allocate an API port
72
+ devports allocate myproject api --type api
73
+ # → ✅ Allocated port 3000 for myproject/api
74
+
75
+ # List all allocations
76
+ devports list
77
+
78
+ # Check what's available
79
+ devports status
80
+
81
+ # Release when done
82
+ devports release myproject postgres
83
+ ```
84
+
85
+ ## Usage
86
+
87
+ ### Basic Commands
88
+
89
+ ```bash
90
+ # Set up current directory (main clone only)
91
+ devports setup [--template <file>] [--force] [--skip-render]
92
+
93
+ # Allocate a port
94
+ devports allocate <project> <service> --type <type>
95
+
96
+ # Release port(s)
97
+ devports release <project> [service] [--all]
98
+
99
+ # List allocations
100
+ devports list [--project <name>] [--type <type>]
101
+
102
+ # Check availability
103
+ devports status
104
+ devports check <port>
105
+
106
+ # Render templates
107
+ devports render <file> [--output <file>]
108
+
109
+ # Manage .gitignore
110
+ devports gitignore [--preview]
111
+
112
+ # Show configuration
113
+ devports info
114
+ ```
115
+
116
+ ### Port Types
117
+
118
+ | Type | Default Range | Usage |
119
+ | -------- | ------------- | ----------------------- |
120
+ | postgres | 5434-5499 | PostgreSQL databases |
121
+ | mysql | 3308-3399 | MySQL/MariaDB databases |
122
+ | redis | 6381-6399 | Redis instances |
123
+ | api | 3002-3099 | API servers |
124
+ | app | 5002-5999 | Web applications |
125
+ | custom | 8002-8999 | Custom services |
126
+
127
+ > **Note**: Port ranges start slightly above standard ports (postgres: 5432, mysql: 3306, redis: 6379, api: 3000, etc.) to avoid conflicts with development services running directly on the host. Port 8080 is reserved by default as it's commonly used for development servers.
128
+
129
+ Port ranges are fully customizable in `~/.config/devports/config.json`.
130
+
131
+ ### Scripting & Automation
132
+
133
+ All commands support `--quiet` and `--json` for automation:
134
+
135
+ ```bash
136
+ # Get just the port number
137
+ PORT=$(devports allocate myapp postgres --type postgres --quiet)
138
+ echo "Using port: $PORT"
139
+
140
+ # Get JSON output
141
+ devports allocate myapp api --type api --json
142
+ # → {"port":3001,"project":"myapp","service":"api","type":"api"}
143
+
144
+ # Check if port is available (exit code 0=yes, 1=no)
145
+ if devports check 5432 --quiet; then
146
+ echo "Port 5432 is available"
147
+ fi
148
+ ```
149
+
150
+ ## Real-World Examples
151
+
152
+ ### Shell Script Setup
153
+
154
+ ```bash
155
+ #!/bin/bash
156
+ PROJECT=$(basename $(pwd))
157
+
158
+ # Allocate ports
159
+ POSTGRES_PORT=$(devports allocate "$PROJECT" postgres --type postgres --quiet)
160
+ API_PORT=$(devports allocate "$PROJECT" api --type api --quiet)
161
+
162
+ # Write to .env
163
+ cat > .env <<EOF
164
+ DATABASE_PORT=$POSTGRES_PORT
165
+ API_PORT=$API_PORT
166
+ DATABASE_URL=postgresql://user:pass@localhost:$POSTGRES_PORT/db
167
+ EOF
168
+
169
+ echo "✅ Ports allocated: PG=$POSTGRES_PORT, API=$API_PORT"
170
+ ```
171
+
172
+ ### Main Clone Setup
173
+
174
+ Use `devports setup` to initialize your main repository clone with port allocation and template processing:
175
+
176
+ ```bash
177
+ # Basic setup (defaults to postgres if no template found)
178
+ devports setup
179
+
180
+ # Setup with custom template
181
+ devports setup --template .env.devports
182
+
183
+ # Force overwrite existing .env (creates .env.backup)
184
+ devports setup --force
185
+
186
+ # Skip auto-rendering of *.devports files
187
+ devports setup --skip-render
188
+ ```
189
+
190
+ #### Template System
191
+
192
+ Create a `.env.devports` template file with `{devports:type:service-name}` placeholders:
193
+
194
+ ```bash
195
+ # .env.devports
196
+ DEVPORTS_PROJECT_NAME=myproject
197
+ DATABASE_URL=postgresql://user:pass@localhost:{devports:postgres:db}/myapp
198
+ API_PORT={devports:api:server}
199
+ REDIS_URL=redis://localhost:{devports:redis:cache}
200
+ API_URL=https://{devports:project}-api.example.com
201
+ ```
202
+
203
+ Running `devports setup` will:
204
+
205
+ 1. Allocate ports for detected services (db, server, cache)
206
+ 2. Process template and generate `.env` file
207
+ 3. Auto-render any `*.devports` files found in the directory
208
+
209
+ Example auto-rendering:
210
+
211
+ ```yaml
212
+ # docker-compose.yml.devports
213
+ services:
214
+ db:
215
+ image: postgres:15
216
+ ports:
217
+ - "{devports:postgres:db}:5432"
218
+ container_name: {devports:project}-db
219
+
220
+ app:
221
+ build: .
222
+ ports:
223
+ - "{devports:api:server}:3000"
224
+ container_name: {devports:project}-app
225
+ ```
226
+
227
+ After `devports setup`, this becomes `docker-compose.yml` with actual ports and project name substituted.
228
+
229
+ ### Git Worktree Integration
230
+
231
+ #### Basic Usage
232
+
233
+ ```bash
234
+ # Create worktree with automatic port allocation
235
+ devports worktree add ../feature-auth -b feature/auth
236
+
237
+ # Remove worktree and release all ports
238
+ devports worktree remove ../feature-auth
239
+ ```
240
+
241
+ #### Template-Based Allocation
242
+
243
+ Create a `.env.devports` template to control exactly what gets port-mapped:
244
+
245
+ ```bash
246
+ # .env.devports template
247
+ DEVPORTS_PROJECT_NAME=myproject
248
+ MCP_DATABASE_URL=postgresql://user:pass@localhost:{devports:postgres:main-database}/mydb
249
+ API_URL=http://localhost:{devports:api:main-api}/api
250
+ ```
251
+
252
+ Running `devports worktree add ../my-feature -b feature/branch` creates an `.env` file with actual ports allocated.
253
+
254
+ #### Auto-rendering \*.devports Files
255
+
256
+ After creating a worktree, devports automatically scans for and renders all `*.devports` files:
257
+
258
+ ```bash
259
+ # If your project has these files:
260
+ docker-compose.yml.devports
261
+ config.json.devports
262
+ nginx.conf.devports
263
+
264
+ # After running: devports worktree add ../feature-payments -b feature/payments
265
+ # The worktree will contain:
266
+ docker-compose.yml # ← rendered from docker-compose.yml.devports template
267
+ config.json # ← rendered from config.json.devports template
268
+ nginx.conf # ← rendered from nginx.conf.devports template
269
+ .env # ← generated from .env.devports template
270
+ ```
271
+
272
+ This pattern allows you to:
273
+
274
+ - Keep templates in version control (`*.devports`)
275
+ - Auto-generate configuration files with allocated ports
276
+ - Use `devports gitignore` to prevent committing generated files
277
+
278
+ ### Package.json Scripts
279
+
280
+ For worktree management (useful with local installations):
281
+
282
+ ```json
283
+ {
284
+ "scripts": {
285
+ "worktree": "devports worktree",
286
+ "ports": "devports list --project $(basename $(pwd))"
287
+ }
288
+ }
289
+ ```
290
+
291
+ Then run:
292
+
293
+ ```bash
294
+ # Create worktree
295
+ npm run worktree -- add ../feature-auth -b feature/auth
296
+
297
+ # Check current project's ports
298
+ npm run ports
299
+ ```
300
+
301
+ ### Programmatic Usage (Node.js)
302
+
303
+ For CI/CD environments or tool integrations:
304
+
305
+ ```javascript
306
+ import { allocatePort, listAllocations, checkPortInUse } from 'devports';
307
+
308
+ // CI/CD: Allocate ephemeral port for testing
309
+ const testRunId = `ci-${process.env.GITHUB_RUN_ID}`;
310
+ const dbPort = await allocatePort(testRunId, 'test-db', 'postgres');
311
+
312
+ // Tool integration: Check if port is actually available
313
+ const isInUse = await checkPortInUse(5432);
314
+ if (!isInUse) {
315
+ console.log('Port 5432 is available for use');
316
+ }
317
+
318
+ // Development tools: List project ports
319
+ const projectPorts = listAllocations({ project: 'myapp' });
320
+ console.log('Current allocations:', projectPorts);
321
+ ```
322
+
323
+ ## Configuration
324
+
325
+ ### Config File
326
+
327
+ Location: `~/.config/devports/config.json`
328
+
329
+ ```json
330
+ {
331
+ "ranges": {
332
+ "postgres": { "start": 5434, "end": 5499 },
333
+ "mysql": { "start": 3308, "end": 3399 },
334
+ "redis": { "start": 6381, "end": 6399 },
335
+ "api": { "start": 3002, "end": 3099 },
336
+ "app": { "start": 5002, "end": 5999 },
337
+ "custom": { "start": 8002, "end": 8999 }
338
+ },
339
+ "registryPath": "~/.config/devports/ports.json"
340
+ }
341
+ ```
342
+
343
+ You can edit this file to customize port ranges or add new types.
344
+
345
+ ### Registry File
346
+
347
+ Location: `~/.config/devports/ports.json`
348
+
349
+ ```json
350
+ {
351
+ "allocations": [
352
+ {
353
+ "port": 5432,
354
+ "project": "myapp",
355
+ "service": "postgres",
356
+ "type": "postgres",
357
+ "allocatedAt": "2025-01-15T10:30:00.000Z"
358
+ }
359
+ ],
360
+ "reservations": []
361
+ }
362
+ ```
363
+
364
+ This file is managed automatically but can be edited manually if needed.
365
+
366
+ ## Importing Existing Allocations
367
+
368
+ If you already have manual port assignments:
369
+
370
+ 1. Copy the example script:
371
+
372
+ ```bash
373
+ cp node_modules/devports/scripts/import-example.mjs ./import-ports.mjs
374
+ ```
375
+
376
+ 2. Edit `import-ports.mjs` and add your allocations:
377
+
378
+ ```javascript
379
+ const EXISTING_ALLOCATIONS = [
380
+ { port: 5432, project: 'myapp', service: 'postgres', type: 'postgres' },
381
+ { port: 3001, project: 'myapp', service: 'api', type: 'api' },
382
+ ];
383
+ ```
384
+
385
+ 3. Run the import:
386
+ ```bash
387
+ node import-ports.mjs
388
+ ```
389
+
390
+ ## AI Assistant Integration
391
+
392
+ `devports` is designed to work seamlessly with AI coding assistants (Claude Code, Cursor, GitHub Copilot, etc.). See [AI-ASSISTANT-GUIDE.md](./AI-ASSISTANT-GUIDE.md) for comprehensive automation patterns and examples.
393
+
394
+ Quick tips for AI usage:
395
+
396
+ - Use `--quiet` to get just the port number
397
+ - Use `--json` for structured output
398
+ - All commands return proper exit codes
399
+ - No interactive prompts - fully scriptable
400
+
401
+ ## Port Availability Checking
402
+
403
+ devports automatically checks if ports are actually in use when allocating them:
404
+
405
+ ```bash
406
+ # If port 5432 is in use, devports will skip to 5433, 5434, etc.
407
+ devports allocate myproject postgres --type postgres
408
+ # → ✅ Allocated port 5433 for myproject/postgres
409
+ # → ⚠️ Warning: Port 5433 is currently in use by another process.
410
+ ```
411
+
412
+ The warning helps you identify potential conflicts, but allocation still succeeds since the process might not be running when you need the port.
413
+
414
+ ## Environment Variables
415
+
416
+ When devports creates `.env` files (via worktree commands), it includes:
417
+
418
+ - **Port variables**: `DATABASE_PORT`, `API_PORT`, etc.
419
+ - **Project name**: `DEVPORTS_PROJECT_NAME` (URL-safe version of project name)
420
+
421
+ This is useful for dynamic configuration like Tailscale funnel domains, development URLs, and external tool integration.
422
+
423
+ ## Integration Guides
424
+
425
+ devports works seamlessly with various development tools and platforms:
426
+
427
+ - **[Docker & Docker Compose](./DOCKER.md)** - Complete guide for container port management and naming conflicts
428
+ - **AI Assistant Integration** - See [AI-ASSISTANT-GUIDE.md](./AI-ASSISTANT-GUIDE.md) for automation patterns
429
+ - **Contributing** - See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup and guidelines
430
+
431
+ ## Tips & Best Practices
432
+
433
+ ### Project Naming
434
+
435
+ To avoid conflicts between projects with same branch names:
436
+
437
+ **Good:**
438
+
439
+ ```bash
440
+ # Use project-specific identifiers
441
+ devports allocate "myproject-feature-auth" postgres --type postgres
442
+ devports allocate "otherproject-feature-auth" postgres --type postgres
443
+ ```
444
+
445
+ **Also Good:**
446
+
447
+ ```bash
448
+ # Include project name in identifier
449
+ PROJECT=$(basename $(pwd))
450
+ devports allocate "$PROJECT-$BRANCH" postgres --type postgres
451
+ ```
452
+
453
+ ### Team Collaboration
454
+
455
+ Share consistent port ranges across the team:
456
+
457
+ ```bash
458
+ # Commit a team config template
459
+ cp ~/.config/devports/config.json ./devports-config.json
460
+ git add devports-config.json
461
+
462
+ # Team members link it (keeps configs in sync)
463
+ ln -sf "$(pwd)/devports-config.json" ~/.config/devports/config.json
464
+ ```
465
+
466
+ This symlink approach ensures everyone stays in sync automatically when the config is updated.
467
+
468
+ ### Cleanup
469
+
470
+ Release ports when completely finished with a project or worktree:
471
+
472
+ ```bash
473
+ # Release specific service
474
+ devports release myproject postgres
475
+
476
+ # Release all ports for a project (when completely done)
477
+ devports release myproject --all
478
+
479
+ # Or by port number
480
+ devports release 5432 --port
481
+ ```
482
+
483
+ "Done" means you're completely finished with the project/worktree, not just done for the day.
484
+
485
+ ## Command Reference
486
+
487
+ ### allocate
488
+
489
+ ```bash
490
+ devports allocate <project> <service> --type <type> [options]
491
+
492
+ Options:
493
+ -t, --type <type> Service type (postgres, mysql, redis, api, app, custom) [required]
494
+ -q, --quiet Output only the port number
495
+ --json Output as JSON
496
+ ```
497
+
498
+ ### release
499
+
500
+ ```bash
501
+ devports release <project> [service] [options]
502
+
503
+ Options:
504
+ -a, --all Release all ports for project
505
+ -p, --port First argument is port number to release
506
+ -q, --quiet Suppress output
507
+ --json Output as JSON
508
+ ```
509
+
510
+ ### list
511
+
512
+ Shows current port allocations.
513
+
514
+ ```bash
515
+ devports list [options]
516
+
517
+ Options:
518
+ -p, --project <name> Filter by project
519
+ -t, --type <type> Filter by type
520
+ -q, --quiet Output only port numbers
521
+ --json Output as JSON
522
+ ```
523
+
524
+ Example output:
525
+
526
+ ```
527
+ 📋 Port Allocations:
528
+
529
+ 🏗️ myapp
530
+ ┌──────┬──────────────────┬──────────────────┬────────────────────────┐
531
+ │ Port │ Service │ Type │ Allocated │
532
+ ├──────┼──────────────────┼──────────────────┼────────────────────────┤
533
+ │ 3000 │ api │ api │ 11/17/2025, 2:34:18 PM │
534
+ │ 5432 │ postgres │ postgres │ 11/17/2025, 2:34:18 PM │
535
+ └──────┴──────────────────┴──────────────────┴────────────────────────┘
536
+
537
+ 🏗️ feature-auth
538
+ ┌──────┬──────────────────┬──────────────────┬────────────────────────┐
539
+ │ Port │ Service │ Type │ Allocated │
540
+ ├──────┼──────────────────┼──────────────────┼────────────────────────┤
541
+ │ 5433 │ postgres │ postgres │ 11/17/2025, 3:15:22 PM │
542
+ └──────┴──────────────────┴──────────────────┴────────────────────────┘
543
+ ```
544
+
545
+ ### status
546
+
547
+ Shows port availability statistics by type.
548
+
549
+ ```bash
550
+ devports status [options]
551
+
552
+ Options:
553
+ -q, --quiet Output type:port pairs
554
+ --json Output as JSON
555
+ ```
556
+
557
+ Example output:
558
+
559
+ ```
560
+ Port Status:
561
+
562
+ postgres : 2 used, 66 available
563
+ Next available: 5434
564
+ mysql : 0 used, 94 available
565
+ Next available: 3306
566
+ api : 1 used, 99 available
567
+ Next available: 3001
568
+ ```
569
+
570
+ ### check
571
+
572
+ ```bash
573
+ devports check <port> [options]
574
+
575
+ Options:
576
+ -q, --quiet Silent mode (exit code only: 0=available, 1=in use)
577
+ --json Output as JSON
578
+ ```
579
+
580
+ ### worktree
581
+
582
+ #### add
583
+
584
+ ```bash
585
+ devports worktree add <path> [options]
586
+
587
+ Options:
588
+ -b, --branch <branch> Create and checkout a new branch [required]
589
+ --no-env Skip .env file creation
590
+ --env-file <file> Custom .env file name (default: .env)
591
+ --services <services> Services to allocate (comma-separated)
592
+ --template <file> Use template file for .env generation
593
+ --post-hook <script> Run script after worktree creation
594
+ --json Output as JSON
595
+
596
+ Template Patterns:
597
+ {devports:project} → URL-safe project name (recommended)
598
+ {DEVPORTS_PROJECT_NAME} → URL-safe project name (deprecated, use {devports:project})
599
+ {devports:type:service-name} → Allocated port for service (type required)
600
+ ```
601
+
602
+ #### remove
603
+
604
+ ```bash
605
+ devports worktree remove <path> [options]
606
+
607
+ Options:
608
+ -f, --force Force removal even if worktree is dirty
609
+ --json Output as JSON
610
+ ```
611
+
612
+ ### info
613
+
614
+ ```bash
615
+ devports info [--json]
616
+ ```
617
+
618
+ Shows configuration location, registry location, and port statistics.
619
+
620
+ ### reserve / unreserve
621
+
622
+ ```bash
623
+ devports reserve <port> [reason]
624
+ devports unreserve <port>
625
+ ```
626
+
627
+ Reserve or unreserve a specific port to prevent automatic allocation.
628
+
629
+ ### render
630
+
631
+ ```bash
632
+ devports render <file> [options]
633
+
634
+ Options:
635
+ -p, --project <name> Project name (overrides template project name)
636
+ -o, --output <file> Output file (defaults to stdout)
637
+ --json Output allocation info as JSON
638
+ ```
639
+
640
+ Render a template file by replacing `{devports:type:service-name}` patterns with allocated ports.
641
+
642
+ Example:
643
+
644
+ ```bash
645
+ # Render template to stdout
646
+ devports render .env.devports
647
+
648
+ # Render to specific file
649
+ devports render config.yml.devports -o config.yml
650
+
651
+ # Override project name
652
+ devports render .env.devports --project myproject-feature
653
+ ```
654
+
655
+ ### gitignore
656
+
657
+ ```bash
658
+ devports gitignore [options]
659
+
660
+ Options:
661
+ --preview Show what would be added without making changes
662
+ --clean Remove stale devports entries from .gitignore
663
+ --json Output as JSON
664
+ ```
665
+
666
+ Manage .gitignore entries for `*.devports` files. For each `file.devports` found, adds `file` to .gitignore to prevent committing generated files while keeping templates in version control.
667
+
668
+ Examples:
669
+
670
+ ```bash
671
+ # Add *.devports files to .gitignore
672
+ devports gitignore
673
+
674
+ # Preview what would be added
675
+ devports gitignore --preview
676
+
677
+ # Clean up stale entries
678
+ devports gitignore --clean
679
+ ```
680
+
681
+ ### completion
682
+
683
+ ```bash
684
+ devports completion [shell] [options]
685
+
686
+ Arguments:
687
+ shell Shell type (bash, zsh) - defaults to zsh
688
+
689
+ Options:
690
+ -i, --install Install completion script and setup shell config automatically
691
+ -u, --uninstall Remove completion script and clean shell config
692
+ --check Check if completion is already installed
693
+ --test Test if completion works in a fresh shell
694
+ --json Output as JSON
695
+ ```
696
+
697
+ Generate and install shell completion scripts. Supports tab completion for commands, project names, service names, port types, and file paths.
698
+
699
+ Examples:
700
+
701
+ ```bash
702
+ # Install zsh completion (macOS default)
703
+ devports completion zsh --install
704
+
705
+ # Install bash completion (Linux default)
706
+ devports completion bash --install
707
+
708
+ # Generate script to stdout
709
+ devports completion zsh
710
+
711
+ # Check if already installed
712
+ devports completion zsh --check
713
+ ```
714
+
715
+ ## Shell Completion
716
+
717
+ devports supports tab completion for commands, options, and dynamic values like project names.
718
+
719
+ ### Quick Setup
720
+
721
+ **One-Command Setup (All Platforms)**:
722
+
723
+ ```bash
724
+ # Automatic setup for your shell (detects zsh/bash)
725
+ devports completion --install
726
+
727
+ # Then start a new terminal or reload your shell config
728
+ ```
729
+
730
+ The `--install` command automatically:
731
+
732
+ - ✅ Detects your shell (zsh on macOS, bash on Linux)
733
+ - ✅ Installs the completion script
734
+ - ✅ Updates your shell config (.zshrc/.bashrc)
735
+ - ✅ Adds helpful comments with instructions
736
+
737
+ ### Advanced Options
738
+
739
+ ```bash
740
+ # Check if completion is already installed
741
+ devports completion --check
742
+
743
+ # Test that completion works (validates in fresh shell)
744
+ devports completion --test
745
+
746
+ # Generate completion script to stdout
747
+ devports completion zsh
748
+
749
+ # Uninstall completion (removes files and shell config)
750
+ devports completion --uninstall
751
+ ```
752
+
753
+ ### What Gets Completed
754
+
755
+ - **Commands**: `devports <TAB>` → allocate, release, list, status, etc.
756
+ - **Project names**: `devports release -a <TAB>` → cycles through actual project names
757
+ - **Service names**: `devports release myproject <TAB>` → shows services for that project
758
+ - **Port types**: `devports allocate myproject service --type <TAB>` → postgres, mysql, redis, etc.
759
+ - **File paths**: Template files, scripts, output files
760
+ - **Options**: All command-line flags and options
761
+
762
+ ### Examples
763
+
764
+ ```bash
765
+ # Tab completion in action:
766
+ devports rel<TAB> # → devports release
767
+ devports release -a my<TAB> # → cycles through projects starting with "my"
768
+ devports allocate myapp db --type post<TAB> # → postgres
769
+ ```
770
+
771
+ The completion dynamically reads your current port allocations, so project and service names are always up to date.
772
+
773
+ ## Troubleshooting
774
+
775
+ **"devports: command not found"**
776
+
777
+ ```bash
778
+ npm install -g devports
779
+ # Or check: npm list -g devports
780
+ ```
781
+
782
+ **"Port already allocated"**
783
+
784
+ ```bash
785
+ devports list --project myproject
786
+ devports release myproject service
787
+ ```
788
+
789
+ **"No available ports"**
790
+
791
+ ```bash
792
+ devports status
793
+ devports list --type postgres
794
+ # Consider expanding range in config
795
+ ```
796
+
797
+ **"Invalid service type"**
798
+
799
+ ```bash
800
+ devports info # See valid types
801
+ # Valid: postgres, mysql, redis, api, app, custom
802
+ ```
803
+
804
+ ## Contributing
805
+
806
+ Contributions welcome! See [CONTRIBUTING.md](./CONTRIBUTING.md) and [DEVELOPMENT.md](./DEVELOPMENT.md).
807
+
808
+ Ideas for contributions:
809
+
810
+ - Docker Compose auto-update integration
811
+ - VSCode extension
812
+ - Port health checking (verify ports aren't in use)
813
+ - Team sync features
814
+ - Additional port type presets
815
+
816
+ ## License
817
+
818
+ MIT © [Ben Dechrai](https://bendechr.ai)
819
+
820
+ ## Links
821
+
822
+ - [npm package](https://www.npmjs.com/package/devports)
823
+ - [GitHub repository](https://github.com/bendechrai/devports)
824
+ - [Issue tracker](https://github.com/bendechrai/devports/issues)
825
+ - [AI Assistant Guide](./AI-ASSISTANT-GUIDE.md)
826
+ - [Development Guide](./DEVELOPMENT.md)