@tt-a1i/hive 2.1.10 → 2.1.12

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 (69) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +13 -11
  3. package/README.zh.md +9 -8
  4. package/dist/src/cli/hive-defaults.d.ts +1 -0
  5. package/dist/src/cli/hive-defaults.js +1 -0
  6. package/dist/src/cli/hive-mcp.d.ts +62 -0
  7. package/dist/src/cli/hive-mcp.js +254 -0
  8. package/dist/src/cli/hive.d.ts +2 -0
  9. package/dist/src/cli/hive.js +12 -2
  10. package/dist/src/cli/team.d.ts +8 -0
  11. package/dist/src/cli/team.js +100 -0
  12. package/dist/src/server/agent-runtime-contract.d.ts +1 -0
  13. package/dist/src/server/agent-runtime.js +4 -0
  14. package/dist/src/server/agent-startup-instructions.js +1 -1
  15. package/dist/src/server/command-preset-defaults.d.ts +1 -1
  16. package/dist/src/server/command-preset-defaults.js +10 -0
  17. package/dist/src/server/diagnostics-support-bundle.d.ts +1 -1
  18. package/dist/src/server/external-goal-auth.d.ts +1 -0
  19. package/dist/src/server/external-goal-auth.js +1 -0
  20. package/dist/src/server/external-goal-bridge.d.ts +103 -0
  21. package/dist/src/server/external-goal-bridge.js +299 -0
  22. package/dist/src/server/external-goal-store.d.ts +59 -0
  23. package/dist/src/server/external-goal-store.js +165 -0
  24. package/dist/src/server/hive-team-guidance.js +1 -0
  25. package/dist/src/server/post-start-input-writer.js +28 -7
  26. package/dist/src/server/route-types.d.ts +30 -0
  27. package/dist/src/server/routes-external-goals.d.ts +2 -0
  28. package/dist/src/server/routes-external-goals.js +184 -0
  29. package/dist/src/server/routes-runtime.js +6 -1
  30. package/dist/src/server/routes-team-goals.d.ts +2 -0
  31. package/dist/src/server/routes-team-goals.js +60 -0
  32. package/dist/src/server/routes.js +4 -0
  33. package/dist/src/server/runtime-store-contract.d.ts +11 -0
  34. package/dist/src/server/runtime-store-external-goals.d.ts +47 -0
  35. package/dist/src/server/runtime-store-external-goals.js +24 -0
  36. package/dist/src/server/runtime-store-helpers.d.ts +3 -0
  37. package/dist/src/server/runtime-store-helpers.js +11 -1
  38. package/dist/src/server/runtime-store.js +6 -0
  39. package/dist/src/server/sqlite-schema-v37.d.ts +2 -0
  40. package/dist/src/server/sqlite-schema-v37.js +38 -0
  41. package/dist/src/server/sqlite-schema-v38.d.ts +2 -0
  42. package/dist/src/server/sqlite-schema-v38.js +26 -0
  43. package/dist/src/server/sqlite-schema.d.ts +1 -1
  44. package/dist/src/server/sqlite-schema.js +46 -1
  45. package/dist/src/server/team-authz.d.ts +1 -1
  46. package/dist/src/server/team-authz.js +1 -0
  47. package/dist/src/server/ui-auth.d.ts +2 -0
  48. package/dist/src/server/ui-auth.js +7 -0
  49. package/dist/src/server/workflow-cli-policy.d.ts +1 -1
  50. package/dist/src/server/workflow-cli-policy.js +1 -0
  51. package/package.json +3 -3
  52. package/web/dist/assets/{AddWorkerDialog-Dc0slXtx.js → AddWorkerDialog-BA0p5Pcr.js} +2 -2
  53. package/web/dist/assets/{AddWorkspaceFlow-AyzSdx5w.js → AddWorkspaceFlow-YO-HxdrH.js} +1 -1
  54. package/web/dist/assets/{FirstRunWizard-DGB5zWhl.js → FirstRunWizard-C5iyX5QF.js} +1 -1
  55. package/web/dist/assets/{MarketplaceDrawer-DAZ-crqq.js → MarketplaceDrawer-BIyJIDK4.js} +1 -1
  56. package/web/dist/assets/{TaskGraphDrawer-DYk-0uKD.js → TaskGraphDrawer-C0eOFQ8c.js} +1 -1
  57. package/web/dist/assets/{WhatsNewDialog-B5tu3MV2.js → WhatsNewDialog-Ci9pUKEP.js} +1 -1
  58. package/web/dist/assets/{WorkerModal-C73K7SUg.js → WorkerModal-DXHUZSN-.js} +1 -1
  59. package/web/dist/assets/WorkflowsDrawer-C5cS2jKY.js +1 -0
  60. package/web/dist/assets/{WorkspaceMemoryDrawer-CCz3HB4F.js → WorkspaceMemoryDrawer-BsAoM-lK.js} +1 -1
  61. package/web/dist/assets/{WorkspaceTaskDrawer-C7JzoRp8.js → WorkspaceTaskDrawer-rLaXBrNl.js} +1 -1
  62. package/web/dist/assets/index-CTJnf-r_.js +84 -0
  63. package/web/dist/assets/{search-Bx1xfpzr.js → search-CbyBNPSq.js} +1 -1
  64. package/web/dist/assets/{square-terminal-Dfr9QC1I.js → square-terminal-eIii6bbw.js} +1 -1
  65. package/web/dist/index.html +1 -1
  66. package/web/dist/manifest.webmanifest +1 -1
  67. package/web/dist/sw.js +1 -1
  68. package/web/dist/assets/WorkflowsDrawer-mrSAPqAh.js +0 -1
  69. package/web/dist/assets/index-CVQc8PLJ.js +0 -84
package/CHANGELOG.md CHANGED
@@ -2,6 +2,37 @@
2
2
 
3
3
  All notable user-facing changes will be documented in this file.
4
4
 
5
+ ## 2.1.12 - 2026-06-25
6
+
7
+ Default port and Pi agent support.
8
+
9
+ - Changes Hive's default local runtime port from `3000` to `9483`, reducing
10
+ collisions with common local development services while keeping `--port 0`
11
+ available for OS-assigned ports.
12
+ - Updates the local Supervisor MCP adapter and Vite dev proxy to follow the
13
+ same default port.
14
+ - Adds Pi as a built-in agent preset with `pi --approve`, including workflow
15
+ CLI policy support, prompt-readiness handling, and migration support for
16
+ existing Hive databases.
17
+
18
+ ## 2.1.11 - 2026-06-25
19
+
20
+ Supervisor MCP bridge and terminal input polish.
21
+
22
+ - Adds a local Supervisor MCP adapter so external agents such as Codex App,
23
+ Claude, or Hermes can hand a goal to the Hive Orchestrator and wait on
24
+ durable structured goal events.
25
+ - Adds `team goal report` for Orchestrators to report external goal progress,
26
+ completion, blocked states, or failures without giving external supervisors
27
+ direct member or PTY control.
28
+ - Keeps the Supervisor MCP surface intentionally narrow: list/inspect
29
+ workspaces, start/wait/continue/cancel goals, with no direct member spawn,
30
+ member send, raw scrollback, or PTY write tools.
31
+ - Improves OpenCode prompt readiness detection for completed turns and
32
+ interrupt-status screens, making post-start input delivery more reliable.
33
+ - Preserves Codex prompt edit repaint frames after Backspace/Delete-style input,
34
+ so terminal editing stays visually in sync.
35
+
5
36
  ## 2.1.10 - 2026-06-23
6
37
 
7
38
  Scenario teams and terminal delivery polish.
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <img src="./assets/hive-hero.png" alt="Hive local-first multi-agent collaboration workspace hero image" />
9
9
  </p>
10
10
 
11
- **Run Claude Code, Codex, Gemini, OpenCode, Qwen, and other CLI agents as a visible local team.** Hive gives you one browser workbench where an
11
+ **Run Claude Code, Codex, Gemini, OpenCode, Qwen, Pi, and other CLI agents as a visible local team.** Hive gives you one browser workbench where an
12
12
  Orchestrator plans and delegates while workers implement, review, test,
13
13
  research, and report back — all as real PTY processes on your laptop.
14
14
 
@@ -48,7 +48,7 @@ awkward:
48
48
 
49
49
  Hive adds the coordination layer without replacing the CLIs. The Orchestrator
50
50
  is a real `agy` / `claude` / `codex` / `opencode` / `gemini` / `hermes` /
51
- `qwen` process, not a scripted PM. Workers are real CLI agents too. Hive
51
+ `qwen` / `pi` process, not a scripted PM. Workers are real CLI agents too. Hive
52
52
  injects a small `team` command into their shells, so they can dispatch,
53
53
  report, and keep a shared markdown task graph at `<workspace>/.hive/tasks.md`.
54
54
 
@@ -117,8 +117,8 @@ Those warnings usually come from npm's install-script review plus native
117
117
  binary setup for `node-pty`, `better-sqlite3`, and `esbuild`; they do not mean
118
118
  Hive failed to install. The troubleshooting section below breaks them down.
119
119
 
120
- Open the printed local URL, usually `http://127.0.0.1:3000/`. Use
121
- `hive --port 4010` when you need a specific local port.
120
+ Open the printed local URL, usually `http://127.0.0.1:9483/`. Use
121
+ `hive --port 0` when you want Hive to ask the OS for any free local port.
122
122
 
123
123
  To upgrade in place:
124
124
 
@@ -133,7 +133,7 @@ npm copy will shadow your existing install.
133
133
 
134
134
  Install Hive as an app (optional):
135
135
 
136
- Open `http://127.0.0.1:3000/` in Chrome, Edge, or Brave and click the install
136
+ Open `http://127.0.0.1:9483/` in Chrome, Edge, or Brave and click the install
137
137
  icon at the right edge of the browser's omnibox. The PWA launches in its own
138
138
  dock-anchored window without browser chrome and shows **Add Workspace** /
139
139
  **Try Demo** shortcuts from the dock right-click menu. Firefox and Safari
@@ -143,8 +143,8 @@ only appears in Chromium-based browsers.
143
143
  The Hive daemon must still be running for the PWA to do anything; if the
144
144
  runtime isn't reachable when you launch the app, you'll see a "Hive runtime
145
145
  is not running" page that auto-reloads once `hive` is back on `127.0.0.1`.
146
- The PWA install scope is keyed by origin, so `hive --port 4011` installs as
147
- a separate app from `hive --port 3000`. To uninstall, visit `chrome://apps`,
146
+ The PWA install scope is keyed by origin, so `hive --port 9484` installs as
147
+ a separate app from `hive --port 9483`. To uninstall, visit `chrome://apps`,
148
148
  right-click the Hive tile, and choose **Remove from Chrome…**.
149
149
 
150
150
  Hive asks the browser to confirm before closing the tab or PWA window so an
@@ -220,6 +220,7 @@ Three details matter:
220
220
  | Gemini | `gemini` | `--yolo` | `--resume <session_id>` |
221
221
  | Hermes | `hermes` | `--yolo` | `--resume <session_id>` |
222
222
  | Qwen Code | `qwen` | `--approval-mode yolo` | `--resume <session_id>` |
223
+ | Pi | `pi` | `--approve` | Session id capture not wired yet |
223
224
  | Cursor CLI | `cursor` | `--force` | Session id capture not wired yet |
224
225
  | Grok Build | `grok` | `--always-approve` | Session id capture not wired yet |
225
226
  | Custom | Any executable | User configured | User configured |
@@ -232,7 +233,7 @@ same shell environment you use to start Hive.
232
233
  | Tier | CLIs | Commitment |
233
234
  | --- | --- | --- |
234
235
  | Tier 1 | Claude Code, Codex | Minimum compatibility report in CI (`pnpm compat:cli:report`): Node 22, `node-pty`, `better-sqlite3`, and CLI version detection when installed. |
235
- | Tier 2 | Gemini, OpenCode, Qwen Code, Hermes, Cursor CLI, Grok Build, Antigravity CLI | Built-in presets and manual smoke coverage; upstream CLI changes may require user reports before Hive catches up. |
236
+ | Tier 2 | Gemini, OpenCode, Qwen Code, Hermes, Pi, Cursor CLI, Grok Build, Antigravity CLI | Built-in presets and manual smoke coverage; upstream CLI changes may require user reports before Hive catches up. |
236
237
  | Custom | Any executable | User-maintained command, args, and auth behavior. Hive preserves the PTY/session wrapper but cannot promise CLI-specific compatibility. |
237
238
 
238
239
  ## What Hive Provides
@@ -250,7 +251,8 @@ same shell environment you use to start Hive.
250
251
  - Workflow CLI policy: choose the default CLI for workflow-created agents and
251
252
  restrict which CLIs workflow scripts may launch.
252
253
  - `.hive/tasks.md` editor with external-file conflict handling.
253
- - Background PTY preservation and best-effort native session resume.
254
+ - Background PTY preservation and best-effort native session resume for presets with
255
+ configured session capture.
254
256
  - A What's New dialog after upgrades with curated release highlights.
255
257
  - Local SQLite metadata under `%APPDATA%\hive` on Windows and `~/.config/hive`
256
258
  on macOS / Linux by default, or `$HIVE_DATA_DIR` when set.
@@ -404,7 +406,7 @@ pnpm install
404
406
  pnpm dev
405
407
  ```
406
408
 
407
- Development mode runs the runtime on `127.0.0.1:4010`; Vite runs on
409
+ Development mode runs the runtime on `127.0.0.1:9483`; Vite runs on
408
410
  `127.0.0.1:5180` and proxies API and WebSocket traffic to the runtime.
409
411
 
410
412
  Useful checks:
@@ -419,7 +421,7 @@ Production-style local run:
419
421
 
420
422
  ```bash
421
423
  pnpm build
422
- node dist/src/cli/hive.js --port 4010
424
+ node dist/src/cli/hive.js --port 9483
423
425
  ```
424
426
 
425
427
  The production server serves the built web UI directly. No Vite server is
package/README.zh.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <img src="./assets/hive-hero.png" alt="Hive 本机多 agent 协作工作台" />
9
9
  </p>
10
10
 
11
- **Hive 是浏览器里的 Agent 协作工作台——一群 Agent 在你本机各自开工,一个当 Orchestrator 派活、归总进展,其余各司其职。** Orchestrator 本身就是一个真实的 `agy` / `claude` / `codex` / `opencode` / `gemini` / `hermes` / `qwen` 进程——不是你、也不是脚本——它派单的 Worker 同样是真 CLI agent。所有 agent 都是本机真实的 PTY 进程,通过 Hive 注入到 shell 里的小型 `team` 协议互相通信,共享 `<workspace>/.hive/tasks.md` 这份 markdown 任务图。
11
+ **Hive 是浏览器里的 Agent 协作工作台——一群 Agent 在你本机各自开工,一个当 Orchestrator 派活、归总进展,其余各司其职。** Orchestrator 本身就是一个真实的 `agy` / `claude` / `codex` / `opencode` / `gemini` / `hermes` / `qwen` / `pi` 进程——不是你、也不是脚本——它派单的 Worker 同样是真 CLI agent。所有 agent 都是本机真实的 PTY 进程,通过 Hive 注入到 shell 里的小型 `team` 协议互相通信,共享 `<workspace>/.hive/tasks.md` 这份 markdown 任务图。
12
12
 
13
13
  写代码、做调研、起草文档、做翻译——凡是能拆给一群人协作的脑力活,都可以让一群 Agent 合伙干。
14
14
 
@@ -94,7 +94,7 @@ npm install -g @tt-a1i/hive --registry=https://registry.npmmirror.com
94
94
 
95
95
  安装时如果看到 `npm warn allow-scripts` 或 `prebuild-install@7.1.3 deprecated`,先看最后是否显示 `added ... packages`。这些 warning 多数来自 npm 对安装脚本的安全审查,以及 `node-pty` / `better-sqlite3` / `esbuild` 这类原生依赖的二进制安装链路;不代表 Hive 启动失败。下面的故障排查里有逐项解释。
96
96
 
97
- 打开终端打印出来的本机地址,通常是 `http://127.0.0.1:3000/`。如果你想指定端口,可以用 `hive --port 4010`。
97
+ 打开终端打印出来的本机地址,通常是 `http://127.0.0.1:9483/`。如果你想让系统自动分配一个空闲端口,可以用 `hive --port 0`。
98
98
 
99
99
  升级到最新版本:
100
100
 
@@ -106,9 +106,9 @@ hive update
106
106
 
107
107
  把 Hive 装为应用(可选):
108
108
 
109
- 在 Chrome / Edge / Brave 里打开 `http://127.0.0.1:3000/`,点浏览器地址栏右侧的安装图标即可。装好后 Hive 会以独立窗口启动、有自己的 dock 图标,且 dock 右键菜单上会显示 **添加 Workspace** / **试用演示** 两个快捷入口。Firefox 和 Safari 暂未实现 PWA install-prompt 协议,浏览器地址栏的安装图标只在 Chromium 系浏览器里出现。
109
+ 在 Chrome / Edge / Brave 里打开 `http://127.0.0.1:9483/`,点浏览器地址栏右侧的安装图标即可。装好后 Hive 会以独立窗口启动、有自己的 dock 图标,且 dock 右键菜单上会显示 **添加 Workspace** / **试用演示** 两个快捷入口。Firefox 和 Safari 暂未实现 PWA install-prompt 协议,浏览器地址栏的安装图标只在 Chromium 系浏览器里出现。
110
110
 
111
- PWA 只是 UI 壳,Hive 后端仍需要在终端里跑着。如果启动 PWA 时后端没起,会看到 “Hive 后端未启动” 页面,等你跑起 `hive` 后会自动刷新。PWA 的 install scope 按 origin(含端口)划分,所以 `hive --port 4011` 跟 `hive --port 3000` 在浏览器看来是两个独立应用。卸载方法:浏览器地址栏访问 `chrome://apps`,右键 Hive 图标,选 **从 Chrome 中移除…**。
111
+ PWA 只是 UI 壳,Hive 后端仍需要在终端里跑着。如果启动 PWA 时后端没起,会看到 “Hive 后端未启动” 页面,等你跑起 `hive` 后会自动刷新。PWA 的 install scope 按 origin(含端口)划分,所以 `hive --port 9484` 跟 `hive --port 9483` 在浏览器看来是两个独立应用。卸载方法:浏览器地址栏访问 `chrome://apps`,右键 Hive 图标,选 **从 Chrome 中移除…**。
112
112
 
113
113
  关闭 PWA 窗口或 tab 时 Hive 会主动请求浏览器弹原生确认对话框,避免关闭快捷键(macOS 上是 Cmd+W、Windows / Linux 上是 Ctrl+W)误关丢失会话。但现代浏览器要求你跟页面"交互过"(点击 / 滚动 / 输入)才会真的弹这个对话框——刚打开 PWA 立刻按关闭快捷键仍会直接关闭,这是浏览器策略,不是 Hive 的 bug。
114
114
 
@@ -165,6 +165,7 @@ Workspace 任务图:
165
165
  | Gemini | `gemini` | `--yolo` | `--resume <session_id>` |
166
166
  | Hermes | `hermes` | `--yolo` | `--resume <session_id>` |
167
167
  | Qwen Code | `qwen` | `--approval-mode yolo` | `--resume <session_id>` |
168
+ | Pi | `pi` | `--approve` | 暂未自动捕获 session id |
168
169
  | Cursor CLI | `cursor` | `--force` | 暂未自动捕获 session id |
169
170
  | Grok Build | `grok` | `--always-approve` | 暂未自动捕获 session id |
170
171
  | 自定义 | 任意可执行文件 | 自己配 | 自己配 |
@@ -176,7 +177,7 @@ Hive 不替你安装这些 CLI。请在启动 Hive 的同一个 shell 环境里
176
177
  | 分级 | CLI | 承诺 |
177
178
  | --- | --- | --- |
178
179
  | Tier 1 | Claude Code、Codex | CI 生成最小兼容报告(`pnpm compat:cli:report`):检查 Node 22、`node-pty`、`better-sqlite3`,并在本机已安装 CLI 时记录版本。 |
179
- | Tier 2 | Gemini、OpenCode、Qwen Code、Hermes、Cursor CLI、Grok Build、Antigravity CLI | 内置 preset + 手动 smoke 覆盖;上游 CLI 行为变化可能需要用户报告后再跟进。 |
180
+ | Tier 2 | Gemini、OpenCode、Qwen Code、Hermes、Pi、Cursor CLI、Grok Build、Antigravity CLI | 内置 preset + 手动 smoke 覆盖;上游 CLI 行为变化可能需要用户报告后再跟进。 |
180
181
  | Custom | 任意可执行命令 | 用户自己维护命令、参数和登录状态;Hive 只保证 PTY/session 包装,不承诺 CLI 专属兼容性。 |
181
182
 
182
183
  ## Hive 提供什么
@@ -188,7 +189,7 @@ Hive 不替你安装这些 CLI。请在启动 Hive 的同一个 shell 环境里
188
189
  - Workflows(实验性,默认关闭):Orchestrator 可以运行多阶段、多 agent 的 workflow,Hive 在 Workflows 面板里展示运行、日志、结果、定时任务和停止控制。
189
190
  - Workflow CLI 策略:为 workflow 创建的 agent 选择默认 CLI,并限制允许使用的 CLI,避免脚本误启未配置的 agent。
190
191
  - `.hive/tasks.md` 编辑器,带外部文件冲突处理。
191
- - PTY 后台保留 + 尽力使用各 CLI 原生 session 恢复。
192
+ - PTY 后台保留;对已配置 session capture 的预设,尽力使用对应 CLI 的原生 session 恢复。
192
193
  - 升级后的 What's New 弹窗,用简短 release highlights 告诉你新版改了什么。
193
194
  - 元数据存在本机 SQLite,Windows 默认在 `%APPDATA%\hive`,macOS / Linux 默认在 `~/.config/hive`,也可以通过 `$HIVE_DATA_DIR` 指定。
194
195
 
@@ -294,7 +295,7 @@ pnpm install
294
295
  pnpm dev
295
296
  ```
296
297
 
297
- 开发模式下 runtime 跑在 `127.0.0.1:4010`,Vite 跑在 `127.0.0.1:5180`,把 API 和 WebSocket 代理到 runtime。
298
+ 开发模式下 runtime 跑在 `127.0.0.1:9483`,Vite 跑在 `127.0.0.1:5180`,把 API 和 WebSocket 代理到 runtime。
298
299
 
299
300
  常用命令:
300
301
 
@@ -308,7 +309,7 @@ pnpm test
308
309
 
309
310
  ```bash
310
311
  pnpm build
311
- node dist/src/cli/hive.js --port 4010
312
+ node dist/src/cli/hive.js --port 9483
312
313
  ```
313
314
 
314
315
  Production 模式下 runtime 直接服务构建好的 web UI,不需要单独的 Vite。
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_HIVE_PORT = 9483;
@@ -0,0 +1 @@
1
+ export const DEFAULT_HIVE_PORT = 9483;
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+ export declare const HIVE_MCP_TOOL_NAMES: readonly ["hive.list_workspaces", "hive.inspect_workspace", "hive.start_goal", "hive.wait_goal", "hive.continue_goal", "hive.cancel_goal"];
3
+ export declare const HIVE_MCP_TOOLS: readonly [{
4
+ readonly name: "hive.list_workspaces";
5
+ readonly description: "List local Hive workspaces available for external Supervisor goals.";
6
+ readonly inputSchema: {
7
+ additionalProperties: boolean;
8
+ properties: Record<string, unknown>;
9
+ required: string[];
10
+ type: string;
11
+ };
12
+ }, {
13
+ readonly name: "hive.inspect_workspace";
14
+ readonly description: "Inspect a Hive workspace, its Orchestrator status, and member roster.";
15
+ readonly inputSchema: {
16
+ additionalProperties: boolean;
17
+ properties: Record<string, unknown>;
18
+ required: string[];
19
+ type: string;
20
+ };
21
+ }, {
22
+ readonly name: "hive.start_goal";
23
+ readonly description: "Start an external Supervisor goal by delivering it to the workspace Orchestrator.";
24
+ readonly inputSchema: {
25
+ additionalProperties: boolean;
26
+ properties: Record<string, unknown>;
27
+ required: string[];
28
+ type: string;
29
+ };
30
+ }, {
31
+ readonly name: "hive.wait_goal";
32
+ readonly description: "Wait for durable external goal events after a cursor, with a bounded timeout.";
33
+ readonly inputSchema: {
34
+ additionalProperties: boolean;
35
+ properties: Record<string, unknown>;
36
+ required: string[];
37
+ type: string;
38
+ };
39
+ }, {
40
+ readonly name: "hive.continue_goal";
41
+ readonly description: "Append context to an external goal and deliver it to the Orchestrator.";
42
+ readonly inputSchema: {
43
+ additionalProperties: boolean;
44
+ properties: Record<string, unknown>;
45
+ required: string[];
46
+ type: string;
47
+ };
48
+ }, {
49
+ readonly name: "hive.cancel_goal";
50
+ readonly description: "Cancel an external goal and notify the Orchestrator. Does not auto-cancel member dispatches.";
51
+ readonly inputSchema: {
52
+ additionalProperties: boolean;
53
+ properties: Record<string, unknown>;
54
+ required: string[];
55
+ type: string;
56
+ };
57
+ }];
58
+ export declare const callHiveMcpTool: (toolName: string, args?: Record<string, unknown>, input?: {
59
+ baseUrl?: string;
60
+ env?: NodeJS.ProcessEnv;
61
+ }) => Promise<unknown>;
62
+ export declare const runHiveMcpCommand: (argv?: string[], env?: NodeJS.ProcessEnv) => Promise<void>;
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/env node
2
+ import { createInterface } from 'node:readline';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { HIVE_SUPERVISOR_TOKEN_HEADER } from '../server/external-goal-auth.js';
5
+ import { readPackageVersion } from '../server/package-version.js';
6
+ import { sameFilesystemPath } from '../server/path-canonicalization.js';
7
+ import { DEFAULT_HIVE_PORT } from './hive-defaults.js';
8
+ export const HIVE_MCP_TOOL_NAMES = [
9
+ 'hive.list_workspaces',
10
+ 'hive.inspect_workspace',
11
+ 'hive.start_goal',
12
+ 'hive.wait_goal',
13
+ 'hive.continue_goal',
14
+ 'hive.cancel_goal',
15
+ ];
16
+ const jsonSchema = (properties, required = []) => ({
17
+ additionalProperties: false,
18
+ properties,
19
+ required,
20
+ type: 'object',
21
+ });
22
+ export const HIVE_MCP_TOOLS = [
23
+ {
24
+ name: 'hive.list_workspaces',
25
+ description: 'List local Hive workspaces available for external Supervisor goals.',
26
+ inputSchema: jsonSchema({}),
27
+ },
28
+ {
29
+ name: 'hive.inspect_workspace',
30
+ description: 'Inspect a Hive workspace, its Orchestrator status, and member roster.',
31
+ inputSchema: jsonSchema({
32
+ workspace_id: { type: 'string' },
33
+ }, ['workspace_id']),
34
+ },
35
+ {
36
+ name: 'hive.start_goal',
37
+ description: 'Start an external Supervisor goal by delivering it to the workspace Orchestrator.',
38
+ inputSchema: jsonSchema({
39
+ context: {},
40
+ goal: { type: 'string' },
41
+ timeout_hint_ms: { type: 'number' },
42
+ workspace_id: { type: 'string' },
43
+ }, ['workspace_id', 'goal']),
44
+ },
45
+ {
46
+ name: 'hive.wait_goal',
47
+ description: 'Wait for durable external goal events after a cursor, with a bounded timeout.',
48
+ inputSchema: jsonSchema({
49
+ cursor: { minimum: 0, type: 'integer' },
50
+ goal_id: { type: 'string' },
51
+ timeout_ms: { minimum: 0, type: 'number' },
52
+ }, ['goal_id']),
53
+ },
54
+ {
55
+ name: 'hive.continue_goal',
56
+ description: 'Append context to an external goal and deliver it to the Orchestrator.',
57
+ inputSchema: jsonSchema({
58
+ context: {},
59
+ goal_id: { type: 'string' },
60
+ message: { type: 'string' },
61
+ }, ['goal_id', 'message']),
62
+ },
63
+ {
64
+ name: 'hive.cancel_goal',
65
+ description: 'Cancel an external goal and notify the Orchestrator. Does not auto-cancel member dispatches.',
66
+ inputSchema: jsonSchema({
67
+ goal_id: { type: 'string' },
68
+ reason: { type: 'string' },
69
+ }, ['goal_id', 'reason']),
70
+ },
71
+ ];
72
+ const parseBaseUrl = (argv, env) => {
73
+ const index = argv.indexOf('--base-url');
74
+ if (index !== -1) {
75
+ const value = argv[index + 1];
76
+ if (!value)
77
+ throw new Error('--base-url requires a value');
78
+ return value.replace(/\/$/u, '');
79
+ }
80
+ if (env.HIVE_MCP_BASE_URL)
81
+ return env.HIVE_MCP_BASE_URL.replace(/\/$/u, '');
82
+ if (env.HIVE_PORT)
83
+ return `http://127.0.0.1:${env.HIVE_PORT}`;
84
+ return `http://127.0.0.1:${DEFAULT_HIVE_PORT}`;
85
+ };
86
+ const readHttpErrorDetail = async (response) => {
87
+ const text = await response.text().catch(() => '');
88
+ if (!text.trim())
89
+ return `HTTP ${response.status}`;
90
+ try {
91
+ const parsed = JSON.parse(text);
92
+ if (typeof parsed.error === 'string')
93
+ return parsed.error;
94
+ }
95
+ catch {
96
+ return text.trim();
97
+ }
98
+ return text.trim();
99
+ };
100
+ const getSupervisorToken = async (baseUrl) => {
101
+ const response = await fetch(`${baseUrl}/api/external-goals/session`);
102
+ if (!response.ok)
103
+ throw new Error(await readHttpErrorDetail(response));
104
+ const body = (await response.json());
105
+ if (typeof body.token !== 'string' || body.token.length === 0) {
106
+ throw new Error('Hive runtime did not issue a Supervisor token');
107
+ }
108
+ return body.token;
109
+ };
110
+ const requestJson = async (baseUrl, path, init = {}) => {
111
+ const supervisorToken = await getSupervisorToken(baseUrl);
112
+ const response = await fetch(`${baseUrl}${path}`, {
113
+ ...init,
114
+ headers: {
115
+ ...(init.headers ?? {}),
116
+ [HIVE_SUPERVISOR_TOKEN_HEADER]: supervisorToken,
117
+ ...(init.body ? { 'content-type': 'application/json' } : {}),
118
+ },
119
+ });
120
+ if (!response.ok)
121
+ throw new Error(await readHttpErrorDetail(response));
122
+ return response.json();
123
+ };
124
+ const postJson = (baseUrl, path, body) => requestJson(baseUrl, path, {
125
+ body: JSON.stringify(body),
126
+ method: 'POST',
127
+ });
128
+ const requireStringArg = (args, key) => {
129
+ const value = args[key];
130
+ if (typeof value !== 'string' || value.trim().length === 0) {
131
+ throw new Error(`Missing ${key}`);
132
+ }
133
+ return value;
134
+ };
135
+ export const callHiveMcpTool = async (toolName, args = {}, input = {}) => {
136
+ const baseUrl = input.baseUrl ?? parseBaseUrl([], input.env ?? process.env);
137
+ if (toolName === 'hive.list_workspaces') {
138
+ return requestJson(baseUrl, '/api/external-goals/workspaces');
139
+ }
140
+ if (toolName === 'hive.inspect_workspace') {
141
+ const workspaceId = requireStringArg(args, 'workspace_id');
142
+ return requestJson(baseUrl, `/api/external-goals/workspaces/${encodeURIComponent(workspaceId)}`);
143
+ }
144
+ if (toolName === 'hive.start_goal') {
145
+ return postJson(baseUrl, '/api/external-goals/start', {
146
+ context: args.context,
147
+ goal: requireStringArg(args, 'goal'),
148
+ source: 'hive-mcp',
149
+ timeout_hint_ms: args.timeout_hint_ms,
150
+ workspace_id: requireStringArg(args, 'workspace_id'),
151
+ });
152
+ }
153
+ if (toolName === 'hive.wait_goal') {
154
+ return postJson(baseUrl, '/api/external-goals/wait', {
155
+ cursor: args.cursor,
156
+ goal_id: requireStringArg(args, 'goal_id'),
157
+ timeout_ms: args.timeout_ms,
158
+ });
159
+ }
160
+ if (toolName === 'hive.continue_goal') {
161
+ return postJson(baseUrl, '/api/external-goals/continue', {
162
+ context: args.context,
163
+ goal_id: requireStringArg(args, 'goal_id'),
164
+ message: requireStringArg(args, 'message'),
165
+ });
166
+ }
167
+ if (toolName === 'hive.cancel_goal') {
168
+ return postJson(baseUrl, '/api/external-goals/cancel', {
169
+ goal_id: requireStringArg(args, 'goal_id'),
170
+ reason: requireStringArg(args, 'reason'),
171
+ });
172
+ }
173
+ throw new Error(`Unknown Hive MCP tool: ${toolName}`);
174
+ };
175
+ const resultResponse = (id, result) => ({
176
+ id,
177
+ jsonrpc: '2.0',
178
+ result,
179
+ });
180
+ const errorResponse = (id, code, message) => ({
181
+ error: { code, message },
182
+ id: id ?? null,
183
+ jsonrpc: '2.0',
184
+ });
185
+ const toolResult = (result) => ({
186
+ content: [
187
+ {
188
+ text: JSON.stringify(result),
189
+ type: 'text',
190
+ },
191
+ ],
192
+ structuredContent: result,
193
+ });
194
+ const handleRequest = async (request, baseUrl) => {
195
+ if (!request.method) {
196
+ return errorResponse(request.id, -32600, 'Invalid JSON-RPC request');
197
+ }
198
+ if (request.method === 'initialize') {
199
+ return resultResponse(request.id, {
200
+ capabilities: { tools: {} },
201
+ protocolVersion: typeof request.params?.protocolVersion ===
202
+ 'string'
203
+ ? request.params.protocolVersion
204
+ : '2025-06-18',
205
+ serverInfo: { name: 'hive-supervisor', version: readPackageVersion() },
206
+ });
207
+ }
208
+ if (request.method === 'ping')
209
+ return resultResponse(request.id, {});
210
+ if (request.method === 'tools/list')
211
+ return resultResponse(request.id, { tools: HIVE_MCP_TOOLS });
212
+ if (request.method === 'tools/call') {
213
+ const params = request.params;
214
+ if (!params?.name)
215
+ return errorResponse(request.id, -32602, 'Missing tool name');
216
+ const result = await callHiveMcpTool(params.name, params.arguments ?? {}, { baseUrl });
217
+ return resultResponse(request.id, toolResult(result));
218
+ }
219
+ if (request.id === undefined)
220
+ return null;
221
+ return errorResponse(request.id, -32601, `Unknown method: ${request.method}`);
222
+ };
223
+ const writeJsonRpc = (message) => {
224
+ process.stdout.write(`${JSON.stringify(message)}\n`);
225
+ };
226
+ export const runHiveMcpCommand = async (argv = process.argv.slice(2), env = process.env) => {
227
+ const baseUrl = parseBaseUrl(argv, env);
228
+ const rl = createInterface({ input: process.stdin, terminal: false });
229
+ for await (const line of rl) {
230
+ const trimmed = line.trim();
231
+ if (!trimmed)
232
+ continue;
233
+ let requestId;
234
+ try {
235
+ const request = JSON.parse(trimmed);
236
+ requestId = request.id;
237
+ const response = await handleRequest(request, baseUrl);
238
+ if (response)
239
+ writeJsonRpc(response);
240
+ }
241
+ catch (error) {
242
+ writeJsonRpc(errorResponse(requestId, -32603, error instanceof Error ? error.message : String(error)));
243
+ }
244
+ }
245
+ };
246
+ const isMainModule = process.argv[1]
247
+ ? sameFilesystemPath(fileURLToPath(import.meta.url), process.argv[1])
248
+ : false;
249
+ if (isMainModule) {
250
+ void runHiveMcpCommand(process.argv.slice(2)).catch((error) => {
251
+ console.error(error instanceof Error ? error.message : String(error));
252
+ process.exit(1);
253
+ });
254
+ }
@@ -2,6 +2,7 @@
2
2
  import { type RemoteTunnel, type RemoteTunnelDeps } from '../server/remote-tunnel.js';
3
3
  import { type RuntimeStore } from '../server/runtime-store.js';
4
4
  import { type VersionService } from '../server/version-service.js';
5
+ import { DEFAULT_HIVE_PORT } from './hive-defaults.js';
5
6
  interface RunHiveCommandResult {
6
7
  port: number;
7
8
  close: () => Promise<void>;
@@ -40,6 +41,7 @@ type RunHiveCommandOptions = {
40
41
  * registration is mostly about giving SQLite a chance to checkpoint.
41
42
  */
42
43
  export declare const SHUTDOWN_SIGNALS: readonly ["SIGINT", "SIGTERM", "SIGHUP", "SIGBREAK"];
44
+ export { DEFAULT_HIVE_PORT };
43
45
  export declare const HIVE_USAGE: string;
44
46
  export declare const handleHiveInfoCommand: (argv: string[]) => boolean;
45
47
  /**
@@ -13,6 +13,8 @@ import { createRemoteConfigSource } from '../server/remote-config-keys.js';
13
13
  import { createRemoteTunnel, } from '../server/remote-tunnel.js';
14
14
  import { createRuntimeStore } from '../server/runtime-store.js';
15
15
  import { createVersionService } from '../server/version-service.js';
16
+ import { DEFAULT_HIVE_PORT } from './hive-defaults.js';
17
+ import { runHiveMcpCommand } from './hive-mcp.js';
16
18
  import { runHiveRemoteCommand } from './hive-remote.js';
17
19
  import { runHiveUpdateCommand } from './hive-update.js';
18
20
  /**
@@ -37,18 +39,20 @@ import { runHiveUpdateCommand } from './hive-update.js';
37
39
  * registration is mostly about giving SQLite a chance to checkpoint.
38
40
  */
39
41
  export const SHUTDOWN_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGBREAK'];
42
+ export { DEFAULT_HIVE_PORT };
40
43
  export const HIVE_USAGE = [
41
44
  'Usage:',
42
45
  ' hive [--port <port>] [--no-open]',
43
46
  ' hive update',
44
47
  '',
45
48
  'Options:',
46
- ' --port <port> Bind the local runtime to a specific port (default: 3000).',
49
+ ` --port <port> Bind the local runtime to a specific port (default: ${DEFAULT_HIVE_PORT}).`,
47
50
  ' --no-open Do not auto-open the browser after start.',
48
51
  ' -h, --help Print this help.',
49
52
  ' -v, --version Print the installed Hive version.',
50
53
  '',
51
54
  'Commands:',
55
+ ' mcp Run the local Supervisor MCP stdio adapter.',
52
56
  ' update Upgrade npm-installed Hive in place; otherwise use the matching package manager.',
53
57
  ' remote Manage remote access (login / status / logout / devices / revoke).',
54
58
  ].join('\n');
@@ -87,7 +91,7 @@ const parsePort = (argv) => {
87
91
  parsedPort = port;
88
92
  index += 1;
89
93
  }
90
- return parsedPort ?? 3000;
94
+ return parsedPort ?? DEFAULT_HIVE_PORT;
91
95
  };
92
96
  /**
93
97
  * Resolve the directory where Hive persists its SQLite DB and supporting
@@ -350,6 +354,12 @@ if (isMainModule) {
350
354
  process.exit(1);
351
355
  });
352
356
  }
357
+ else if (argv[0] === 'mcp') {
358
+ runHiveMcpCommand(argv.slice(1)).catch((error) => {
359
+ console.error(error instanceof Error ? error.message : error);
360
+ process.exit(1);
361
+ });
362
+ }
353
363
  else if (handleHiveInfoCommand(argv)) {
354
364
  process.exit(0);
355
365
  }
@@ -11,6 +11,14 @@ export interface ParsedReportArgs {
11
11
  }
12
12
  export declare const parseReportArgs: (args: string[], command?: string) => ParsedReportArgs;
13
13
  export declare const parseCancelArgs: (args: string[]) => ParsedCancelArgs;
14
+ export interface ParsedGoalReportArgs {
15
+ artifacts: string[];
16
+ goalId: string;
17
+ result: string | null;
18
+ status: 'progress' | 'done' | 'blocked' | 'failed';
19
+ useStdin: boolean;
20
+ }
21
+ export declare const parseGoalReportArgs: (args: string[]) => ParsedGoalReportArgs;
14
22
  export declare const parseRecallArgs: (args: string[]) => {
15
23
  window?: number;
16
24
  limit?: number;