@dbx-tools/cli-service

中文文档
0.9.206发布于 2026/11/11Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 9089

Cross-platform service lifecycle, uv Python runtimes, and system tray menus for CLIs

原始使用文档
文档目录12 节
  1. Add service commands
  2. Install and manage the service
  3. Customize the tray menu
  4. Command reference
  5. <cli> service
  6. <cli> service install
  7. <cli> service start
  8. <cli> service stop
  9. <cli> service restart
  10. <cli> service status
  11. <cli> service logs
  12. <cli> service uninstall

@dbx-tools/cli-service

Add current-user service installation, lifecycle commands, optional uv-managed Python dependencies, and a tray menu to a Commander CLI. The managed command continues after its terminal closes on macOS, Linux, and Windows.

Add service commands

import { buildServiceCommand } from "@dbx-tools/cli-service/cli";
import { defineService } from "@dbx-tools/cli-service/definition";
import { Command } from "commander";

const program = new Command("example");
program.addCommand(
  buildServiceCommand(
    defineService(import.meta.url, {
      command: { arguments: ["serve"] },
      menu: [{ type: "url", label: "Open App", url: "http://127.0.0.1:4400" }],
    }),
  ),
);
await program.parseAsync(process.argv);

defineService uses the owning package's name, version, and default executable. Use command.binName when the package has multiple executable entries. Set command.executable to run an existing external program instead of compiling a package entrypoint. Managed commands default NODE_ENV to production. An explicit command.environment.NODE_ENV overrides it.

Set pythonPackage when the compiled service command needs a Python runtime:

defineService(import.meta.url, {
  pythonPackage: { name: "example-runtime" },
  command: { arguments: ["serve"] },
});

During installation, the service creates an isolated uv environment under its data directory, installs the Python distribution at the service version, and sets PYTHON to that environment's interpreter. pythonPackage.python selects the Python version uv manages and defaults to 3.11. uv must be available on PATH during installation. Uninstalling the service removes the environment with the rest of the service-owned data.

Local-project installations preserve package extras and companion dependencies. Offline installations resolve only from uv's cache and fail immediately when a required artifact is unavailable.

command.options accepts either a concrete option object or a Zod object schema. Objects serialize their current values. Schemas parse {} and serialize their defaults. Boolean values become positive or negated flags, arrays become repeated flags, and undefined values are omitted:

defineService(import.meta.url, {
  command: {
    arguments: ["serve"],
    options: {
      host: "127.0.0.1",
      port: 4400,
      telemetry: false,
    },
  },
});

Install and manage the service

For the example program above:

example service install
example service status
example service logs -- tail -f
example service uninstall

Arguments after -- run as a command with the service log path appended, so logs -- cat prints the log and logs -- tail -f follows it.

The service belongs to the current user. Login startup uses a LaunchAgent on macOS, an XDG autostart entry on Linux, and a Startup command on Windows. Package entrypoints are compiled with Bun into versioned, per-install generations under ~/.dbx-tools/bin; Python environments use the same versioned generation under the service data directory, and each host generation carries its matching tray executable. Installing on macOS unloads any stale LaunchAgent definition, clears any persisted disabled override, and starts the current generation through launchd. Concurrent service installs serialize both service replacement and updates to the shared runtime dependency directory.

Services may provide an authentication preflight that runs before their managed command. The install-time waitForAuth mode defaults to auto: the owning CLI decides whether an applicable auth source exists, true requires a preflight, and false skips it. The host stays responsive to status and stop requests while the preflight waits.

The startup entries do not supervise the host, so the host restarts a preflight or managed command whenever it exits on its own, waiting 1s, 2s, 5s, 10s, 30s, then 60s between consecutive failures. Each restart is recorded in host.log. Quitting from the tray or running stop ends the host without a restart.

restart stops and starts the installed executable. It does not rebuild it. Re-run install after upgrading a consuming package to replace compiled executables and update the saved configuration.

Customize the tray menu

The default tray menu shows the program name and version and offers Quit. Add URL, command, or separator items through the service definition. Custom command items can select a package binary or an external executable in the same way as the main service command.

Use this package when adding service support to another CLI so users get the same installation, lifecycle commands, and tray behavior. The generated reference uses <cli> as a placeholder for the consuming program's name.

Command reference

<cli> service

Install and manage the desktop service

<cli> service [command]

Commands

CommandDescription
install [options]Install the service for the current user and start it
startStart the installed service
stopStop the running service
restartRestart the installed service
statusPrint service installation and process state as JSON
logs [command...]Print the service log path or append it to a command
uninstallStop and remove the service for the current user

<cli> service install

Install the service for the current user and start it

<cli> service install [options]

Options

OptionDescription
--startStart the service after installation. (default: true)
--no-startDisable start the service after installation.
--python-project <value>Local Python project installed instead of the registry package.
--offlineInstall Python packages from the uv cache without network access. (default: false)
--no-offlineDisable install python packages from the uv cache without network access.
--wait-for-auth <value>Authentication readiness mode: auto waits when the service provides an applicable auth preflight, true requires it, and false skips it. (choices: "auto", "true", "false", default: "auto")

<cli> service start

Start the installed service

<cli> service start

<cli> service stop

Stop the running service

<cli> service stop

<cli> service restart

Restart the installed service

<cli> service restart

<cli> service status

Print service installation and process state as JSON

<cli> service status

<cli> service logs

Print the service log path or append it to a command

<cli> service logs [command...]

Arguments

ArgumentDescription
commandCommand and arguments to run before the service log path

<cli> service uninstall

Stop and remove the service for the current user

<cli> service uninstall

版本与发布记录

@dbx-tools/cli-service 共发布 99 个版本,首次发布于 2026/10/06;过去 12 个月发布了 99 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.9.206latest2026/11/11今天
0.9.2052026/11/111 天前
0.9.2042026/11/101 天前
0.9.2032026/11/074 天前
0.9.2022026/11/065 天前
0.9.2012026/11/056 天前

关于 @dbx-tools/cli-service 的常见问题

@dbx-tools/cli-service 是什么?

Cross-platform service lifecycle, uv Python runtimes, and system tray menus for CLIs

如何安装 @dbx-tools/cli-service?

在项目目录运行 npm install @dbx-tools/cli-service,或使用 pnpm add / yarn add / bun add。

@dbx-tools/cli-service 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dbx-tools/cli-service 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dbx-tools/cli-service 可以商用吗?

@dbx-tools/cli-service 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dbx-tools/cli-service 的下载量有多少?

根据 npm 官方下载统计,@dbx-tools/cli-service 在 2026/10/12 – 2026/11/10 这 30 天内被下载 9,089 次,日均约 303 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dbx-tools/cli-service 还在维护吗?

最新版本 0.9.206 发布于 2026/11/11(今天);至今共发布 99 个版本,其中过去 12 个月发布了 99 个;首次发布于 2026/10/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。