@saltpub/xiaojiu-agent-bridge 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.md +167 -166
  3. package/dist/cli.js +1295 -305
  4. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # xiaojiu-agent-bridge
2
2
 
3
+ ## 0.1.9
4
+
5
+ ### Highlights
6
+
7
+ - 新增 `/btw [问题]` 旁路提问:长任务运行中可向该会话问一句,用会话上下文回答、不执行工具、不写入会话历史,也不会让 btw 会话出现在 `/resume`;claude/codex/pi/omp/opencode 分别走 fork、RPC btw 与 `session.generate` 等价机制。
8
+ - 修复 launcher 模式下守护进程无法停止的问题:`stop`/`kill` 现在会先终止 launcher 监管进程再停止 bot 子进程,避免子进程被立即自动拉起导致停止假成功;`kill <uid>` 与 `stop --profile` 统一为同一套停止逻辑。停止时会同时清理现行 `port-*` 与旧版 profile 命名的系统服务定义。`profile remove` 在持锁进程已退出时自动清理残留锁,锁冲突错误现在带持有者 pid 与启动时间。
9
+
10
+ ### Added
11
+
12
+ - feat(commands): 新增 /btw 会话旁路提问
13
+
14
+ ### Fixed
15
+
16
+ - fix(launcher): 停止时先终止 launcher 监管进程
17
+
3
18
  ## 0.1.8
4
19
 
5
20
  ### Highlights
@@ -13,7 +28,7 @@
13
28
 
14
29
  ### Fixed
15
30
 
16
- - fix(launcher): 启动超时兜底防wedged卡死
31
+ - fix(launcher): 启动超时兜底防 wedged 卡死
17
32
 
18
33
  ## 0.1.7
19
34
 
package/README.md CHANGED
@@ -1,166 +1,167 @@
1
- <p align="center">
2
- <img src="./assets/readme/hero.gif" width="100%" alt="Xiaojiu Agent Bridge routes a Xiaojiu message through the local bridge runtime to one of five local coding-agent CLIs and returns the reply to the same Xiaojiu session">
3
- </p>
4
-
5
- <p align="center">
6
- <sub>静态 SVG 回退:Xiaojiu 消息 → 本机 CLI Agent → 回到同一会话 · <a href="./assets/readme/hero.svg">查看完整路由图</a></sub>
7
- </p>
8
-
9
- # xiaojiu-agent-bridge
10
-
11
- 在 Xiaojiu 里发一句私聊或群内 `@` 消息,让本机的 Claude Code、Codex CLI、Pi、OpenCode 或 OMP 在指定工作目录执行;Markdown 或卡片结果回到同一个会话。
12
-
13
- > 本地优先的消息桥:不自建后端,把 Xiaojiu 的聊天入口接到你已经安装好的 coding-agent CLI。
14
-
15
- ## 你会得到什么
16
-
17
- - **从聊天开始**:接收 `message_receive` 与 `card_action_trigger` Webhook,快速确认后异步处理。
18
- - **会话不丢上下文**:按聊天 / 话题 scope 保存 Agent 会话、工作目录与运行状态。
19
- - **一套入口,多种 Agent**:统一适配 Claude Code、Codex CLI、Pi、OpenCode 和 OMP。
20
- - **可控地运行**:合并连续输入,执行访问控制、超时、中断、恢复和附件缓存。
21
- - **结果回到原处**:以 Markdown 或消息卡片回复;流式输出通过更新消息模拟。
22
- - **团队可管理**:用 profile、后台服务和本机 Web 控制台管理多套 Bot 配置。
23
-
24
- ## 先看一条消息的完整路径
25
-
26
- 下面是项目机制示意,不是生产环境截图:
27
-
28
- ```text
29
- Xiaojiu Webhook
30
- │ message_receive / card_action_trigger
31
- ▼
32
- HTTP 校验 · header.id 去重 · 立即 200
33
- ▼
34
- 消息合并 · scope · 运行策略 · 工作目录
35
- ▼
36
- RunExecutor → AgentAdapter → 本机 CLI 子进程
37
- ▼
38
- RunState → Markdown / 卡片 → Xiaojiu 会话
39
- ```
40
-
41
- 每个 scope 同时最多运行一个任务;全局子进程池默认最多 10 个运行,范围为 1–50。共享服务器可托管多个 profile,并按 App ID 分发事件。
42
-
43
- ## 快速开始
44
-
45
- ### 环境要求
46
-
47
- - Node.js `>= 20.12.0`
48
- - pnpm `10`(源码开发)
49
- - 已安装并登录至少一个本地 Agent:`claude`、`codex`、`pi`、`opencode` 或 `omp`
50
- - 一个 Xiaojiu Bot,以及 Xiaojiu 能访问的 HTTP/HTTPS 回调地址
51
-
52
- ### 安装与构建
53
-
54
- 从 npm 安装稳定版:
55
-
56
- ```bash
57
- npm install -g @saltpub/xiaojiu-agent-bridge
58
- ```
59
-
60
- 源码开发:
61
-
62
- ```bash
63
- pnpm install
64
- pnpm typecheck
65
- pnpm build
66
- npm install -g .
67
- ```
68
-
69
-
70
- ### 启动第一个 profile
71
-
72
- 把占位符换成你的 Bot 凭据与 Bot Owner 工号:
73
-
74
- ```bash
75
- xiaojiu-agent-bridge run \
76
- --app-id <app-id> \
77
- --app-secret <app-secret> \
78
- --owner <staff-no>
79
- ```
80
-
81
- 启动后在 Xiaojiu 私聊 Bot 发送 `/status`,即可确认 profile、Agent、工作目录和运行状态。平台地址、凭据、事件订阅与回调安全见 [`docs/xiaojiu.md`](./docs/xiaojiu.md)。
82
-
83
- ## 多 profile 与服务
84
-
85
- 需要在同一台机器上管理多个 Agent 时,先创建 profile:
86
-
87
- ```bash
88
- xiaojiu-agent-bridge profile create claude --agent claude --owner <staff-no>
89
- xiaojiu-agent-bridge profile create codex --agent codex --owner <staff-no>
90
- xiaojiu-agent-bridge profile list
91
- xiaojiu-agent-bridge profile use claude
92
- ```
93
-
94
- 一次 `start` / `run` 只上线一个 bot。默认共用 9699 时,第二个 `start --profile` 会加入已有监听,而不是再起一套服务。用 `ps` 查看各进程的端口和在线 bot。
95
-
96
- ```bash
97
- xiaojiu-agent-bridge start
98
- xiaojiu-agent-bridge start --profile codex
99
- xiaojiu-agent-bridge ps
100
- xiaojiu-agent-bridge status
101
- xiaojiu-agent-bridge stop
102
- ```
103
-
104
- 需要本机网页时加 `--web-ui`。`start` 会按操作系统注册服务:macOS 使用 launchd,Linux 使用 systemd,Windows 使用任务计划程序。也可以用 `kill <id|pid|#>` 停止指定进程。
105
-
106
- ## Xiaojiu 内命令
107
-
108
- | 命令 | 作用 |
109
- | --- | --- |
110
- | `/new`、`/reset` | 清空当前会话 |
111
- | `/status` | 查看 profile、Agent、工作目录和运行状态 |
112
- | `/agent <claude\|codex\|pi\|opencode\|omp>` | 空闲时切换当前 profile 的 Agent |
113
- | `/cd <path>` | 切换工作目录并重置会话(路径会发进当前聊天;也可在本机 Web 控制台按会话绑定) |
114
- | `/ws list`、`/ws save <name>`、`/ws use <name>` | 管理当前会话的命名工作空间 |
115
- | `/resume`、`/resume previous` | 查看兼容历史;恢复当前 scope 的上一归档会话(群内不展示详情) |
116
- | `/invite user @某人` | 允许用户私聊使用 |
117
- | `/invite admin @某人` | 添加管理员 |
118
- | `/invite group` | 允许当前群或频道使用 |
119
- | `/remove user @某人`、`/remove admin @某人`、`/remove group` | 移除访问资格 |
120
- | `/stop` | 停止当前任务 |
121
- | `/timeout [N\|off\|default]` | 调整当前会话超时 |
122
- | `/doctor [描述]` | 执行低敏诊断 |
123
- | `/help` | 显示帮助 |
124
-
125
- ## 配置与安全
126
-
127
- 默认配置目录为 `~/.xiaojiu-agent-bridge`,可通过 `XIAOJIU_BRIDGE_HOME` 修改。Webhook 默认监听 `0.0.0.0:9699`,默认 profile 回调路径为 `/webhook/<profile>`。
128
-
129
- 生产部署请使用 HTTPS、不可猜测的回调路径、`header.appId` 校验和反向代理访问控制。不要把 App Secret、回调密钥、访问令牌或原始 prompt 写进配置、日志或聊天。
130
-
131
- 密钥由 bridge 加密存储;如需迁移 profile,可使用 `profile export`,并谨慎处理包含 secrets 的导出内容。
132
-
133
- 长会话会省略重复指令;长时间空闲且输入用量较大时,用近期对话重建上下文。Bot/群指令更新也会建立新会话,避免旧规则残留;可用 `/resume previous` 恢复上一归档。长期笔记按 workspace 共享,存放于 profile 内部,不修改工作区文件。参数与并发边界见 [`docs/runtime/context-management.md`](./docs/runtime/context-management.md)。
134
-
135
- ## 版本更新
136
-
137
- CLI 在交互式终端中每 24 小时检查一次 npm Registry,不阻塞命令启动。为避免干扰首次配置或交互式界面,提示只会在支持的终端会话中显示。手动升级展示稳定版的 What's new,再从同一个官方 npm registry 安装展示的精确版本;registry 不可用或返回无效数据时明确报错,不再当作“已经最新”。
138
-
139
- ```bash
140
- xiaojiu-agent-bridge update
141
- xiaojiu-agent-bridge update --check
142
- xiaojiu-agent-bridge changelog
143
- ```
144
-
145
- `update` 不会打断进行中的会话:有会话在跑时直接拒绝,等会话结束后再执行。没有会话时,daemon 托管的安装会自动停止后台服务 → 安装新版本 → 重新拉起服务;前台 `run` 和控制台进程仍需先手动停止。自更新仅用于全局 npm 安装:npx 缓存和源码目录会给出对应的更新方式,不会悄悄另装一个全局副本。`update --check` 只查询,不安装、不停止进程。
146
-
147
- 设置 `XIAOJIU_BRIDGE_NO_UPDATE_CHECK=1` 可以关闭自动检查。CI、非交互终端和管道输出不会显示更新提示。
148
-
149
- ## 开发验证
150
-
151
- ```bash
152
- pnpm vitest run tests/unit/channel tests/integration/channel
153
- pnpm typecheck
154
- pnpm test
155
- pnpm build
156
- ```
157
-
158
- 没有真实 Xiaojiu 凭据时,只能验证本地契约和模拟 HTTP 流程。发布包只包含 `dist`、`bin`、`README.md`、`CHANGELOG.md` 与 `LICENSE`;平台级接入资料保留在 [`docs/xiaojiu.md`](./docs/xiaojiu.md)。
159
-
160
- ## 边界
161
-
162
- 会议智能体、云文档评论、账号切换和 WebSocket 重连等上游能力已从本项目移除,不支持对应命令或流程。本项目不包含独立后端、数据库或面向 Xiaojiu 用户的前端;`web/` 只构建本机管理控制台。
163
-
164
- ## License
165
-
166
- MIT。原项目许可证保留在 [`LICENSE`](./LICENSE)。
1
+ <p align="center">
2
+ <img src="./assets/readme/hero.gif" width="100%" alt="Xiaojiu Agent Bridge routes a Xiaojiu message through the local bridge runtime to one of five local coding-agent CLIs and returns the reply to the same Xiaojiu session">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <sub>静态 SVG 回退:Xiaojiu 消息 → 本机 CLI Agent → 回到同一会话 · <a href="./assets/readme/hero.svg">查看完整路由图</a></sub>
7
+ </p>
8
+
9
+ # xiaojiu-agent-bridge
10
+
11
+ 在 Xiaojiu 里发一句私聊或群内 `@` 消息,让本机的 Claude Code、Codex CLI、Pi、OpenCode 或 OMP 在指定工作目录执行;Markdown 或卡片结果回到同一个会话。
12
+
13
+ > 本地优先的消息桥:不自建后端,把 Xiaojiu 的聊天入口接到你已经安装好的 coding-agent CLI。
14
+
15
+ ## 你会得到什么
16
+
17
+ - **从聊天开始**:接收 `message_receive` 与 `card_action_trigger` Webhook,快速确认后异步处理。
18
+ - **会话不丢上下文**:按聊天 / 话题 scope 保存 Agent 会话、工作目录与运行状态。
19
+ - **一套入口,多种 Agent**:统一适配 Claude Code、Codex CLI、Pi、OpenCode 和 OMP。
20
+ - **可控地运行**:合并连续输入,执行访问控制、超时、中断、恢复和附件缓存。
21
+ - **结果回到原处**:以 Markdown 或消息卡片回复;流式输出通过更新消息模拟。
22
+ - **团队可管理**:用 profile、后台服务和本机 Web 控制台管理多套 Bot 配置。
23
+
24
+ ## 先看一条消息的完整路径
25
+
26
+ 下面是项目机制示意,不是生产环境截图:
27
+
28
+ ```text
29
+ Xiaojiu Webhook
30
+ │ message_receive / card_action_trigger
31
+ ▼
32
+ HTTP 校验 · header.id 去重 · 立即 200
33
+ ▼
34
+ 消息合并 · scope · 运行策略 · 工作目录
35
+ ▼
36
+ RunExecutor → AgentAdapter → 本机 CLI 子进程
37
+ ▼
38
+ RunState → Markdown / 卡片 → Xiaojiu 会话
39
+ ```
40
+
41
+ 每个 scope 同时最多运行一个任务;全局子进程池默认最多 10 个运行,范围为 1–50。共享服务器可托管多个 profile,并按 App ID 分发事件。
42
+
43
+ ## 快速开始
44
+
45
+ ### 环境要求
46
+
47
+ - Node.js `>= 20.12.0`
48
+ - pnpm `10`(源码开发)
49
+ - 已安装并登录至少一个本地 Agent:`claude`、`codex`、`pi`、`opencode` 或 `omp`
50
+ - 一个 Xiaojiu Bot,以及 Xiaojiu 能访问的 HTTP/HTTPS 回调地址
51
+
52
+ ### 安装与构建
53
+
54
+ 从 npm 安装稳定版:
55
+
56
+ ```bash
57
+ npm install -g @saltpub/xiaojiu-agent-bridge
58
+ ```
59
+
60
+ 源码开发:
61
+
62
+ ```bash
63
+ pnpm install
64
+ pnpm typecheck
65
+ pnpm build
66
+ npm install -g .
67
+ ```
68
+
69
+
70
+ ### 启动第一个 profile
71
+
72
+ 把占位符换成你的 Bot 凭据与 Bot Owner 工号:
73
+
74
+ ```bash
75
+ xiaojiu-agent-bridge run \
76
+ --app-id <app-id> \
77
+ --app-secret <app-secret> \
78
+ --owner <staff-no>
79
+ ```
80
+
81
+ 启动后在 Xiaojiu 私聊 Bot 发送 `/status`,即可确认 profile、Agent、工作目录和运行状态。平台地址、凭据、事件订阅与回调安全见 [`docs/xiaojiu.md`](./docs/xiaojiu.md)。
82
+
83
+ ## 多 profile 与服务
84
+
85
+ 需要在同一台机器上管理多个 Agent 时,先创建 profile:
86
+
87
+ ```bash
88
+ xiaojiu-agent-bridge profile create claude --agent claude --owner <staff-no>
89
+ xiaojiu-agent-bridge profile create codex --agent codex --owner <staff-no>
90
+ xiaojiu-agent-bridge profile list
91
+ xiaojiu-agent-bridge profile use claude
92
+ ```
93
+
94
+ 一次 `start` / `run` 只上线一个 bot。默认共用 9699 时,第二个 `start --profile` 会加入已有监听,而不是再起一套服务。用 `ps` 查看各进程的端口和在线 bot。
95
+
96
+ ```bash
97
+ xiaojiu-agent-bridge start
98
+ xiaojiu-agent-bridge start --profile codex
99
+ xiaojiu-agent-bridge ps
100
+ xiaojiu-agent-bridge status
101
+ xiaojiu-agent-bridge stop
102
+ ```
103
+
104
+ 需要本机网页时加 `--web-ui`。`start` 会按操作系统注册服务:macOS 使用 launchd,Linux 使用 systemd,Windows 使用任务计划程序。也可以用 `kill <id|pid|#>` 停止指定进程。
105
+
106
+ ## Xiaojiu 内命令
107
+
108
+ | 命令 | 作用 |
109
+ | --- | --- |
110
+ | `/new`、`/reset` | 清空当前会话 |
111
+ | `/status` | 查看 profile、Agent、工作目录和运行状态 |
112
+ | `/btw [问题]` | 向正在跑的任务旁路提问:用会话上下文回答、不执行工具、不写入历史 |
113
+ | `/agent <claude\|codex\|pi\|opencode\|omp>` | 空闲时切换当前 profile 的 Agent |
114
+ | `/cd <path>` | 切换工作目录并重置会话(路径会发进当前聊天;也可在本机 Web 控制台按会话绑定) |
115
+ | `/ws list`、`/ws save <name>`、`/ws use <name>` | 管理当前会话的命名工作空间 |
116
+ | `/resume`、`/resume previous` | 查看兼容历史;恢复当前 scope 的上一归档会话(群内不展示详情) |
117
+ | `/invite user @某人` | 允许用户私聊使用 |
118
+ | `/invite admin @某人` | 添加管理员 |
119
+ | `/invite group` | 允许当前群或频道使用 |
120
+ | `/remove user @某人`、`/remove admin @某人`、`/remove group` | 移除访问资格 |
121
+ | `/stop` | 停止当前任务 |
122
+ | `/timeout [N\|off\|default]` | 调整当前会话超时 |
123
+ | `/doctor [描述]` | 执行低敏诊断 |
124
+ | `/help` | 显示帮助 |
125
+
126
+ ## 配置与安全
127
+
128
+ 默认配置目录为 `~/.xiaojiu-agent-bridge`,可通过 `XIAOJIU_BRIDGE_HOME` 修改。Webhook 默认监听 `0.0.0.0:9699`,默认 profile 回调路径为 `/webhook/<profile>`。
129
+
130
+ 生产部署请使用 HTTPS、不可猜测的回调路径、`header.appId` 校验和反向代理访问控制。不要把 App Secret、回调密钥、访问令牌或原始 prompt 写进配置、日志或聊天。
131
+
132
+ 密钥由 bridge 加密存储;如需迁移 profile,可使用 `profile export`,并谨慎处理包含 secrets 的导出内容。
133
+
134
+ 长会话会省略重复指令;长时间空闲且输入用量较大时,用近期对话重建上下文。Bot/群指令更新也会建立新会话,避免旧规则残留;可用 `/resume previous` 恢复上一归档。长期笔记按 workspace 共享,存放于 profile 内部,不修改工作区文件。参数与并发边界见 [`docs/runtime/context-management.md`](./docs/runtime/context-management.md)。
135
+
136
+ ## 版本更新
137
+
138
+ CLI 在交互式终端中每 24 小时检查一次 npm Registry,不阻塞命令启动。为避免干扰首次配置或交互式界面,提示只会在支持的终端会话中显示。手动升级展示稳定版的 What's new,再从同一个官方 npm registry 安装展示的精确版本;registry 不可用或返回无效数据时明确报错,不再当作“已经最新”。
139
+
140
+ ```bash
141
+ xiaojiu-agent-bridge update
142
+ xiaojiu-agent-bridge update --check
143
+ xiaojiu-agent-bridge changelog
144
+ ```
145
+
146
+ `update` 不会打断进行中的会话:有会话在跑时直接拒绝,等会话结束后再执行。没有会话时,daemon 托管的安装会自动停止后台服务 → 安装新版本 → 重新拉起服务;前台 `run` 和控制台进程仍需先手动停止。自更新仅用于全局 npm 安装:npx 缓存和源码目录会给出对应的更新方式,不会悄悄另装一个全局副本。`update --check` 只查询,不安装、不停止进程。
147
+
148
+ 设置 `XIAOJIU_BRIDGE_NO_UPDATE_CHECK=1` 可以关闭自动检查。CI、非交互终端和管道输出不会显示更新提示。
149
+
150
+ ## 开发验证
151
+
152
+ ```bash
153
+ pnpm vitest run tests/unit/channel tests/integration/channel
154
+ pnpm typecheck
155
+ pnpm test
156
+ pnpm build
157
+ ```
158
+
159
+ 没有真实 Xiaojiu 凭据时,只能验证本地契约和模拟 HTTP 流程。发布包只包含 `dist`、`bin`、`README.md`、`CHANGELOG.md` 与 `LICENSE`;平台级接入资料保留在 [`docs/xiaojiu.md`](./docs/xiaojiu.md)。
160
+
161
+ ## 边界
162
+
163
+ 会议智能体、云文档评论、账号切换和 WebSocket 重连等上游能力已从本项目移除,不支持对应命令或流程。本项目不包含独立后端、数据库或面向 Xiaojiu 用户的前端;`web/` 只构建本机管理控制台。
164
+
165
+ ## License
166
+
167
+ MIT。原项目许可证保留在 [`LICENSE`](./LICENSE)。