dsh-hive-runner 0.1.0 → 0.6.1
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 +66 -0
- package/LICENSE +21 -0
- package/README.md +274 -10
- package/README.zh-CN.md +206 -0
- package/SPEC.md +212 -0
- package/cordis.patch.yml +80 -2
- package/docs/DESIGN.md +181 -0
- package/index.js +182 -64
- package/lib/commands.js +280 -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 +380 -0
- package/lib/shell.js +72 -0
- package/lib/supervisor.js +574 -0
- package/package.json +45 -10
package/SPEC.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# dsh-hive-runner — protocol specification
|
|
2
|
+
|
|
3
|
+
Status: 0.6.1, verified against DSH 0.2.2-rc.5.
|
|
4
|
+
|
|
5
|
+
This document is normative for the host contract of the plugin. It is written for
|
|
6
|
+
maintainers: user documentation is [README.md](README.md) and
|
|
7
|
+
[README.zh-CN.md](README.zh-CN.md) and deliberately omits these details. Implementation
|
|
8
|
+
notes are in [docs/DESIGN.md](docs/DESIGN.md).
|
|
9
|
+
|
|
10
|
+
## 1. Package contract
|
|
11
|
+
|
|
12
|
+
| Field | Value | Meaning |
|
|
13
|
+
| --- | --- | --- |
|
|
14
|
+
| `name` | `dsh-hive-runner` | Package and Cordis plugin name |
|
|
15
|
+
| `main` / `exports["."]` | `./index.js` | Cordis host plugin (`name`, `inject`, `apply`) |
|
|
16
|
+
| `dsh.bundle.patch` | `./cordis.patch.yml` | Inserts the host plugin entry (`id: hive-runner`) into the composition |
|
|
17
|
+
| `peerDependencies` | `@deepseek-ai/dsh-tools` | Provided by the DSH host |
|
|
18
|
+
| `engines.node` | `>=22` | Matches the DSH runtime |
|
|
19
|
+
|
|
20
|
+
## 2. Host surfaces
|
|
21
|
+
|
|
22
|
+
| Surface | Registration | Purpose |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| `HiveSupervisor` | `ctx.provide('hiveSupervisor', supervisor)` | Resident scheduler service |
|
|
25
|
+
| Timer | `ctx.effect(() => { supervisor.start(); return () => supervisor.stop() })` | Ticks while DSH runs, independent of browser tabs |
|
|
26
|
+
| Fetch route | `ctx.connection.fetch.register({ path: '/api/hive-runner', methods: ['GET','POST'], requestBody: 'buffered', fetch })` | Same-origin control and observability |
|
|
27
|
+
| Tools | `ctx.tools.register(defineTool(...))` | `hive_run_round`, `hive_tasks_ready`, `hive_board`, `hive_supervisor_status` |
|
|
28
|
+
|
|
29
|
+
All shell work goes through `ctx.shell.resolve` + `ctx.shell.execute`; card workers are
|
|
30
|
+
DSH subagents started with `ctx.subagents.startActivation`. The plugin never imports
|
|
31
|
+
`node:child_process` (architecture test).
|
|
32
|
+
|
|
33
|
+
## 3. HTTP protocol
|
|
34
|
+
|
|
35
|
+
Path: `/api/hive-runner`, JSON request/response, same-origin and authenticated by DSH's
|
|
36
|
+
connection layer.
|
|
37
|
+
|
|
38
|
+
Errors: unknown `op` -> `400`; missing `repo` -> `400`; unknown repository -> `404`;
|
|
39
|
+
wrong method -> `405` (`hive/method-not-allowed`).
|
|
40
|
+
|
|
41
|
+
### 3.1 `GET ?op=status`
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"ok": true,
|
|
46
|
+
"op": "status",
|
|
47
|
+
"started": true,
|
|
48
|
+
"intervalMs": 30000,
|
|
49
|
+
"idleBackoffMs": 120000,
|
|
50
|
+
"maxConcurrentRepos": 2,
|
|
51
|
+
"maxConsecutiveFailures": 3,
|
|
52
|
+
"roleConcurrency": { "coder": 5, "tester": 5 },
|
|
53
|
+
"repoRoleConcurrency": {},
|
|
54
|
+
"defaultRoleConcurrency": 5,
|
|
55
|
+
"capacityRetryMs": 2000,
|
|
56
|
+
"lastTickAt": "2026-12-04T00:00:00.000Z",
|
|
57
|
+
"lastDiscoverError": null,
|
|
58
|
+
"repos": [
|
|
59
|
+
{
|
|
60
|
+
"repo": "/abs/repo",
|
|
61
|
+
"state": "running",
|
|
62
|
+
"lastRoundAt": "2026-12-04T00:00:01.000Z",
|
|
63
|
+
"lastError": null,
|
|
64
|
+
"inFlight": true,
|
|
65
|
+
"paused": false,
|
|
66
|
+
"pausedBy": null,
|
|
67
|
+
"pausedReason": null,
|
|
68
|
+
"lastCheckAt": "2026-12-04T00:00:02.000Z",
|
|
69
|
+
"nextAttemptAt": null,
|
|
70
|
+
"consecutiveFailures": 0,
|
|
71
|
+
"lastCards": 0,
|
|
72
|
+
"lastResults": 0,
|
|
73
|
+
"backlog": { "queued": 3, "inFlight": 5, "completed": 12 },
|
|
74
|
+
"roles": {
|
|
75
|
+
"coder": { "limit": 5, "live": 5, "queued": 3 },
|
|
76
|
+
"tester": { "limit": 5, "live": 0, "queued": 0 }
|
|
77
|
+
},
|
|
78
|
+
"limitsError": null,
|
|
79
|
+
"environmentError": null,
|
|
80
|
+
"mode": null,
|
|
81
|
+
"frozenSkipped": 0,
|
|
82
|
+
"lastSkipReason": null
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
- `roles[role].limit` — effective live-worker cap (persisted file > repo config >
|
|
89
|
+
global role config > `defaultRoleConcurrency`).
|
|
90
|
+
- `roles[role].live` — workers running right now; a finished worker frees its slot
|
|
91
|
+
immediately.
|
|
92
|
+
- `roles[role].queued` — fetched cards waiting for a slot; they do not count as live.
|
|
93
|
+
- `backlog` — aggregate `{ queued, inFlight, completed }` for the current or last drain.
|
|
94
|
+
- `state` — `idle` | `running` | `backoff` | `paused`.
|
|
95
|
+
|
|
96
|
+
### 3.2 `POST ?op=pause` / `POST ?op=resume`
|
|
97
|
+
|
|
98
|
+
Body or query: `{ "repo": "/abs/repo" }`. Response:
|
|
99
|
+
`{ ok: true, op: "pause"|"resume", repo: <repository status> }`.
|
|
100
|
+
|
|
101
|
+
### 3.3 `POST ?op=limits`
|
|
102
|
+
|
|
103
|
+
Body:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{ "repo": "/abs/repo", "roleLimits": { "coder": 2, "tester": 0 } }
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- Values are integers `0..999`; `0` pauses the role. Role names match
|
|
110
|
+
`/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/`.
|
|
111
|
+
- The values merge into `<repo>/.hive/limits.json` (atomic write) and apply to the next
|
|
112
|
+
dispatch immediately; a running drain reads limits only at its start.
|
|
113
|
+
- Response: `{ ok: true, op: "limits", repo: <repository status> }`.
|
|
114
|
+
- Malformed values -> `400` `hive/invalid-role-limits`.
|
|
115
|
+
|
|
116
|
+
## 4. Per-repository limits
|
|
117
|
+
|
|
118
|
+
Precedence for one role in one repository:
|
|
119
|
+
|
|
120
|
+
1. `<repo>/.hive/limits.json` role entry (written by `op=limits`, read at startup,
|
|
121
|
+
hot-reloaded when mtime/size changes);
|
|
122
|
+
2. `config.roleConcurrency["<abs repo>"]` (repository override in the plugin config);
|
|
123
|
+
3. `config.roleConcurrency[role]` (global role map; default `{ coder: 5, tester: 5 }`);
|
|
124
|
+
4. `config.defaultRoleConcurrency` (default `5`, for every role not listed above).
|
|
125
|
+
|
|
126
|
+
The persisted file contains only runtime overrides and is safe to commit. Shape:
|
|
127
|
+
`{ "coder": 2, "tester": 0 }`. A malformed file is ignored, previous values stay and
|
|
128
|
+
`limitsError` is reported in status.
|
|
129
|
+
|
|
130
|
+
## 5. Concurrency and capacity
|
|
131
|
+
|
|
132
|
+
- At most 5 **live** workers per role per repository by default.
|
|
133
|
+
- Queued cards do not occupy a slot; when a worker finishes it immediately takes the next
|
|
134
|
+
queued card of the same role.
|
|
135
|
+
- `maxConcurrentRepos` (default 2) limits how many repositories drain at the same time;
|
|
136
|
+
a single repository is always serial.
|
|
137
|
+
- DSH's `subagent.maxActiveSubagents` is the hard ceiling below the plugin:
|
|
138
|
+
`startActivation` can reject with `ACTIVATION_LIMIT_REACHED`. The queue requeues the
|
|
139
|
+
claimed card, waits `capacityRetryMs` (default 2000) and retries; nothing is dropped.
|
|
140
|
+
- A role limit of `0` leaves the role's ready cards untouched on the Hive board.
|
|
141
|
+
|
|
142
|
+
## 6. Supervisor state machine
|
|
143
|
+
|
|
144
|
+
```text
|
|
145
|
+
idle --tick, ready cards--> running --drain done--> idle (next tick)
|
|
146
|
+
idle --tick, no cards--> backoff (idleBackoffMs)
|
|
147
|
+
running --drain exception--> backoff (intervalMs * 2^failures, capped at idleBackoffMs)
|
|
148
|
+
running --3 consecutive exceptions--> paused (auto; requires explicit resume)
|
|
149
|
+
paused --resume--> idle
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Card-level failures (no commit, acceptance failure, non-completed subagent) are recorded
|
|
153
|
+
in Hive as `fail` and do not count as round exceptions. Environmental errors (no live
|
|
154
|
+
parent agent, no subagent provider) are deferrable: they set `lastError` and back off
|
|
155
|
+
for `idleBackoffMs` without consuming the failure budget.
|
|
156
|
+
|
|
157
|
+
## 7. Tools
|
|
158
|
+
|
|
159
|
+
All tools return a JSON string. `repo` defaults to `config.cwd` and must be a configured
|
|
160
|
+
repository unless it is that default.
|
|
161
|
+
|
|
162
|
+
| Tool | Parameters | Output |
|
|
163
|
+
| --- | --- | --- |
|
|
164
|
+
| `hive_run_round` | `repo`, `ttl`, `agent` | Per-card results, role state and remaining queue |
|
|
165
|
+
| `hive_tasks_ready` | `repo`, `role`, `limit` | Ready cards, best first |
|
|
166
|
+
| `hive_board` | `repo` | Presence board |
|
|
167
|
+
| `hive_supervisor_status` | - | Same data as `GET ?op=status` |
|
|
168
|
+
|
|
169
|
+
Tool-triggered rounds use the calling Session's sandbox policy; resident rounds use the
|
|
170
|
+
deployment policy with the repository pinned as the workspace root.
|
|
171
|
+
|
|
172
|
+
## 8. Round preconditions and worker protocol
|
|
173
|
+
|
|
174
|
+
Before every drain the supervisor requires a Hive-initialised repository whose
|
|
175
|
+
`<repo>/.git/hooks/pre-commit` runs merge-on-commit (it mentions merge-on-commit or moc).
|
|
176
|
+
A missing hook is a deferrable environment error: the repository backs off,
|
|
177
|
+
`environmentError` is reported, and no card is failed and no auto-pause counts.
|
|
178
|
+
|
|
179
|
+
Per card:
|
|
180
|
+
|
|
181
|
+
1. `hive guard <scope...> --agent <claim identity>` co-signs the card's leases before
|
|
182
|
+
the worker starts, using the SAME identity as `hive claim` (a different identity would
|
|
183
|
+
be denied by the claim's own leases). Exit 2 with our own identity as the holder is
|
|
184
|
+
allowed and renewed; exit 2 means another agent holds the scope: that card fails with
|
|
185
|
+
the holder information and
|
|
186
|
+
no worker or commit happens.
|
|
187
|
+
2. `hive recall <scope>` lessons are injected into the worker prompt (best effort).
|
|
188
|
+
3. The worker prompt hard-codes the consensus rules (guard every scope entry including
|
|
189
|
+
`resource:` keys, stop and report on exit 2, never edit out of scope or drop lease
|
|
190
|
+
refs) and the commit rules (plain `git commit` only, never `--no-verify`/history
|
|
191
|
+
rewrites, resolve hook conflicts in place).
|
|
192
|
+
4. Done verification requires HEAD to have moved and the merge-on-commit hook to still be
|
|
193
|
+
present; leases for the scope are best-effort released after done or fail.
|
|
194
|
+
|
|
195
|
+
The supervisor reads the Hive mode every round: in freeze mode only fix cards are
|
|
196
|
+
dispatched, other ready cards stay on the board and are reported through `mode`,
|
|
197
|
+
`frozenSkipped` and `lastSkipReason`.
|
|
198
|
+
|
|
199
|
+
## 9. Security invariants
|
|
200
|
+
|
|
201
|
+
- Commands are built from fixed templates; ids, roles, agents, TTLs and shas are
|
|
202
|
+
regex-validated, free text is POSIX-quoted before entering `bash -c`.
|
|
203
|
+
- Card `acceptance` is repository-controlled shell under the same policy: treat the
|
|
204
|
+
repository as trusted input.
|
|
205
|
+
- The route is same-origin and authenticated by DSH; no port is opened.
|
|
206
|
+
- Auto-paused repositories require an explicit resume.
|
|
207
|
+
|
|
208
|
+
## 10. Compatibility
|
|
209
|
+
|
|
210
|
+
Host APIs used: `tools.register`, `shell.resolve/execute`, `subagents.startActivation`,
|
|
211
|
+
`connection.fetch.register`, `provide`, `effect`. A DSH upgrade can change these:
|
|
212
|
+
re-run `npm test` and `npm run check` against the installed DSH before releasing.
|
package/cordis.patch.yml
CHANGED
|
@@ -1,5 +1,83 @@
|
|
|
1
|
-
# dsh-hive-runner — DSH host half
|
|
1
|
+
# dsh-hive-runner — DSH host half for Hive.
|
|
2
|
+
#
|
|
3
|
+
# The plugin registers a resident HiveSupervisor (Cordis service + effect-owned
|
|
4
|
+
# timer), three Hive tools plus hive_supervisor_status, and the same-origin
|
|
5
|
+
# observability route /api/hive-runner.
|
|
6
|
+
#
|
|
7
|
+
# Supervisor semantics (see README):
|
|
8
|
+
# tick every intervalMs; dispatch every ready card (one subagent per task) and
|
|
9
|
+
# drain the queue, retrying when DSH subagent capacity is exhausted; one drain
|
|
10
|
+
# per repository at a time; at most maxConcurrentRepos repositories
|
|
11
|
+
# concurrently; no ready cards -> back off idleBackoffMs; drain exception ->
|
|
12
|
+
# exponential backoff; maxConsecutiveFailures consecutive exceptions ->
|
|
13
|
+
# auto-paused (POST ?op=resume to clear).
|
|
14
|
+
#
|
|
15
|
+
# This plugin never invokes `hive-run --watch`: it schedules its own rounds.
|
|
2
16
|
- insert:
|
|
3
17
|
- id: hive-runner
|
|
4
18
|
name: dsh-hive-runner
|
|
5
|
-
config:
|
|
19
|
+
config:
|
|
20
|
+
# Repository registry: absolute paths. Empty = supervisor idles until a
|
|
21
|
+
# repository is discovered or added by a future release (status API and
|
|
22
|
+
# the tools still work).
|
|
23
|
+
repos: []
|
|
24
|
+
# Optional auto-discovery: scan discoverRoots (below) for git repositories
|
|
25
|
+
# whose git dir has refs/hive/v1, bounded by discoverDepth and skipping
|
|
26
|
+
# node_modules/.git. When discoverRoots is empty, the parent directory of
|
|
27
|
+
# every configured repo is scanned.
|
|
28
|
+
autoDiscover: false
|
|
29
|
+
discoverRoots: []
|
|
30
|
+
discoverDepth: 3
|
|
31
|
+
discoverIntervalMs: 600000
|
|
32
|
+
# Tick period (ms). Per-repository scheduling is independent of this:
|
|
33
|
+
# a running drain or a backoff does not block another repository.
|
|
34
|
+
intervalMs: 30000
|
|
35
|
+
# No-work backoff (ms): a repository with no ready cards is skipped this
|
|
36
|
+
# long instead of re-reading the board on every tick.
|
|
37
|
+
idleBackoffMs: 120000
|
|
38
|
+
# Cross-repository concurrency cap. A single repository is always serial.
|
|
39
|
+
maxConcurrentRepos: 2
|
|
40
|
+
# Consecutive round exceptions before the repository is auto-paused.
|
|
41
|
+
# Paused repositories need POST /api/hive-runner?op=resume (or a restart
|
|
42
|
+
# with the path removed from `paused`).
|
|
43
|
+
maxConsecutiveFailures: 3
|
|
44
|
+
# Repositories paused at startup (absolute paths). Manual resume works.
|
|
45
|
+
paused: []
|
|
46
|
+
# Claim identity / claim TTL.
|
|
47
|
+
agent: dsh
|
|
48
|
+
ttl: 5m
|
|
49
|
+
# Per-role LIVE-worker limits, per repository. Default five workers per
|
|
50
|
+
# role; 0 pauses a role (its ready cards stay on the board). These are
|
|
51
|
+
# the config defaults/fallbacks — each repository can persist its own
|
|
52
|
+
# limits in <repo>/.hive/limits.json (written by the panel's limit
|
|
53
|
+
# control, hot-reloaded on mtime change, and safe to commit).
|
|
54
|
+
# Repository overrides may also be given here with absolute-path keys:
|
|
55
|
+
# "/abs/repo": { coder: 3 }
|
|
56
|
+
# Unlisted roles fall back to defaultRoleConcurrency below.
|
|
57
|
+
roleConcurrency:
|
|
58
|
+
coder: 5
|
|
59
|
+
tester: 5
|
|
60
|
+
# Fallback live-worker limit for roles not listed in roleConcurrency.
|
|
61
|
+
defaultRoleConcurrency: 5
|
|
62
|
+
# Delay (ms) before retrying queued cards when DSH subagent capacity is
|
|
63
|
+
# exhausted (ACTIVATION_LIMIT_REACHED).
|
|
64
|
+
capacityRetryMs: 2000
|
|
65
|
+
# Subagent provider used to run card workers (spawn is the shipped
|
|
66
|
+
# in-process fresh-child backend).
|
|
67
|
+
provider: spawn
|
|
68
|
+
# Optional: parent supervisor card workers with this live session instead of
|
|
69
|
+
# the first live agent. Without a live parent agent a round is deferred,
|
|
70
|
+
# not failed.
|
|
71
|
+
parentSession: null
|
|
72
|
+
# Tool default repository when a tool call does not pass `repo`.
|
|
73
|
+
cwd: null
|
|
74
|
+
# Binaries (absolute path or PATH name); the HIVE_*_BIN env vars win.
|
|
75
|
+
tasksBin: null
|
|
76
|
+
hiveBin: null
|
|
77
|
+
gitBin: git
|
|
78
|
+
# Timeouts (ms).
|
|
79
|
+
cliTimeoutMs: 120000
|
|
80
|
+
headTimeoutMs: 30000
|
|
81
|
+
acceptanceTimeoutMs: 900000
|
|
82
|
+
# Verbose supervisor logging.
|
|
83
|
+
debug: false
|
package/docs/DESIGN.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# dsh-hive-runner — design and wire protocol
|
|
2
|
+
|
|
3
|
+
This document is for maintainers. User documentation lives in
|
|
4
|
+
[`README.md`](../README.md) / [`README.zh-CN.md`](../README.zh-CN.md) and does
|
|
5
|
+
not describe transport details.
|
|
6
|
+
|
|
7
|
+
## 1. Host surfaces
|
|
8
|
+
|
|
9
|
+
| Surface | Registration | Purpose |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `HiveSupervisor` | `ctx.provide('hiveSupervisor', supervisor)` | Resident scheduler service |
|
|
12
|
+
| Timer | `ctx.effect(() => { supervisor.start(); return () => supervisor.stop(); })` | Ticks while DSH runs, independent of browser tabs |
|
|
13
|
+
| Fetch route | `ctx.connection.fetch.register({ path: '/api/hive-runner', methods: ['GET','POST'], requestBody: 'buffered', fetch })` | Same-origin control/observability |
|
|
14
|
+
| Tools | `ctx.tools.register(defineTool(...))` | `hive_run_round`, `hive_tasks_ready`, `hive_board`, `hive_supervisor_status` |
|
|
15
|
+
|
|
16
|
+
All shell work goes through `ctx.shell.resolve` + `ctx.shell.execute`; card
|
|
17
|
+
workers are DSH subagents via `ctx.subagents.startActivation`. No
|
|
18
|
+
`node:child_process` anywhere (architecture test enforces this).
|
|
19
|
+
|
|
20
|
+
## 2. HTTP protocol
|
|
21
|
+
|
|
22
|
+
Path: `/api/hive-runner`. JSON request/response. Unknown `op` → `400`;
|
|
23
|
+
missing `repo` → `400`; unknown `repo` → `404`.
|
|
24
|
+
|
|
25
|
+
### `GET ?op=status`
|
|
26
|
+
|
|
27
|
+
Response:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"ok": true,
|
|
32
|
+
"op": "status",
|
|
33
|
+
"started": true,
|
|
34
|
+
"intervalMs": 30000,
|
|
35
|
+
"idleBackoffMs": 120000,
|
|
36
|
+
"maxConcurrentRepos": 2,
|
|
37
|
+
"maxConsecutiveFailures": 3,
|
|
38
|
+
"roleConcurrency": { "coder": 5, "tester": 5 },
|
|
39
|
+
"repoRoleConcurrency": {},
|
|
40
|
+
"defaultRoleConcurrency": 5,
|
|
41
|
+
"capacityRetryMs": 2000,
|
|
42
|
+
"lastTickAt": "2026-12-04T00:00:00.000Z",
|
|
43
|
+
"lastDiscoverError": null,
|
|
44
|
+
"repos": [
|
|
45
|
+
{
|
|
46
|
+
"repo": "/abs/repo",
|
|
47
|
+
"state": "running",
|
|
48
|
+
"lastRoundAt": "2026-12-04T00:00:01.000Z",
|
|
49
|
+
"lastError": null,
|
|
50
|
+
"inFlight": true,
|
|
51
|
+
"paused": false,
|
|
52
|
+
"pausedBy": null,
|
|
53
|
+
"pausedReason": null,
|
|
54
|
+
"lastCheckAt": "2026-12-04T00:00:02.000Z",
|
|
55
|
+
"nextAttemptAt": null,
|
|
56
|
+
"consecutiveFailures": 0,
|
|
57
|
+
"lastCards": 0,
|
|
58
|
+
"lastResults": 0,
|
|
59
|
+
"backlog": { "queued": 3, "inFlight": 5, "completed": 12 },
|
|
60
|
+
"roles": {
|
|
61
|
+
"coder": { "limit": 5, "live": 5, "queued": 3 },
|
|
62
|
+
"tester": { "limit": 5, "live": 0, "queued": 0 }
|
|
63
|
+
},
|
|
64
|
+
"limitsError": null
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- `roles[role].limit` — effective live-worker cap (persisted file > config >
|
|
71
|
+
`defaultRoleConcurrency`).
|
|
72
|
+
- `roles[role].live` — card workers running **now**; a completed worker frees
|
|
73
|
+
its slot immediately.
|
|
74
|
+
- `roles[role].queued` — fetched cards waiting for a slot (they do not count
|
|
75
|
+
against `live`).
|
|
76
|
+
- `backlog` — aggregate `{ queued, inFlight, completed }` for the current or
|
|
77
|
+
last drain.
|
|
78
|
+
- `state` — `idle` | `running` | `backoff` | `paused`.
|
|
79
|
+
|
|
80
|
+
### `POST ?op=pause` / `POST ?op=resume`
|
|
81
|
+
|
|
82
|
+
Body or query: `{ "repo": "/abs/repo" }`. Returns
|
|
83
|
+
`{ ok: true, op: "pause"|"resume", repo: <repository status> }`.
|
|
84
|
+
|
|
85
|
+
### `POST ?op=limits`
|
|
86
|
+
|
|
87
|
+
Body:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{ "repo": "/abs/repo", "roleLimits": { "coder": 2, "tester": 0 } }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- `roleLimits` values are integers `0..999`; `0` pauses the role. Role names
|
|
94
|
+
match `/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/`.
|
|
95
|
+
- The values merge into `<repo>/.hive/limits.json` (atomic write) and apply to
|
|
96
|
+
the next dispatch immediately; a running drain reads limits only at its start.
|
|
97
|
+
- Returns `{ ok: true, op: "limits", repo: <repository status> }`.
|
|
98
|
+
- Malformed values → `400` `hive/invalid-role-limits`; non-POST → `405`
|
|
99
|
+
`hive/method-not-allowed`; unknown repo → `404`.
|
|
100
|
+
|
|
101
|
+
## 3. Per-repository limits
|
|
102
|
+
|
|
103
|
+
Precedence for one role in one repository:
|
|
104
|
+
|
|
105
|
+
1. `<repo>/.hive/limits.json` role entry (runtime/persisted, written by
|
|
106
|
+
`op=limits`, read at startup and hot-reloaded when mtime/size changes);
|
|
107
|
+
2. `config.roleConcurrency["<abs repo>"]` (repo override in the plugin config);
|
|
108
|
+
3. `config.roleConcurrency[role]` (global role map; default
|
|
109
|
+
`{ coder: 5, tester: 5 }`);
|
|
110
|
+
4. `config.defaultRoleConcurrency` (default `5`; applies to every role not
|
|
111
|
+
listed above).
|
|
112
|
+
|
|
113
|
+
The persisted file contains only runtime overrides and is safe to commit. A
|
|
114
|
+
malformed file is ignored (previous in-memory values stay, `limitsError` is
|
|
115
|
+
reported in status). File shape:
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{ "coder": 2, "tester": 0 }
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 4. Concurrency and capacity
|
|
122
|
+
|
|
123
|
+
- Default behaviour: at most 5 **live** workers per role per repository.
|
|
124
|
+
- Queued cards do not occupy a slot. A worker that finishes a card immediately
|
|
125
|
+
takes the next queued card of the same role.
|
|
126
|
+
- `maxConcurrentRepos` (default 2) limits how many repositories may drain at the
|
|
127
|
+
same time. A repository is always serial.
|
|
128
|
+
- DSH's `subagent.maxActiveSubagents` is the hard ceiling below the plugin:
|
|
129
|
+
`startActivation` can reject with `ACTIVATION_LIMIT_REACHED`. The queue
|
|
130
|
+
treats that as a retry: the claimed card goes back to its role queue, the
|
|
131
|
+
worker waits `capacityRetryMs` (default 2000), and retries. Nothing is
|
|
132
|
+
dropped.
|
|
133
|
+
- A role limit of `0` leaves its ready cards untouched on the Hive board.
|
|
134
|
+
|
|
135
|
+
## 5. Supervisor state machine
|
|
136
|
+
|
|
137
|
+
```text
|
|
138
|
+
idle --tick, ready cards--> running --drain done--> idle (next tick in intervalMs)
|
|
139
|
+
idle --tick, no cards--> backoff (idleBackoffMs 120s)
|
|
140
|
+
running --drain exception--> backoff (intervalMs * 2^failures, capped idleBackoffMs)
|
|
141
|
+
running --3 consecutive exceptions--> paused (auto; requires resume)
|
|
142
|
+
paused --resume--> idle
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Card-level failures (no commit / acceptance failure / non-completed subagent)
|
|
146
|
+
are recorded in Hive as `fail` and do not count as round exceptions.
|
|
147
|
+
Environmental errors (no live parent Agent, no subagent provider) are
|
|
148
|
+
deferrable: they set `lastError` and back off for `idleBackoffMs` without
|
|
149
|
+
consuming the failure budget.
|
|
150
|
+
|
|
151
|
+
## 6. Module layout
|
|
152
|
+
|
|
153
|
+
| File | Responsibility |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| `index.js` | Cordis plugin entry: config, limits store, supervisor service/timer, Fetch route, tools |
|
|
156
|
+
| `lib/supervisor.js` | Repository registry + state machine + per-repo queue/backlog/roles; exposes `setRoleLimits` |
|
|
157
|
+
| `lib/queue.js` | Live-only per-role worker pools, immediate slot refill, capacity requeue, per-role state callback |
|
|
158
|
+
| `lib/round.js` | One card end to end: claim → subagent activation → commit/acceptance verify → done/fail |
|
|
159
|
+
| `lib/limits.js` | `<repo>/.hive/limits.json` read/write/hot-reload and precedence helpers |
|
|
160
|
+
| `lib/config.js` | Config defaults/validation, role map parsing, effective-limit helpers |
|
|
161
|
+
| `lib/commands.js` | Allowlisted `hive-tasks` / `git` / acceptance commands with shell quoting |
|
|
162
|
+
| `lib/shell.js` | `ctx.shell.resolve/execute` adapter (sandbox policy per call) |
|
|
163
|
+
| `lib/discover.js` | `refs/hive/v1` repository discovery |
|
|
164
|
+
| `lib/http.js` | `/api/hive-runner` Fetch route (status/pause/resume/limits) |
|
|
165
|
+
|
|
166
|
+
## 7. Security notes
|
|
167
|
+
|
|
168
|
+
- Commands are built from fixed templates; card ids, roles, agents, TTLs and
|
|
169
|
+
shas are regex-validated, free text is POSIX-quoted before entering `bash -c`.
|
|
170
|
+
- Agentless supervisor calls resolve the deployment sandbox policy and pin its
|
|
171
|
+
workspace root to the target repository; tool-triggered calls use the calling
|
|
172
|
+
session's policy.
|
|
173
|
+
- Card `acceptance` is repository-controlled shell under the same policy: treat
|
|
174
|
+
the repository as trusted input.
|
|
175
|
+
|
|
176
|
+
## 8. Tests
|
|
177
|
+
|
|
178
|
+
`node --test test/*.test.js`. Suites: supervisor state machine and limits
|
|
179
|
+
persistence/hot reload, live-only role queue, single-card round paths, config,
|
|
180
|
+
HTTP protocol (including `op=limits` validation), discovery, command allowlist,
|
|
181
|
+
and an architecture guard (no child processes; README protocol hygiene).
|