@brooswit/herdr-sdk

中文文档
1.0.0发布于 2026/10/17MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 3523

Typed TypeScript client for the herdr socket API, generated from herdr's published JSON Schema

原始使用文档
文档目录4 节
  1. Layers
  2. Socket address
  3. Wire facts this is built on (herdr 0.8.2, protocol 20)
  4. Scripts

@brooswit/herdr-sdk

Typed TypeScript client for the herdr socket API, generated from the schema herdr itself publishes (herdr api schema --json).

import { HerdrClient } from "@brooswit/herdr-sdk";

const h = new HerdrClient();                       // herdr's own default config dir, or $HERDR_SOCKET_PATH
const { snapshot } = await h.session.snapshot();  // fully typed
await h.agent.wait({ target: "w1:p3", until: ["idle"], timeout_ms: 30_000 });

const sub = await h.subscribe([{ type: "pane.agent_status_changed", pane_id: "w1:p3" }]);
for await (const frame of sub) console.log(frame.event, frame.data);

Layers

dirjob
src/transportunix socket ↔ newline-delimited frames. No JSON, no protocol.
src/protocolenvelope shapes, HerdrError, ids. No I/O.
src/clientone request → one response → server closes (that is herdr's wire behaviour).
src/eventsevents.subscribe: the one long-lived connection, as an async iterator.
src/servicesone file per method family; thin typed façades.
src/reducerspure: snapshot + push frames → current fleet state.
src/generatedcodegen output. Do not edit; run bun run generate.
scripts/genthe generator, one file per output.

Socket address

  • Env var precedence: HERDR_SOCKET_PATH (herdr's own published override) wins; HERDR_SOCKET is honored only as a deprecated fallback when HERDR_SOCKET_PATH is unset. Prefer HERDR_SOCKET_PATH in new code.
  • Default path, when neither is set, mirrors herdr's own config-dir resolution: XDG_CONFIG_HOME if set; else on Windows %APPDATA%, then %USERPROFILE%\AppData\Roaming, then $HOME/.config, then the temp dir; else (POSIX) $HOME/.config, then the temp dir — joined with herdr/herdr.sock (or herdr-dev/herdr.sock with { dev: true }, or .../sessions/<name>/herdr.sock with { sessionName }).
  • Per-OS address: on Linux/macOS the path above is a real Unix-domain socket, used unchanged. On Windows, herdr listens on the named pipe \\.\pipe\<path> instead — the path itself is only ever prefixed, never otherwise rewritten. This SDK derives that automatically from process.platform; socketEndpoint() (exported from src/transport/socket-path.ts) does the derivation if you need it directly.
  • Dev builds / named sessions: pass { dev: true } to point at a herdr-dev build's config dir, or { sessionName } to connect to a named session's socket, e.g. new HerdrClient({ dev: true, sessionName: "work" }). Neither is ever guessed at runtime.

Wire facts this is built on (herdr 0.8.2, protocol 20)

  • Request {id, method, params} → {id, result:{type,…}} or {id, error:{code,message}}.
  • The server closes after one response. Each RPC is its own connection.
  • events.subscribe acks subscription_started and then keeps the connection open, streaming {event, data} frames.
  • Timeouts are typed errors (code: "timeout"), never hangs. isTimeout(e).
  • The schema does not say which result each method returns; scripts/gen/method-result-map.ts does, and test/live proves it.

Scripts

bun run generate     # schema → src/generated
bun run check        # generate + drift guard + typecheck + unit  (what CI runs)
bun run build
HERDR_LIVE=1 bun test test/live   # against your running herdr

版本与发布记录

@brooswit/herdr-sdk 共发布 6 个版本,首次发布于 2026/08/24;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.0latest2026/10/1722 天前
0.3.02026/09/281 个月前
0.2.02026/09/281 个月前
0.1.32026/08/272 个月前
0.1.22026/08/242 个月前
0.1.02026/08/242 个月前

关于 @brooswit/herdr-sdk 的常见问题

@brooswit/herdr-sdk 是什么?

Typed TypeScript client for the herdr socket API, generated from herdr's published JSON Schema

如何安装 @brooswit/herdr-sdk?

在项目目录运行 npm install @brooswit/herdr-sdk,或使用 pnpm add / yarn add / bun add。

@brooswit/herdr-sdk 支持 TypeScript 吗?

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

@brooswit/herdr-sdk 支持 ESM 还是 CommonJS?

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

@brooswit/herdr-sdk 可以商用吗?

@brooswit/herdr-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@brooswit/herdr-sdk 的下载量有多少?

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

@brooswit/herdr-sdk 还在维护吗?

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