dsh-hive-runner 0.0.0-stage → 0.6.0
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.
- package/CHANGELOG.md +45 -0
- package/LICENSE +21 -0
- package/README.md +285 -2
- package/README.zh-CN.md +206 -0
- package/SPEC.md +209 -0
- package/cordis.patch.yml +83 -0
- package/docs/DESIGN.md +181 -0
- package/index.js +195 -0
- package/lib/commands.js +261 -0
- package/lib/config.js +264 -0
- package/lib/discover.js +96 -0
- package/lib/hooks.js +92 -0
- package/lib/http.js +120 -0
- package/lib/limits.js +184 -0
- package/lib/queue.js +156 -0
- package/lib/round.js +362 -0
- package/lib/shell.js +72 -0
- package/lib/supervisor.js +574 -0
- package/package.json +60 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file. The format is
|
|
4
|
+
based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project
|
|
5
|
+
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
Version 0.6.0 is the first public snapshot; 0.1.0-0.5.0 were local development
|
|
8
|
+
iterations of the plugin before this repository was published.
|
|
9
|
+
|
|
10
|
+
## [0.6.0] - 2026-12-04
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Merge-on-commit enforcement: every round preflights `<repo>/.git/hooks/pre-commit`,
|
|
15
|
+
a missing or non-moc hook is a deferrable environment error (backoff, no card failure,
|
|
16
|
+
no auto-pause), and a card is only recorded done when HEAD moved through that hook.
|
|
17
|
+
- Hive-consensus worker protocol: worker prompts carry mandatory guard/commit/release
|
|
18
|
+
rules, the supervisor co-signs the card scope with `hive guard` before starting a
|
|
19
|
+
worker and injects `hive recall` lessons for that scope, and a scope held by another
|
|
20
|
+
agent fails only that card with the holder information.
|
|
21
|
+
- Freeze mode: non-fix cards are left on the Hive board instead of being failed while
|
|
22
|
+
the repository is frozen; per-repository status reports `environmentError`, `mode`,
|
|
23
|
+
`frozenSkipped` and `lastSkipReason`.
|
|
24
|
+
- A resident `HiveSupervisor` in the DSH host process: ticks every 30 s, reads the
|
|
25
|
+
ready cards of every configured repository and drains one repository at a time, while
|
|
26
|
+
the Web UI can be closed and DSH keeps running.
|
|
27
|
+
- One DSH subagent worker per card, with live-only per-role slot accounting: a waiting
|
|
28
|
+
card does not occupy a slot and a finished worker frees it immediately.
|
|
29
|
+
- Per-role worker limits (default 5 live workers per role; 0 pauses a role), editable
|
|
30
|
+
from the Hive panel's Runner tab, persisted to `<repo>/.hive/limits.json` and hot
|
|
31
|
+
reloaded on change.
|
|
32
|
+
- Per-repository pause/resume, exponential backoff when idle or failing, and auto-pause
|
|
33
|
+
after three consecutive round exceptions (manual resume required).
|
|
34
|
+
- Repository discovery for initialised Hive repositories (`refs/hive/v1`) under
|
|
35
|
+
configured roots, bounded by depth.
|
|
36
|
+
- Model-facing tools: `hive_run_round`, `hive_tasks_ready`, `hive_board` and
|
|
37
|
+
`hive_supervisor_status`; plus a same-origin status/control route used by the panel.
|
|
38
|
+
- 89 tests (`node --test`) with a pure shim: no DSH process, no real timers and no real
|
|
39
|
+
CLI, including an architecture guard that the plugin never spawns child processes.
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
|
|
43
|
+
- Card rounds run as DSH subagents through the harness instead of child processes.
|
|
44
|
+
- Role limits are read from the panel's persisted file first, then plugin config, then
|
|
45
|
+
the per-role defaults.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tommy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,286 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# dsh-hive-runner
|
|
4
|
+
|
|
5
|
+
**English** · [简体中文](README.zh-CN.md)
|
|
6
|
+
|
|
7
|
+
**A resident Hive supervisor inside DSH.** While DSH is open it keeps taking ready task
|
|
8
|
+
cards for your repositories and runs one DSH subagent ("bee") per card, inside the
|
|
9
|
+
per-role worker limits you set in the Hive panel.
|
|
10
|
+
|
|
11
|
+
[](https://github.com/d86e/dsh-hive-runner/actions)
|
|
12
|
+
[](https://www.npmjs.com/package/dsh-hive-runner)
|
|
13
|
+
[](LICENSE)
|
|
14
|
+
[](https://nodejs.org)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
[Hive](https://github.com/d86e/hive) coordinates a swarm of coding agents inside git: task
|
|
21
|
+
cards with acceptance commands, expiring path leases, a presence board and a commit-time
|
|
22
|
+
merge, all stored as refs and files in the repository itself. The
|
|
23
|
+
[hive-runner](https://github.com/d86e/hive-runner) CLI runs **one** round and exits.
|
|
24
|
+
|
|
25
|
+
**dsh-hive-runner** makes that loop resident inside DSH. It runs a supervisor in the DSH
|
|
26
|
+
host process — not in the browser tab — so closing the panel or the window does not stop
|
|
27
|
+
it; it keeps working as long as DSH is running. Workers are DSH subagents, and every shell
|
|
28
|
+
call goes through DSH's own shell seam, so the work stays inside the deployment sandbox:
|
|
29
|
+
the plugin never spawns processes outside the harness.
|
|
30
|
+
|
|
31
|
+
## What it does
|
|
32
|
+
|
|
33
|
+
- For every configured repository it reads the ready task cards and dispatches one worker
|
|
34
|
+
subagent per card.
|
|
35
|
+
- **Only live workers occupy a slot.** A card waiting for a slot is not counted; when a
|
|
36
|
+
worker finishes its card the slot is freed immediately and the next waiting card of the
|
|
37
|
+
same role starts.
|
|
38
|
+
- Each role has its own limit. The default is **5 live workers per role** for roles that
|
|
39
|
+
are not configured.
|
|
40
|
+
- **0 pauses a role**: its ready cards stay on the Hive board and are not dispatched.
|
|
41
|
+
- A repository is always processed one drain at a time; different repositories can run in
|
|
42
|
+
parallel (2 by default).
|
|
43
|
+
- A card that produces no commit, fails its acceptance command, or whose worker stops
|
|
44
|
+
early is recorded as failed in Hive; the rest of the queue continues.
|
|
45
|
+
- If a repository keeps failing, it backs off and is auto-paused after three consecutive
|
|
46
|
+
failures. Paused repositories never resume by themselves.
|
|
47
|
+
- Workers follow the Hive consensus protocol: the supervisor co-signs each card's scope
|
|
48
|
+
with `hive guard` before a worker starts, injects recalled lessons into the prompt,
|
|
49
|
+
and releases the scope leases afterwards. A scope held by another agent fails only that
|
|
50
|
+
card, with the holder information.
|
|
51
|
+
- Commits are verified against merge-on-commit: the repository must have the
|
|
52
|
+
merge-on-commit pre-commit hook (`hive init` installs it), and a card only counts as
|
|
53
|
+
done when HEAD moved through that hook.
|
|
54
|
+
- While the repository is in Hive freeze mode, non-fix cards stay on the board instead of
|
|
55
|
+
failing.
|
|
56
|
+
|
|
57
|
+
## Requirements
|
|
58
|
+
|
|
59
|
+
- DSH 0.2.2-rc.5 with the `desktop` or `web` profile — the version the plugin is
|
|
60
|
+
developed against. Node 22 or newer.
|
|
61
|
+
- The [hive](https://github.com/d86e/hive) and
|
|
62
|
+
[hive-tasks](https://github.com/d86e/hive-tasks) packages. `hive-tasks` must be
|
|
63
|
+
reachable from the DSH host process, either on its PATH or via `tasksBin`.
|
|
64
|
+
- Repositories already initialised with Hive (`hive init`), unless you enable discovery.
|
|
65
|
+
- The [Hive panel](https://github.com/d86e/dsh-hive-panel) is not required, but it is the
|
|
66
|
+
easiest way to change limits and pause/resume a repository.
|
|
67
|
+
|
|
68
|
+
## Install
|
|
69
|
+
|
|
70
|
+
Install into the profile that boots the DSH host where the supervisor should run. The
|
|
71
|
+
**desktop** profile is managed by the DSH Desktop app, so
|
|
72
|
+
`dsh plugin --profile desktop ...` refuses to edit it; edit it by hand:
|
|
73
|
+
|
|
74
|
+
1. In `~/.dsh/profiles/desktop/package.json`, add the dependency and the bundle:
|
|
75
|
+
|
|
76
|
+
```diff
|
|
77
|
+
"dependencies": {
|
|
78
|
+
+ "dsh-hive-runner": "link:/path/to/dsh-hive-runner",
|
|
79
|
+
},
|
|
80
|
+
"dsh": {
|
|
81
|
+
"profile": {
|
|
82
|
+
"bundles": [
|
|
83
|
+
+ "dsh-hive-runner"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
2. Run `cd ~/.dsh/profiles/desktop && pnpm install`.
|
|
90
|
+
3. Add your repositories to the `hive-runner` entry in that profile's
|
|
91
|
+
`cordis.patch.yml`, restart DSH, and open the Hive panel's **Runner** tab.
|
|
92
|
+
|
|
93
|
+
For a CLI profile such as `web`, `dsh plugin --profile web add /path/to/dsh-hive-runner`
|
|
94
|
+
also works; check that `dsh.profile.bundles` lists `dsh-hive-runner`.
|
|
95
|
+
|
|
96
|
+
## Five-minute quickstart
|
|
97
|
+
|
|
98
|
+
1. **Install** the plugin as above and restart DSH.
|
|
99
|
+
2. **Add one repository** to the `hive-runner` config entry:
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
- id: hive-runner
|
|
103
|
+
name: dsh-hive-runner
|
|
104
|
+
config:
|
|
105
|
+
repos:
|
|
106
|
+
- /absolute/path/to/your/repo
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
3. **Create a ready card** in that repository (the Hive CLI, from the repository root):
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
hive tasks add --title "add token refresh" --role coder \
|
|
113
|
+
--scope src/auth.ts --acceptance "npm test -- auth"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
4. **Watch it run.** The supervisor ticks every 30 seconds, claims the card and starts a
|
|
117
|
+
DSH subagent worker for it. The Hive panel's Runner tab shows the per-role limits, live
|
|
118
|
+
workers and cards waiting for a slot; the card moves to done when the worker commits and
|
|
119
|
+
the acceptance command passes.
|
|
120
|
+
5. **Adjust the swarm.** Set per-role worker counts in the panel (0 pauses a role), or
|
|
121
|
+
pause the whole repository with the same tab. Changes take effect immediately.
|
|
122
|
+
|
|
123
|
+
The supervisor keeps running with the panel closed. To stop all work, pause the
|
|
124
|
+
repository or remove it from `repos`.
|
|
125
|
+
|
|
126
|
+
## Changing the number of bees
|
|
127
|
+
|
|
128
|
+
Everything is controlled from the **Hive panel**:
|
|
129
|
+
|
|
130
|
+
1. Open the Hive panel in DSH and select the **Runner** tab.
|
|
131
|
+
2. In **Per-role workers** (每角色蜂数量) set the number for each role: how many live
|
|
132
|
+
workers of that role may run at the same time in that repository. Use 0 to pause a role.
|
|
133
|
+
3. Changes take effect immediately (no restart, no plugin reload).
|
|
134
|
+
4. The value is saved to `<repo>/.hive/limits.json`, so it also survives DSH restarts.
|
|
135
|
+
The file is plain JSON and **safe to commit** into the repository, which shares the same
|
|
136
|
+
limits with every teammate and every machine.
|
|
137
|
+
|
|
138
|
+
To pause or resume the whole repository, use the **Pause / Resume** button in the same
|
|
139
|
+
Runner tab. Pause stops new work from being scheduled; cards that are already running
|
|
140
|
+
finish, and resume makes the repository eligible again on the next tick.
|
|
141
|
+
|
|
142
|
+
The panel also shows, per role, the configured limit, how many workers are live right now,
|
|
143
|
+
and how many cards are waiting for a slot.
|
|
144
|
+
|
|
145
|
+
## How many bees should I set?
|
|
146
|
+
|
|
147
|
+
The limits are user settings, not a hardcoded number. Small values (the default 5 per
|
|
148
|
+
role) keep token cost predictable. Only when you set the values very high does the
|
|
149
|
+
supervisor approximate "as many bees as ready tasks", because the real ceiling is DSH's
|
|
150
|
+
subagent capacity plus the model provider's rate limits:
|
|
151
|
+
|
|
152
|
+
- DSH's profile setting `subagent.maxActiveSubagents` (desktop profile default 80 - check
|
|
153
|
+
your profile) caps how many subagents can exist at once across the whole app. If more
|
|
154
|
+
cards become ready than the capacity allows, they wait and are retried; no card is
|
|
155
|
+
dropped.
|
|
156
|
+
- Token consumption grows roughly linearly with the number of concurrent bees. Measure a
|
|
157
|
+
small repository first, then raise the numbers.
|
|
158
|
+
- If you want more parallelism than the default, raise both the panel limits and
|
|
159
|
+
`subagent.maxActiveSubagents` (for example to 128), and confirm the provider rate limits.
|
|
160
|
+
|
|
161
|
+
## Configuration
|
|
162
|
+
|
|
163
|
+
Deployment defaults live in [`cordis.patch.yml`](cordis.patch.yml); the same keys are
|
|
164
|
+
accepted as plugin `config`. User-facing keys:
|
|
165
|
+
|
|
166
|
+
| Key | Default | Meaning |
|
|
167
|
+
| --- | --- | --- |
|
|
168
|
+
| `repos` | `[]` | Absolute repository paths to drive |
|
|
169
|
+
| `autoDiscover` | `false` | Find initialised Hive repositories under `discoverRoots` |
|
|
170
|
+
| `discoverRoots` | `[]` | Roots to scan when auto-discovering; empty = parents of `repos` |
|
|
171
|
+
| `intervalMs` / `idleBackoffMs` | `30000` / `120000` | How often to look for work / how long to wait when a repository is empty |
|
|
172
|
+
| `maxConcurrentRepos` | `2` | How many repositories may work at the same time |
|
|
173
|
+
| `roleConcurrency` | `{ coder: 5, tester: 5 }` | Initial/fallback per-role worker limits |
|
|
174
|
+
| `defaultRoleConcurrency` | `5` | Fallback for roles not listed in `roleConcurrency` |
|
|
175
|
+
| `paused` | `[]` | Repositories paused at startup (absolute paths) |
|
|
176
|
+
| `agent` / `ttl` | `dsh` / `5m` | Identity and lease TTL for claims |
|
|
177
|
+
| `provider` | `spawn` | DSH subagent provider used for workers |
|
|
178
|
+
| `parentSession` | `null` | Optional live session used as the parent for workers |
|
|
179
|
+
| `tasksBin` / `hiveBin` | `null` | Explicit `hive-tasks` / `hive` executables (PATH name or absolute path) |
|
|
180
|
+
| `gitBin` | `git` | Git executable |
|
|
181
|
+
| `cliTimeoutMs` / `headTimeoutMs` / `acceptanceTimeoutMs` | `120000` / `30000` / `900000` | Command timeouts |
|
|
182
|
+
| `debug` | `false` | Verbose supervisor logging |
|
|
183
|
+
|
|
184
|
+
`roleConcurrency` is only the initial value and the fallback; the per-repository panel
|
|
185
|
+
values in `.hive/limits.json` take precedence for the roles they contain.
|
|
186
|
+
Repository-specific defaults can also be written in the config with absolute-path keys,
|
|
187
|
+
for example `{ "/abs/repo": { "coder": 3 } }`.
|
|
188
|
+
|
|
189
|
+
`hive-tasks` must be resolvable from the DSH host's `PATH` (or configured as
|
|
190
|
+
`tasksBin`). If DSH's shell service is unavailable the plugin fails loudly instead of
|
|
191
|
+
bypassing the sandbox.
|
|
192
|
+
|
|
193
|
+
## Architecture
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
DSH host process (alive as long as the app runs)
|
|
197
|
+
dsh-hive-runner
|
|
198
|
+
|
|
|
199
|
+
+-- HiveSupervisor: tick every 30 s, per-repository backoff, pause/resume
|
|
200
|
+
| |
|
|
201
|
+
| +-- repository registry: config.repos, discovery, <repo>/.hive/limits.json
|
|
202
|
+
| +-- ready cards: hive-tasks through DSH's shell seam (sandbox applies)
|
|
203
|
+
| +-- per-role queues: live-only slots, default 5, 0 pauses a role
|
|
204
|
+
| |
|
|
205
|
+
| +-- one card round
|
|
206
|
+
| claim -> DSH subagent worker ("bee") -> commit + acceptance
|
|
207
|
+
| -> verify -> done | fail on the Hive board
|
|
208
|
+
|
|
|
209
|
+
+-- Hive panel Runner tab: per-role limits, live counts, pause/resume
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The supervisor owns the cadence (tick, backoff, persistence, pause state). A card worker
|
|
213
|
+
is a normal DSH subagent; its commands and shell run through the harness under the
|
|
214
|
+
applicable sandbox policy.
|
|
215
|
+
|
|
216
|
+
## Relationship to the other Hive projects
|
|
217
|
+
|
|
218
|
+
| Project | What it does | How this plugin relates |
|
|
219
|
+
| --- | --- | --- |
|
|
220
|
+
| [hive](https://github.com/d86e/hive) | One CLI entry point: init, roles, tasks, run, board, commit, doctor | The supervisor reads state and cards through the Hive CLIs |
|
|
221
|
+
| [hive-tasks](https://github.com/d86e/hive-tasks) | Task cards with dependencies, priority and acceptance | Ready cards are fetched, claimed, completed or failed through it |
|
|
222
|
+
| [hive-consensus](https://github.com/d86e/hive-consensus) | Path leases, presence board, freeze mode, shared lessons | Claims and presence keep concurrent agents from colliding |
|
|
223
|
+
| [hive-runner](https://github.com/d86e/hive-runner) | One execution round per invocation (`hive-run --once`) | This plugin uses the same round primitives, resident and DSH-native |
|
|
224
|
+
| [merge-on-commit](https://github.com/d86e/merge-on-commit) | Three-way merge at commit time | Workers' commits go through the repository hook like any other commit |
|
|
225
|
+
| [hive-panel](https://github.com/d86e/hive-panel) | Standalone read-only board outside DSH | Not needed; [dsh-hive-panel](https://github.com/d86e/dsh-hive-panel) is the DSH-native board |
|
|
226
|
+
| [dsh-hive-panel](https://github.com/d86e/dsh-hive-panel) | Hive view inside DSH Web | Optional UI: shows supervisor status and edits the per-role limits |
|
|
227
|
+
|
|
228
|
+
## Relation to `hive-run --watch`
|
|
229
|
+
|
|
230
|
+
`hive-run --watch` loops inside one CLI process over one repository. This plugin does
|
|
231
|
+
**not** invoke `--watch` and does not modify the `hive-runner` CLI: the supervisor owns
|
|
232
|
+
the cadence (tick every 30 s, back off when empty, persist per-role limits, pause/resume
|
|
233
|
+
from the panel). `hive-run --once` still works manually; do not run it against a
|
|
234
|
+
repository while the supervisor is active on the same repository.
|
|
235
|
+
|
|
236
|
+
## FAQ and known limits
|
|
237
|
+
|
|
238
|
+
**How many bees run at once?** Per role and per repository, the configured limit (default
|
|
239
|
+
5) of live workers. Across repositories, at most `maxConcurrentRepos` drains run at the
|
|
240
|
+
same time; DSH's `subagent.maxActiveSubagents` is the hard ceiling below that. Cards that
|
|
241
|
+
do not fit wait and are retried, so very large limits do not increase real throughput by
|
|
242
|
+
themselves, and token cost grows with concurrency.
|
|
243
|
+
|
|
244
|
+
**A card is claimed but not started.** Cards waiting in a repository's queue hold their
|
|
245
|
+
Hive claim; if the wait outlives the claim TTL (`ttl`, default 5m) the claim expires and
|
|
246
|
+
the card can be reclaimed. Raise `ttl` for very large queues.
|
|
247
|
+
|
|
248
|
+
**A repository says it is waiting.** Workers need a live DSH agent as their parent. When
|
|
249
|
+
no session is live the repository waits (and the panel says why) instead of failing.
|
|
250
|
+
|
|
251
|
+
**A repository is paused and does not restart.** That is deliberate: auto-pause after
|
|
252
|
+
three consecutive failures, and pause from the panel, both require an explicit resume.
|
|
253
|
+
|
|
254
|
+
**Does it write without asking?** It claims cards and commits through the normal Hive and
|
|
255
|
+
git flows of the repository. The acceptance command comes from the card, i.e. from the
|
|
256
|
+
repository; treat the repository as trusted input. A read-only deployment cannot claim or
|
|
257
|
+
write cards.
|
|
258
|
+
|
|
259
|
+
**What survives a DSH restart?** Per-role limits (in `.hive/limits.json`) and the Hive
|
|
260
|
+
state (in git refs) survive. In-memory queues do not: claimed cards return to the board
|
|
261
|
+
after their claim TTL.
|
|
262
|
+
|
|
263
|
+
**Do I need the Hive panel?** No. The panel is the convenient front-end for limits and
|
|
264
|
+
pause/resume; the supervisor works from `cordis.patch.yml` alone.
|
|
265
|
+
|
|
266
|
+
## Development
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
npm test # node --test test/*.test.js (89 tests)
|
|
270
|
+
npm run check # node --check on index.js and lib/
|
|
271
|
+
npm pack --dry-run
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
The test suite is a pure shim (no DSH process, no real timers, no real CLI) and covers the
|
|
275
|
+
default five-per-role limits, live-only slot accounting with immediate refill, queued cards
|
|
276
|
+
not occupying slots, 0 pausing a role, persisted limits taking effect immediately and
|
|
277
|
+
surviving a restart, invalid limit updates being rejected, the state machine, card round
|
|
278
|
+
paths, discovery, the command allowlist, and an architecture guard that the plugin never
|
|
279
|
+
spawns child processes.
|
|
280
|
+
|
|
281
|
+
The protocol is specified in [SPEC.md](SPEC.md); implementation notes are in
|
|
282
|
+
[docs/DESIGN.md](docs/DESIGN.md).
|
|
283
|
+
|
|
284
|
+
## License
|
|
285
|
+
|
|
286
|
+
MIT © Tommy. See [LICENSE](LICENSE).
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# dsh-hive-runner
|
|
4
|
+
|
|
5
|
+
[English](README.md) · **简体中文**
|
|
6
|
+
|
|
7
|
+
**DSH 里的常驻 Hive supervisor。** DSH 开着时,它为你配置的仓库持续接 ready 任务卡,每张卡跑一个 DSH subagent(「蜂」),并遵守你在 Hive 面板里设置的每角色 worker 上限。
|
|
8
|
+
|
|
9
|
+
[](https://github.com/d86e/dsh-hive-runner/actions)
|
|
10
|
+
[](https://www.npmjs.com/package/dsh-hive-runner)
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
[](https://nodejs.org)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
[Hive](https://github.com/d86e/hive) 让一群 AI agent 在 git 里协调:带验收命令的任务卡、会过期的路径租约、在场看板、提交时合并,全部存在仓库自己的 refs 和文件里。[hive-runner](https://github.com/d86e/hive-runner) CLI 跑**一轮**就退出。
|
|
19
|
+
|
|
20
|
+
**dsh-hive-runner** 把这个循环常驻进 DSH:supervisor 活在 DSH 宿主进程里(不在浏览器 tab 里),关掉面板或窗口都照常工作,只要 DSH 还在运行。worker 是 DSH subagent,所有命令都走 DSH 自己的 shell 执行层,受部署 sandbox 约束——插件不会绕过 harness 直接 spawn 进程。
|
|
21
|
+
|
|
22
|
+
## 它做什么
|
|
23
|
+
|
|
24
|
+
- 对每个已配置的仓库读取 ready 任务卡,每张卡派一个 worker subagent。
|
|
25
|
+
- **只有在飞的 worker 占名额**:排队等名额的卡不占;一张卡完成,名额立刻释放,同角色下一张等待的卡马上补上。
|
|
26
|
+
- 每个角色有独立上限,未单独配置的角色**默认 5 个在飞 worker**。
|
|
27
|
+
- **0 表示暂停该角色**:它的 ready 卡留在 Hive 看板上,不派活。
|
|
28
|
+
- 单仓库一次只处理一轮;不同仓库可以并行(默认 2 个仓库)。
|
|
29
|
+
- 卡片没产生 commit、验收命令失败或 worker 提前停止,会在 Hive 里记为失败,队列继续跑其余卡。
|
|
30
|
+
- 仓库连续失败会退避,连续 3 次异常自动暂停;暂停的仓库不会自己恢复。
|
|
31
|
+
- worker 遵循 Hive consensus 协议:supervisor 先用 `hive guard` 为卡片 scope 联签,再把 `hive recall` 到的经验注入 prompt,结束后释放 scope 租约。scope 被其他 agent 持有时只让这张卡失败,并记录持有者信息。
|
|
32
|
+
- 提交受 merge-on-commit 约束:仓库必须装好 merge-on-commit 的 pre-commit 钩子(`hive init` 会装),只有 HEAD 经过该钩子推进的卡才算 done。
|
|
33
|
+
- 仓库处于 Hive freeze 模式时,非 fix 卡留在看板上,而不是记为失败。
|
|
34
|
+
|
|
35
|
+
## 环境要求
|
|
36
|
+
|
|
37
|
+
- DSH 0.2.2-rc.5,`desktop` 或 `web` profile——插件按这个版本开发;Node 22 或更新。
|
|
38
|
+
- [hive](https://github.com/d86e/hive) 与 [hive-tasks](https://github.com/d86e/hive-tasks)。
|
|
39
|
+
`hive-tasks` 必须能被 DSH 宿主进程找到:在 PATH 上,或配置 `tasksBin`。
|
|
40
|
+
- 已经用 Hive 初始化过的仓库(`hive init`),除非开启自动发现。
|
|
41
|
+
- [Hive 面板](https://github.com/d86e/dsh-hive-panel)不是必须的,但它是改上限、暂停/恢复仓库最方便的方式。
|
|
42
|
+
|
|
43
|
+
## 安装
|
|
44
|
+
|
|
45
|
+
装到启动目标 DSH 宿主所用的 profile 里。**desktop** profile 由 DSH Desktop 应用管理,`dsh plugin --profile desktop ...` 会拒绝修改,需要手动编辑:
|
|
46
|
+
|
|
47
|
+
1. 在 `~/.dsh/profiles/desktop/package.json` 里加依赖和 bundle:
|
|
48
|
+
|
|
49
|
+
```diff
|
|
50
|
+
"dependencies": {
|
|
51
|
+
+ "dsh-hive-runner": "link:/path/to/dsh-hive-runner",
|
|
52
|
+
},
|
|
53
|
+
"dsh": {
|
|
54
|
+
"profile": {
|
|
55
|
+
"bundles": [
|
|
56
|
+
+ "dsh-hive-runner"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
2. 执行 `cd ~/.dsh/profiles/desktop && pnpm install`。
|
|
63
|
+
3. 在该 profile 的 `cordis.patch.yml` 的 `hive-runner` 条目里配置仓库,重启 DSH,打开 Hive 面板的 **Runner** 标签页。
|
|
64
|
+
|
|
65
|
+
CLI profile(例如 `web`)也可以用 `dsh plugin --profile web add /path/to/dsh-hive-runner`,确认 `dsh.profile.bundles` 里列出了 `dsh-hive-runner`。
|
|
66
|
+
|
|
67
|
+
## 五分钟上手
|
|
68
|
+
|
|
69
|
+
1. **安装**插件并重启 DSH(见上)。
|
|
70
|
+
2. **加一个仓库**到 `hive-runner` 配置:
|
|
71
|
+
|
|
72
|
+
```yaml
|
|
73
|
+
- id: hive-runner
|
|
74
|
+
name: dsh-hive-runner
|
|
75
|
+
config:
|
|
76
|
+
repos:
|
|
77
|
+
- /absolute/path/to/your/repo
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
3. **建一张 ready 卡**(在仓库根目录用 Hive CLI):
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
hive tasks add --title "add token refresh" --role coder \
|
|
84
|
+
--scope src/auth.ts --acceptance "npm test -- auth"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
4. **看它跑起来**:supervisor 每 30 秒 tick 一次,认领卡片并为它启动一个 DSH subagent worker。Hive 面板的 Runner 标签页显示每角色上限、在飞 worker 和等待名额的卡数;worker 提交后验收命令通过,卡片就变成 done。
|
|
88
|
+
5. **调整蜂群**:在面板里改每角色 worker 数(0 暂停角色),或用同一个标签页暂停整个仓库。改动立即生效。
|
|
89
|
+
|
|
90
|
+
面板关掉 supervisor 也照常跑。要停掉所有工作,暂停仓库或从 `repos` 里移除它。
|
|
91
|
+
|
|
92
|
+
## 怎么改「蜂」的数量
|
|
93
|
+
|
|
94
|
+
全部在 **Hive 面板**里操作:
|
|
95
|
+
|
|
96
|
+
1. 打开 DSH 的 Hive 面板,进入 **Runner** 标签页。
|
|
97
|
+
2. 在 **每角色蜂数量(Per-role workers)** 里给每个角色填数字:表示该仓库里这个角色同时最多跑多少个在飞 worker。填 0 表示暂停该角色。
|
|
98
|
+
3. 改完**立即生效**,不需要重启或重载插件。
|
|
99
|
+
4. 数值会写入 `<repo>/.hive/limits.json`,DSH 重启后仍然保留。这个文件是普通 JSON,**可以提交进仓库**,让同一仓库的每台机器/每个同事共享同一套上限。
|
|
100
|
+
|
|
101
|
+
要暂停/恢复整个仓库,用同一个 Runner 标签页里的 **暂停 / 恢复** 按钮。暂停会阻止后续调度;已经在跑的卡会跑完,恢复后在下一个 tick 重新参与调度。
|
|
102
|
+
|
|
103
|
+
面板会按角色显示:当前上限、正在跑的 worker 数、等待名额的卡数。
|
|
104
|
+
|
|
105
|
+
## 设多少只蜂合适?
|
|
106
|
+
|
|
107
|
+
并发是用户设置项,不是写死的数字。默认每角色 5 只,token 成本可预期;只有把数值调得很大时,才等价于「有多少 ready 任务就派多少只蜂」——因为真正的天花板是 DSH 的 subagent 容量和模型 provider 限流:
|
|
108
|
+
|
|
109
|
+
- DSH profile 的 `subagent.maxActiveSubagents`(桌面 profile 默认 80,以实际 profile 为准)限制整个应用同时存在的 subagent 总数。ready 卡超过容量时只会等待并重试,不会丢卡。
|
|
110
|
+
- token 消耗随并发近似线性增长。先在小编队仓库测量,再逐步调高。
|
|
111
|
+
- 想要比默认更高的并行度:同时调高面板里的每角色上限和 `subagent.maxActiveSubagents`(例如 128),并确认 provider 限流。
|
|
112
|
+
|
|
113
|
+
## 配置
|
|
114
|
+
|
|
115
|
+
部署默认值在 [`cordis.patch.yml`](cordis.patch.yml),同样的 key 也可作为插件 `config`。用户关心的项:
|
|
116
|
+
|
|
117
|
+
| Key | 默认 | 含义 |
|
|
118
|
+
| --- | --- | --- |
|
|
119
|
+
| `repos` | `[]` | 要驱动的仓库绝对路径 |
|
|
120
|
+
| `autoDiscover` | `false` | 在 `discoverRoots` 下自动发现已初始化的 Hive 仓库 |
|
|
121
|
+
| `discoverRoots` | `[]` | 自动发现的扫描根目录;空 = 使用 `repos` 的父目录 |
|
|
122
|
+
| `intervalMs` / `idleBackoffMs` | `30000` / `120000` | 多久找一次活 / 仓库没活时等多久 |
|
|
123
|
+
| `maxConcurrentRepos` | `2` | 同时工作的仓库数 |
|
|
124
|
+
| `roleConcurrency` | `{ coder: 5, tester: 5 }` | 每角色 worker 数的初始值/兜底值 |
|
|
125
|
+
| `defaultRoleConcurrency` | `5` | 未在 `roleConcurrency` 中列出的角色的兜底值 |
|
|
126
|
+
| `paused` | `[]` | 启动即暂停的仓库(绝对路径) |
|
|
127
|
+
| `agent` / `ttl` | `dsh` / `5m` | claim 身份 / 租约 TTL |
|
|
128
|
+
| `provider` | `spawn` | 卡片 worker 使用的 DSH subagent provider |
|
|
129
|
+
| `parentSession` | `null` | 可选的、作为 worker parent 的 live session |
|
|
130
|
+
| `tasksBin` / `hiveBin` | `null` | 显式指定 `hive-tasks` / `hive` 可执行文件(PATH 名或绝对路径) |
|
|
131
|
+
| `gitBin` | `git` | git 可执行文件 |
|
|
132
|
+
| `cliTimeoutMs` / `headTimeoutMs` / `acceptanceTimeoutMs` | `120000` / `30000` / `900000` | 命令超时 |
|
|
133
|
+
| `debug` | `false` | supervisor 详细日志 |
|
|
134
|
+
|
|
135
|
+
`roleConcurrency` 只是初始值和兜底;面板写入 `.hive/limits.json` 的每仓库数值优先。也可以在这份配置里用绝对路径 key 写仓库级默认值,例如 `{ "/abs/repo": { "coder": 3 } }`。
|
|
136
|
+
|
|
137
|
+
`hive-tasks` 必须在 DSH 宿主进程的 `PATH` 里(或配置 `tasksBin`)。DSH 的 shell 服务不可用时插件会直接报错,不会绕过 sandbox。
|
|
138
|
+
|
|
139
|
+
## 架构
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
DSH 宿主进程(应用开着就一直在)
|
|
143
|
+
dsh-hive-runner
|
|
144
|
+
|
|
|
145
|
+
+-- HiveSupervisor:每 30 秒 tick、每仓库退避、暂停/恢复
|
|
146
|
+
| |
|
|
147
|
+
| +-- 仓库注册表:config.repos、自动发现、<repo>/.hive/limits.json
|
|
148
|
+
| +-- ready 卡:经 DSH shell 执行层调用 hive-tasks(受 sandbox 约束)
|
|
149
|
+
| +-- 每角色队列:只在飞占名额,默认 5,0 暂停角色
|
|
150
|
+
| |
|
|
151
|
+
| +-- 一张卡的一轮
|
|
152
|
+
| claim -> DSH subagent worker(「蜂」)-> commit + 验收
|
|
153
|
+
| -> 校验 -> 在 Hive 看板上 done | fail
|
|
154
|
+
|
|
|
155
|
+
+-- Hive 面板 Runner 标签页:每角色上限、在飞数、暂停/恢复
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
节奏归 supervisor 自己(tick、退避、持久化、暂停状态)。卡片 worker 是普通的 DSH subagent,它的命令和 shell 都经 harness 在适用的 sandbox 策略下执行。
|
|
159
|
+
|
|
160
|
+
## 与 Hive 其他仓库的关系
|
|
161
|
+
|
|
162
|
+
| 仓库 | 作用 | 与本插件的关系 |
|
|
163
|
+
| --- | --- | --- |
|
|
164
|
+
| [hive](https://github.com/d86e/hive) | 统一入口:init、roles、tasks、run、board、commit、doctor | supervisor 通过 Hive CLI 读状态和任务卡 |
|
|
165
|
+
| [hive-tasks](https://github.com/d86e/hive-tasks) | 带依赖、优先级、验收命令的任务卡 | ready 卡的读取、认领、完成、失败都经它 |
|
|
166
|
+
| [hive-consensus](https://github.com/d86e/hive-consensus) | 路径租约、在场看板、冻结模式、共享经验 | claim 和 presence 让并发 agent 不互相踩踏 |
|
|
167
|
+
| [hive-runner](https://github.com/d86e/hive-runner) | 每次调用跑一轮(`hive-run --once`) | 本插件复用同样的轮次原语,但常驻在 DSH 里 |
|
|
168
|
+
| [merge-on-commit](https://github.com/d86e/merge-on-commit) | 提交时三方合并 | worker 的提交和普通提交一样经过仓库钩子 |
|
|
169
|
+
| [hive-panel](https://github.com/d86e/hive-panel) | DSH 之外的独立只读看板 | 不需要;DSH 原生看板是 [dsh-hive-panel](https://github.com/d86e/dsh-hive-panel) |
|
|
170
|
+
| [dsh-hive-panel](https://github.com/d86e/dsh-hive-panel) | DSH Web 里的 Hive 视图 | 可选界面:显示 supervisor 状态、修改每角色上限 |
|
|
171
|
+
|
|
172
|
+
## 与 `hive-run --watch` 的关系
|
|
173
|
+
|
|
174
|
+
`hive-run --watch` 是在单个 CLI 进程里对单个仓库循环跑。本插件**不调用** `--watch`,也不改 `hive-runner` CLI:节奏归 supervisor(30s tick、没活退避、每仓库持久化上限、面板暂停/恢复)。`hive-run --once` 仍可手工使用;supervisor 在同一仓库上运行时不要重复跑。
|
|
175
|
+
|
|
176
|
+
## 常见问题与已知限制
|
|
177
|
+
|
|
178
|
+
**同时能跑多少只蜂?** 每仓库每角色的上限(默认 5)个在飞 worker。跨仓库最多 `maxConcurrentRepos` 个仓库同时处理;再往下的硬天花板是 DSH 的 `subagent.maxActiveSubagents`。放不下的卡只会等待重试,所以把上限调得很大并不会自动提高真实吞吐,token 成本随并发增长。
|
|
179
|
+
|
|
180
|
+
**卡片被 claim 了却迟迟不跑。** 仓库队列里的卡会持有 Hive claim;等待时间超过 claim TTL(`ttl`,默认 5m)后 claim 过期、卡片可被重新认领。队列很长时请调大 `ttl`。
|
|
181
|
+
|
|
182
|
+
**仓库显示在等待。** worker 需要一个 live DSH agent 作为 parent。没有 live session 时仓库会等待(面板会说明原因),而不是直接失败。
|
|
183
|
+
|
|
184
|
+
**仓库暂停后不会自己恢复。** 这是故意的:连续 3 次失败后的自动暂停和面板手动暂停,都需要显式恢复。
|
|
185
|
+
|
|
186
|
+
**它会不问就写吗?** 它通过仓库正常的 Hive 和 git 流程认领卡片、提交。验收命令来自卡片,也就是来自仓库——把仓库当作可信输入。只读部署无法 claim/写卡。
|
|
187
|
+
|
|
188
|
+
**DSH 重启后什么还在?** 每角色上限(`.hive/limits.json`)和 Hive 状态(git refs)都在;内存队列不在,已 claim 的卡会在 claim TTL 后回到看板。
|
|
189
|
+
|
|
190
|
+
**必须要装 Hive 面板吗?** 不必须。面板只是改上限和暂停/恢复的便捷前端;只靠 `cordis.patch.yml` supervisor 也能工作。
|
|
191
|
+
|
|
192
|
+
## 开发
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
npm test # node --test test/*.test.js(89 项)
|
|
196
|
+
npm run check # node --check index.js 和 lib/
|
|
197
|
+
npm pack --dry-run
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
测试是纯 shim(不启动 DSH、不真定时器、不跑真实 CLI),覆盖:默认每角色 5 个、只在飞占名额且完成立刻补位、排队不占名额、0 暂停角色、写入后立即生效且重启后从文件恢复、非法值 400、状态机、卡片 done/fail 路径、仓库发现、命令白名单,以及「不直接 spawn 子进程」的架构守卫。
|
|
201
|
+
|
|
202
|
+
协议见 [SPEC.md](SPEC.md),实现说明见 [docs/DESIGN.md](docs/DESIGN.md)。
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT © Tommy,见 [LICENSE](LICENSE)。
|