@chamvi/cli

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

The chamvi command line: dev, build, start, run-job and migrate for an app built with @chamvi/app.

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Commands
  4. Exit codes
  5. Signals
  6. License

@chamvi/cli

@chamvi/cli

The chamvi command line: dev, build, start (and start --check), run-job and migrate for an app built with @chamvi/app.

npm version CI License


Installation

npm install @chamvi/app @chamvi/cli ai
npm install --save-dev tsdown   # only for chamvi build

Usage

An app is one entry, src/index.ts, whose default export is createApp() from @chamvi/app:

import { createApp } from '@chamvi/app';
import { echo } from './agents.ts';

export default createApp({ agents: [echo] });

package.json scripts:

{
    "type": "module",
    "scripts": {
        "dev": "chamvi dev",
        "build": "chamvi build",
        "start": "chamvi start"
    }
}

Relative imports carry .ts and there is no enum, so chamvi dev (Node's type stripping) and chamvi build (tsdown) accept the same code. The template tsconfig.json:

{
    "compilerOptions": {
        "target": "ES2023",
        "module": "NodeNext",
        "moduleResolution": "NodeNext",
        "strict": true,
        "skipLibCheck": true,
        "verbatimModuleSyntax": true,
        "allowImportingTsExtensions": true,
        "erasableSyntaxOnly": true,
        "noEmit": true
    },
    "include": ["src", "test"]
}

Commands

chamvi <command> [args] [flags], plus --help and --version. Every command takes --entry <path>.

CommandArguments and flagsDoes
dev--entryRuns node --watch [--env-file-if-exists=.env] <cli> start --dev --entry <source entry>: restarts on a change of the entry, its imports or .env (Node watches the env file itself, so no --watch-path is needed). The env flag is passed only when .env exists at start (on Linux, node --watch fails on a missing env file), so a .env created later needs a restart of chamvi dev
build--entry, --out-dir <dir> (default dist)Bundles the entry with tsdown into <out-dir>/index.mjs plus its source map: ESM, node26, every dependencies and peerDependencies package external, the app's own modules inlined. The out dir is emptied first, so one that is the project folder or above it, holds the entry, or holds anything but .mjs and .mjs.map files exits 2
start--entry, --checkStarts the app: store (and migrations), engine and its channels (cron among them), then HTTP. --check runs the same start path up to the start (app.check(): config, store connection, model settings, every module, the agent folders' load and checks) and exits, writing nothing to the store (no migration, revision marker or cancel), serving nothing, running nothing: chamvi: start check passed on stdout and exit 0, each agent folder issue on its own stderr line and exit 2, a configuration error exit 2, a store failure (unreachable, pending migrations with CHAMVI_MIGRATE=false) exit 1; with the default CHAMVI_MIGRATE=true a start would apply them, so pending migrations pass. It needs what a start needs (CHAMVI_TOKENS, provider keys), so run it in CI with the production or staging env. See Pick a Model
run-job<agent>, [subscriptionId], --entryFires one cron subscription once and waits for its run (a Kubernetes CronJob; no channel is started); subscriptionId defaults to the agent's only cron subscription
migrate--entryMigrates the Postgres store (DATABASE_URL required)

The entry is --entry, else for the source commands (dev, build, start --dev) the package.json field "chamvi": { "entry": "<path>" }, else src/index.ts. The built commands (start, run-job, migrate) never read that field and default to dist/index.mjs, so an image built from a repository that sets it still starts; a .ts entry runs through type stripping too. With none of them (no --entry, no chamvi.entry, no default file), dev, start, run-job and migrate run the default app, createApp({}) configured by env alone, with its agents from ./agents (or CHAMVI_AGENTS_DIR), and say so on stderr; build exits 2 (nothing to build). A missing dist/index.mjs beside a src/index.ts still exits 2 with the build hint.

chamvi dev runs start --dev: the source entry, .env from the working directory (never overriding a set variable), in-memory repositories from createMemoryStore() unless DATABASE_URL is set and, without another authenticator, one random * token, logged with a warning, and shorter timeouts (CHAMVI_DRAIN_TIMEOUT_MS 5000, CHAMVI_FORCE_EXIT_MS 15000).

Exit codes

CodeWhen
0Success: a clean stop, a built bundle, a migrated store, a start --check without issues; run-job for a completed, waiting, skipped, queued-behind-an-approval or signal-interrupted run
1Runtime failure: a start, check, build or migrate error (a store unreachable or with pending migrations), a failed or cancelled job, a forced exit
2Usage or configuration: an unknown command or flag, an entry that is missing or no chamvi app, missing or invalid env (named, its value never echoed), model settings with an issue, an agent with no model and no default or a model string whose provider is not configured or whose package is missing, a start --check that found an agent folder issue

The CLI sets process.exitCode and lets Node exit; it calls process.exit() only for a forced exit.

Signals

start and run-job:

  • The first SIGTERM or SIGINT stops the app (/readyz 503, HTTP close, engine drain (channels stop first) up to CHAMVI_DRAIN_TIMEOUT_MS, store close), then exits 0, or 1 when the stop reported an error.
  • A second signal exits 1 at once. A signal within 1 s of the first counts as the same one, since npm run dev and npm start deliver one Ctrl-C twice (npm forwards SIGINT to the script while the terminal signals the whole group).
  • CHAMVI_FORCE_EXIT_MS (default 90000) after the first signal, a stop still running exits 1.

migrate installs no handlers: Node's default ends it.

On Kubernetes keep preStop + CHAMVI_FORCE_EXIT_MS < terminationGracePeriodSeconds. With a 5 s preStop sleep and a grace period of 120 s the worst case is 5 + 30 (drain) + 5 (close) + 30 (workspaces) = 70 s, the forced exit comes at 95 s and SIGKILL at 120 s.

chamvi dev runs its child in a process group of its own, so a terminal Ctrl-C reaches only the CLI, which forwards that one signal (the app then stops once, instead of getting the terminal's SIGINT plus the one node --watch forwards). SIGHUP (the terminal closed) and the CLI's own exit stop the child with SIGTERM, and the child's stdin is a pipe only the CLI writes: when the CLI dies without its exit hook (SIGKILL, the OOM killer), the pipe closes and the app ends the whole group, so it never outlives the CLI. The exit code is the child's, 0 when it ended by a forwarded signal.

License

Published under Apache License 2.0.

版本与发布记录

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

版本发布日期距今
0.8.0latest2026/11/09今天
0.7.32026/11/063 天前
0.7.22026/11/053 天前
0.7.12026/11/054 天前
0.7.02026/11/045 天前
0.6.12026/11/045 天前

关于 @chamvi/cli 的常见问题

@chamvi/cli 是什么?

The chamvi command line: dev, build, start, run-job and migrate for an app built with @chamvi/app.

如何安装 @chamvi/cli?

在项目目录运行 npm install @chamvi/cli,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@chamvi/app(^0.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 chamvi,可以用 npx chamvi 直接运行。

@chamvi/cli 支持 TypeScript 吗?

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

@chamvi/cli 支持 ESM 还是 CommonJS?

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

@chamvi/cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=26.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@chamvi/cli 可以商用吗?

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

@chamvi/cli 的下载量有多少?

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

@chamvi/cli 还在维护吗?

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