DSH’s --profile web mode keeps a long-running process alive in the terminal and is operated through a browser-based Web UI. Closing a browser tab usually cannot stop the process, forcing developers to manually switch back to the terminal and press Ctrl+C. The dsh-auto-exit plugin solves this issue by detecting WebSocket connection status, enabling “close the Web UI and exit the CLI process.”
Plugin Overview¶
- Name: dsh-auto-exit
- One-line description: Automatically exits the CLI process when the Web UI is closed (equivalent to Ctrl+C)
- Author: xiaxingtianxia2-glitch
- License: MIT
- Category: Workflow
Core Features¶
- Automatic CLI process exit
- WebSocket connection detection
- Grace period mechanism (15 seconds by default)
- Status viewing endpoint
- Support for configuration options
Installation¶
With Web mode enabled, install the plugin with the following command:
dsh plugin --profile web add dsh-auto-exit
Usage¶
- Start
dsh --profile weband open the Web UI in your browser (default http://127.0.0.1:3080). - Close the browser tab or window. Note: all tabs/windows must be closed to trigger the exit.
- The process exits automatically after 15 seconds (equivalent to
Ctrl+C).
View Status¶
The plugin provides a status endpoint that can be used for debugging or monitoring:
curl http://127.0.0.1:3080/auto-exit/status
Example response:
{
"enabled": true,
"armed": true,
"sockets": 2,
"countdownMs": 0,
"graceSeconds": 15,
"pollMs": 1000,
"dryRun": false,
"lastEvent": "armed",
"fired": false
}
Configuration Options¶
The plugin supports the following configuration options (defaults shown):
| Field | Default | Description |
|---|---|---|
enabled |
true |
Master switch |
graceSeconds |
15 |
Number of seconds to wait after all connections are disconnected before exiting |
pollMs |
1000 |
Detection interval (milliseconds) |
armAfterFirstConnect |
true |
Becomes active only after the first page connection is seen (does not exit at startup if no page is opened) |
dryRun |
false |
Dry run: only logs; does not actually exit |
Use Cases and Notes¶
- Applicable scope: Only applies to
--profile webmode. - Trigger condition: The exit is triggered only when all tabs/windows are closed. Refreshing the page or briefly reopening it will not cause an accidental exit.
- Exception handling: Computer sleep or browser crashes also disconnect the connection and may cause the process to exit. If you do not want these situations to trigger the exit, increase
graceSeconds.
Conclusion¶
dsh-auto-exit provides an elegant process management approach for Web mode, balancing convenience and fault tolerance through the grace period mechanism.