- Home
- Plugins
- Dev & Plugin Tools
- dsh-magpie-autostart
dsh-magpie-autostart
bafanglaoge/dsh-magpie-autostart
Starts the Magpie LLM gateway when DeepSeek Harness boots: probes the gateway endpoint over TCP and runs `magpie tray` detached only when nothing is listening, so an already-running gateway is left alone.
Install
dsh plugin --profile web add github:bafanglaoge/dsh-magpie-autostartREADME
dsh-magpie-autostart
Start Magpie — the local LLM gateway DSH talks to — together with DeepSeek Harness, so opening DSH is enough and the gateway is already up when the first model request goes out. Close DSH and the gateway it started goes down with it, so a laptop does not keep a model gateway running in the background for the rest of the day.
DSH loads this bundle at boot, probes 127.0.0.1:3425 over TCP, and only when nothing
answers there launches magpie tray detached. If Magpie is already running (login
autostart, a manual launch, an earlier DSH boot) the probe succeeds and the plugin
does nothing. Every failure path is logged, never thrown: a missing or broken Magpie
can never keep DSH from booting or from quitting.
Install
# from this repository
dsh plugin --profile <profile> add github:bafanglaoge/dsh-magpie-autostart
# or from a local checkout, which keeps the link live while you edit
git clone https://github.com/bafanglaoge/dsh-magpie-autostart
dsh plugin --profile <profile> add link:<absolute-path-to-the-checkout>
<profile> is the DSH profile you boot (web, tui, headless, or your own). The
desktop application manages its profile itself: restart DSH and the bundle is mounted,
no manual edit of dsh.profile.bundles needed — the package manager reconciliation
adds it.
Configuration
Every option is optional and lives in the bundle's cordis.patch.yml (config: block),
so a fork or a private overlay can change it without touching the code:
| option | default | meaning |
|---|---|---|
enabled | true | Keep the plugin mounted but idle with false. |
executable | '' (discover) | Explicit path to the Magpie executable. |
args | [tray] | Command line for the executable. [] opens the full window instead of the tray. |
address | 127.0.0.1:3425 | Gateway endpoint probed on boot; keep it in sync with the provider baseURL in DSH settings. |
probeTimeoutMs | 800 | Time allowed for the TCP connect attempt. |
readyTimeoutMs | 0 | How long to wait for the spawned gateway to listen. 0 never blocks boot. |
stopOnExit | started | started stops only the gateway this plugin launched; always stops whatever Magpie serves when DSH exits; never leaves Magpie running. |
stateFile | '' | Where Magpie records the gateway it serves. Empty means $MAGPIE_STATE_FILE, then ~/.config/magpie/gateway.json. |
ownTimeoutMs | 3000 | How long the spawned gateway gets to record its pid before the plugin gives up owning it. |
Executable discovery order: the executable option, then MAGPIE_EXE in the
environment, then magpie / magpie.exe / magpie.com on PATH.
How it behaves
DSH boot
└─ plugin loaded
├─ TCP probe to 127.0.0.1:3425 (800 ms)
│ ├─ open → log "already listening", done
│ └─ closed → resolve executable
│ ├─ not found → warn, done (DSH boots normally)
│ └─ found → spawn <magpie> tray (detached, hidden, unref)
│ ├─ wait for the gateway record (ownTimeoutMs)
│ └─ remember the pid as owned by DSH
└─ any error is logged, never thrown
DSH exit
└─ exit hook
├─ re-read the gateway record
├─ stopOnExit=started → stop only if the served pid is still the owned one
├─ stopOnExit=always → stop whatever pid serves the gateway
└─ stopOnExit=never → nothing
Shutdown
DSH's desktop host calls process.exit() after its own shutdown, so the plugin can
run one last synchronous step: taskkill /PID <pid> /T /F on Windows, SIGTERM
elsewhere. Three rules keep that safe:
- Only what DSH started is stopped (
stopOnExit: started). A Magpie you launched by hand, or one the login autostart launched, is left alone — your other agents may be talking to it. It also means nothing is stopped when the boot probe found the gateway already listening. - The pid comes from Magpie, not from the spawn. Magpie starts as a launcher that hands the gateway to a server process (and exits at once when one is already up), so the plugin reads the served pid out of Magpie's gateway record before and after the spawn, and claims whatever pid appeared in between.
- The process is re-checked before it is killed. On exit the record is read again
and the pid must still belong to a
magpieprocess, so a recycled pid cannot take an unrelated program down with DSH.
If the record never appears (a Magpie build that does not write one, or a gateway that
started slower than ownTimeoutMs) the plugin says so and leaves the gateway running.
Stopping it is then your call, not the plugin's.
Making DSH own the gateway's lifetime
magpie autostart on starts Magpie at login, before DSH exists. With that in place the
boot probe always succeeds, nothing is spawned, and there is nothing for
stopOnExit: started to own — DSH prompts for a gateway it did not start. Two ways to
pair the lifetimes instead:
magpie autostart off # no login daemon; DSH starts and stops the gateway
or keep the autostart and set stopOnExit: always in the patch, which stops whatever
serves the gateway when DSH exits — at the cost of other tools losing it too.
Uninstall
dsh plugin --profile <profile> remove dsh-magpie-autostart
Development
npm test # node --test, no dependencies
说明(中文)
DSH 启动时自动拉起 Magpie 网关:先探测 127.0.0.1:3425,已被监听就什么都不做;
没监听就 spawn('magpie', ['tray']) 以托盘模式启动(detached + unref,不弹窗、不占 DSH
进程)。找不到可执行文件、spawn 失败等一律只写日志、绝不抛出,不会拖垮 DSH 启动。
关闭 DSH 时,插件会停掉它自己拉起的那个网关(stopOnExit: started)。判定“自己拉起的”
不看 spawn 出来的 pid —— Magpie 可能是交接给另一个进程的 launcher —— 而是比对
~/.config/magpie/gateway.json 里的 pid:启动前后各读一次,新出现的那个 pid 归 DSH 所有。
退出时再读一次,并确认该 pid 仍在跑 magpie,才执行 taskkill /T /F(Windows)或
SIGTERM(其他平台)。
- 手动启动的 Magpie、或登录自启动拉起的 Magpie 不会被关掉:别的 agent 可能正连着它。
- 想反过来让 DSH 决定 Magpie 的生死:先
magpie autostart off,或把配置改成stopOnExit: always。 - 网关记录没写出来(
ownTimeoutMs内没出现新 pid)时,插件只告警、不关网关。
可执行文件查找顺序:executable 配置 → 环境变量 MAGPIE_EXE → PATH 里的
magpie / magpie.exe / magpie.com。
License
MIT
Related plugins
deepseek-harness
deepseek-ai/deepseek-harness
dsh-market
dsh-market/dsh-market
dsh-web (dsh-plugin-manager)
zhu1090093659/dsh-web
dsh-web
zhu1090093659/dsh-web