@humaninloop/cli
v0.1.0
Published
Human-in-the-loop interaction tool. The `AskHuman` CLI pops up a window (or uses Telegram) to collect human input and prints the result to stdout — usable standalone or as a dependency.
Maintainers
Readme
@humaninloop/cli
跨平台「Human-in-the-loop」交互工具。命令行 AskHuman 在 AI 助手需要确认/补充时弹出窗口(或经 Telegram)收集人类回应,并把结果按固定区块写到 stdout。
底层为单一可执行文件(Tauri 2 / Rust)。本 npm 包通过「平台子包」分发:安装时只会拉取与当前平台匹配的一个二进制。
单独使用
npm i -g @humaninloop/cli
AskHuman "要不要继续?" -o "继续" -o "停止"作为依赖(程序集成)
npm i @humaninloop/cliimport { getBinaryPath, isAvailable } from "@humaninloop/cli";
import { spawnSync } from "node:child_process";
if (!isAvailable()) {
// 二进制未就位:跳过人工确认环节,避免阻塞流程
} else {
const r = spawnSync(getBinaryPath(), ["要继续吗?", "-o", "继续", "-o", "停止"], {
encoding: "utf8",
});
if (r.status === 3) {
// 当前环境无任何可用 channel(GUI 打不开且未配置 Telegram):降级处理
} else if (r.status === 0) {
// 成功:解析 r.stdout 的结果区块
console.log(r.stdout);
}
}getBinaryPath() 解析顺序:环境变量 HUMANINLOOP_BINARY → 平台子包 → 系统 PATH。
退出码契约
| 退出码 | 含义 |
|---|---|
| 0 | 成功拿到结果,或用户取消(输出 [状态]) |
| 3 | 无任何可用 channel(本地弹窗打不开且未配置 Telegram)——下游应降级 |
| 1 | 其他异常 |
stdout 只含结果区块([选择的选项]/[用户输入]/[图片]/[状态]),所有日志与报错走 stderr。
平台与系统依赖
支持 macOS(arm64/x64)、Windows(x64)、Linux(x64)。
Linux 运行 GUI 弹窗需系统具备 WebKitGTK(如
libwebkit2gtk-4.1)。若缺失且配置了 Telegram,会自动改走 Telegram;若两者都不可用,则以退出码3提示降级。
更多信息见项目仓库:https://github.com/Naituw/HumanInLoop
