dsh-hive-runner 0.6.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 CHANGED
@@ -7,6 +7,23 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
  Version 0.6.0 is the first public snapshot; 0.1.0-0.5.0 were local development
8
8
  iterations of the plugin before this repository was published.
9
9
 
10
+ ## [0.6.1] - 2026-12-04
11
+
12
+ ### Fixed
13
+
14
+ - `hive guard` now runs with the same `--agent` identity as `hive claim`.
15
+ Previously guard used a stable/toolguard identity, so it could be denied by the
16
+ claim's own leases ("README.md — dsh holds it"). Guard denials are now split:
17
+ a scope held by our own claim identity is allowed and renewed instead of
18
+ failing the card, while a scope held by another agent still fails only that
19
+ card with the holder information.
20
+ - `hive release` and `hive renew` also pass the claim identity, so lease cleanup
21
+ no longer depends on the shell environment's `HIVE_AGENT`.
22
+
23
+ ### Published
24
+
25
+ - npm: `dsh-hive-runner@0.6.1` on 2026-12-04.
26
+
10
27
  ## [0.6.0] - 2026-12-04
11
28
 
12
29
  ### Added
@@ -43,3 +60,7 @@ iterations of the plugin before this repository was published.
43
60
  - Card rounds run as DSH subagents through the harness instead of child processes.
44
61
  - Role limits are read from the panel's persisted file first, then plugin config, then
45
62
  the per-role defaults.
63
+
64
+ ### Published
65
+
66
+ - npm: `dsh-hive-runner@0.6.0` on 2026-12-04.
package/SPEC.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-hive-runner — protocol specification
2
2
 
3
- Status: 0.6.0, verified against DSH 0.2.2-rc.5.
3
+ Status: 0.6.1, verified against DSH 0.2.2-rc.5.
4
4
 
5
5
  This document is normative for the host contract of the plugin. It is written for
6
6
  maintainers: user documentation is [README.md](README.md) and
@@ -178,8 +178,11 @@ A missing hook is a deferrable environment error: the repository backs off,
178
178
 
179
179
  Per card:
180
180
 
181
- 1. `hive guard <scope...>` co-signs the card's leases before the worker starts. Exit 2
182
- means another agent holds the scope: that card fails with the holder information and
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
183
186
  no worker or commit happens.
184
187
  2. `hive recall <scope>` lessons are injected into the worker prompt (best effort).
185
188
  3. The worker prompt hard-codes the consensus rules (guard every scope entry including
package/index.js CHANGED
@@ -114,7 +114,7 @@ export function apply(ctx, config = {}) {
114
114
  ttl: { type: 'string', description: 'Claim TTL, for example 5m.' },
115
115
  agent: { type: 'string', description: 'Identity used for claims. Default: config.agent.' },
116
116
  },
117
- output: { schema: { type: 'string' } },
117
+ output: { schema: { type: 'string' }, render: (_args, value) => String(value) },
118
118
  execute: async (args = {}, exec) => {
119
119
  const repo = repoOf(args);
120
120
  const signal = exec?.signal;
@@ -156,7 +156,7 @@ export function apply(ctx, config = {}) {
156
156
  role: { type: 'string', description: 'Filter by Hive role, for example coder or tester.' },
157
157
  limit: { type: 'number', description: 'Maximum number of cards.' },
158
158
  },
159
- output: { schema: { type: 'string' } },
159
+ output: { schema: { type: 'string' }, render: (_args, value) => String(value) },
160
160
  execute: async (args = {}, exec) => {
161
161
  const repo = repoOf(args);
162
162
  const cards = await commands.ready(repo, {
@@ -175,7 +175,7 @@ export function apply(ctx, config = {}) {
175
175
  parameters: {
176
176
  repo: { type: 'string', description: 'Repository path. Default: the configured cwd.' },
177
177
  },
178
- output: { schema: { type: 'string' } },
178
+ output: { schema: { type: 'string' }, render: (_args, value) => String(value) },
179
179
  execute: async (args = {}, exec) => {
180
180
  const repo = repoOf(args);
181
181
  const board = await commands.board(repo, { signal: exec?.signal, session: exec?.agent?.session });
@@ -189,7 +189,7 @@ export function apply(ctx, config = {}) {
189
189
  'Show the resident Hive supervisor state: per-repository state (idle/running/backoff/paused), '
190
190
  + 'last round time, last error, in-flight flag and pause reason. Same data as GET /api/hive-runner?op=status.',
191
191
  parameters: {},
192
- output: { schema: { type: 'string' } },
192
+ output: { schema: { type: 'string' }, render: (_args, value) => String(value) },
193
193
  execute: async () => JSON.stringify(supervisor.status(), null, 2),
194
194
  }));
195
195
  }
package/lib/commands.js CHANGED
@@ -5,8 +5,8 @@
5
5
  * are validated by regular expression and shell-quoted before they enter the
6
6
  * `bash -c` string the shell seam takes. The supervisor only ever runs
7
7
  * `hive-tasks ready|claim|show|done|fail`, the hive-consensus
8
- * `hive guard|release|mode|recall` verbs (plus fixed `git rev-parse HEAD` and a
9
- * card's own acceptance command).
8
+ * `hive guard|release|renew|mode|recall` verbs (plus fixed `git rev-parse HEAD`
9
+ * and a card's own acceptance command).
10
10
  *
11
11
  * No `node:child_process` here: execution goes through `lib/shell.js`.
12
12
  */
@@ -60,7 +60,7 @@ function scopeArgs(paths, name) {
60
60
 
61
61
  /**
62
62
  * Build one allowlisted shell command string.
63
- * @param {'ready'|'claim'|'show'|'done'|'fail'|'board'|'head'|'acceptance'|'guard'|'release'|'mode'|'recall'} verb
63
+ * @param {'ready'|'claim'|'show'|'done'|'fail'|'board'|'head'|'acceptance'|'guard'|'release'|'renew'|'mode'|'recall'} verb
64
64
  * @param {Record<string, unknown>} [args]
65
65
  * @param {{ tasks?: string, hive?: string, git?: string }} [bins]
66
66
  * @returns {string}
@@ -107,12 +107,18 @@ export function buildCommand(verb, args = {}, bins = {}) {
107
107
  return hive + ' board --json';
108
108
  case 'guard': {
109
109
  const keys = scopeArgs(args.paths, 'guard.paths');
110
+ const agent = ' --agent ' + quote(needMatch(AGENT_RE, args.agent, 'guard.agent'));
110
111
  const task = args.id === undefined || args.id === null ? '' : ' --task ' + quote(needMatch(ID_RE, args.id, 'guard.id'));
111
112
  const ttl = args.ttl === undefined || args.ttl === null ? '' : ' --ttl ' + quote(needMatch(TTL_RE, args.ttl, 'guard.ttl'));
112
- return hive + ' guard ' + keys + task + ttl;
113
+ return hive + ' guard ' + keys + agent + task + ttl;
113
114
  }
114
115
  case 'release':
115
- return hive + ' release ' + scopeArgs(args.paths, 'release.paths');
116
+ return hive + ' release ' + scopeArgs(args.paths, 'release.paths')
117
+ + (args.agent === undefined || args.agent === null ? '' : ' --agent ' + quote(needMatch(AGENT_RE, args.agent, 'release.agent')));
118
+ case 'renew':
119
+ return hive + ' renew ' + scopeArgs(args.paths, 'renew.paths')
120
+ + ' --agent ' + quote(needMatch(AGENT_RE, args.agent, 'renew.agent'))
121
+ + ' --ttl ' + quote(needMatch(TTL_RE, args.ttl, 'renew.ttl'));
116
122
  case 'mode':
117
123
  return hive + ' mode';
118
124
  case 'recall': {
@@ -233,11 +239,24 @@ export function createCommands({ ctx, config }) {
233
239
  * caller can map exit 2 to a claim-conflict card failure.
234
240
  */
235
241
  async guard(repo, paths, options = {}) {
236
- return execute('guard', { paths, id: options.taskId, ttl: options.ttl ?? config.ttl }, { ...options, repo });
242
+ return execute('guard', {
243
+ paths,
244
+ agent: options.agent ?? config.agent,
245
+ id: options.taskId,
246
+ ttl: options.ttl ?? config.ttl,
247
+ }, { ...options, repo });
237
248
  },
238
- /** `hive release <scope...>`: drop our leases for the given scope keys (best effort). */
249
+ /** `hive release <scope...> --agent A`: drop our leases (best effort). */
239
250
  async release(repo, paths, options = {}) {
240
- return execute('release', { paths }, { ...options, repo });
251
+ return execute('release', { paths, agent: options.agent ?? config.agent }, { ...options, repo });
252
+ },
253
+ /** `hive renew <scope...> --agent A --ttl T`: extend leases we already hold. */
254
+ async renew(repo, paths, options = {}) {
255
+ return execute('renew', {
256
+ paths,
257
+ agent: options.agent ?? config.agent,
258
+ ttl: options.ttl ?? config.ttl,
259
+ }, { ...options, repo });
241
260
  },
242
261
  /** `hive mode` -> `{ mode: 'free' | 'freeze' | ..., reason }`. */
243
262
  async mode(repo, options = {}) {
package/lib/round.js CHANGED
@@ -38,7 +38,7 @@ export class RoundError extends Error {
38
38
  * @param {Array<{ text: string, status?: string, scope?: string }>} [lessons] recalled hive lessons
39
39
  * @returns {string}
40
40
  */
41
- export function renderPrompt(card, lessons = []) {
41
+ export function renderPrompt(card, lessons = [], claimAgent) {
42
42
  const lines = [
43
43
  '# Task ' + card.id + ': ' + card.title,
44
44
  '',
@@ -54,7 +54,8 @@ export function renderPrompt(card, lessons = []) {
54
54
  if (card.acceptance) lines.push('## Acceptance (the runner will run this)', ' ' + card.acceptance, '');
55
55
  if (card.reason) lines.push('## Previous attempt failed with', card.reason, '');
56
56
  lines.push('## Hive consensus rules (mandatory)');
57
- lines.push('1. At the start, run `hive guard <path...>` for every entry in the card scope (including `resource:` entries, which are leases, not files). It co-signs your leases and marks the board working.');
57
+ lines.push('1. At the start, run `hive guard <path...>` for every entry in the card scope (including `resource:` entries, which are leases, not files). It co-signs your leases and marks the board working.'
58
+ + (claimAgent ? ' Use the same claim identity, for example `hive guard <path...> --agent ' + claimAgent + '`; a different identity would collide with your own leases.' : ''));
58
59
  lines.push('2. If `hive guard` exits 2, stop immediately and report the holder information (stderr) as the failure reason. NEVER bypass it: do not edit files outside the scope, do not `git checkout` files owned by someone else, and do not delete lease refs.');
59
60
  lines.push('3. Your claim already marks the board working with this task id; guard keeps it current.');
60
61
  lines.push('4. Before finishing, release your own leases (`hive release <scope...>`); done/fail normally release them, but verify nothing is left behind.');
@@ -189,15 +190,23 @@ export function createRoundRunner({ ctx, config, commands, limitFor, checkHook =
189
190
  }
190
191
 
191
192
  /** Best-effort release of the leases we own for this card scope. */
192
- async function releaseScope(repo, scope, { signal, session }) {
193
+ async function releaseScope(repo, scope, { signal, session, agent }) {
193
194
  if (scope.length === 0) return;
194
195
  try {
195
- await commands.release(repo, scope, { signal, session });
196
+ await commands.release(repo, scope, { signal, session, agent });
196
197
  } catch {
197
198
  // done/fail already release leases; this is only orphan cleanup.
198
199
  }
199
200
  }
200
201
 
202
+ /** Holder agent names parsed from `hive guard` denial stderr. */
203
+ function deniedHolders(stderr) {
204
+ const holders = new Set();
205
+ const pattern = /([^\s]+)\s+holds it/g;
206
+ for (const match of String(stderr ?? '').matchAll(pattern)) holders.add(match[1]);
207
+ return [...holders];
208
+ }
209
+
201
210
  /** Best-effort release of a claim when the worker could not run at all. */
202
211
  async function releaseClaim(repo, id, error, signal, session) {
203
212
  await commands.fail(repo, id, {
@@ -207,29 +216,38 @@ export function createRoundRunner({ ctx, config, commands, limitFor, checkHook =
207
216
  }).catch(() => {});
208
217
  }
209
218
 
210
- async function executeCard({ repo, card, before, owner, signal, session }) {
219
+ async function executeCard({ repo, card, before, owner, agent, signal, session }) {
211
220
  const id = card.id;
212
221
  const service = assertProvider(config.provider);
213
222
  const scope = scopeOf(card);
223
+ const claimAgent = agent ?? config.agent;
214
224
  let activation;
215
225
  try {
216
- // hive-consensus: co-sign the card's leases (guard) before the worker
217
- // starts. Exit 2 means someone else holds the scope: the card fails with
218
- // the holder information and no work/commit happens.
226
+ // hive-consensus: co-sign the card's leases (guard) with the SAME identity
227
+ // used for the claim. A different identity would collide with the claim's
228
+ // own leases and deny itself.
219
229
  if (scope.length > 0) {
220
230
  const guard = await commands.guard(repo, scope, {
231
+ agent: claimAgent,
221
232
  taskId: id,
222
233
  ttl: config.ttl,
223
234
  signal,
224
235
  session,
225
236
  });
226
237
  if (guard.exitCode === 2) {
227
- const reason = 'guard denied: ' + tail(guard.stderr || guard.stdout || 'scope held by another agent');
228
- await commands.fail(repo, id, { reason, signal, session });
229
- await releaseScope(repo, scope, { signal, session });
230
- return { id, state: 'failed', reason };
231
- }
232
- if (guard.exitCode !== 0) {
238
+ const holders = deniedHolders(guard.stderr);
239
+ const selfHeld = holders.length > 0 && holders.every((holder) => holder === claimAgent);
240
+ if (selfHeld) {
241
+ // Our own earlier lease (for example after a retry): allow the card
242
+ // and extend the leases instead of failing it.
243
+ await commands.renew(repo, scope, { agent: claimAgent, ttl: config.ttl, signal, session }).catch(() => {});
244
+ } else {
245
+ const reason = 'guard denied: ' + tail(guard.stderr || guard.stdout || 'scope held by another agent');
246
+ await commands.fail(repo, id, { reason, signal, session });
247
+ await releaseScope(repo, scope, { signal, session, agent: claimAgent });
248
+ return { id, state: 'failed', reason };
249
+ }
250
+ } else if (guard.exitCode !== 0) {
233
251
  throw new RoundError(
234
252
  'hive/guard-failed',
235
253
  'hive guard exited ' + String(guard.exitCode) + ': ' + tail(guard.stderr || guard.stdout),
@@ -240,7 +258,7 @@ export function createRoundRunner({ ctx, config, commands, limitFor, checkHook =
240
258
  activation = await service.startActivation({
241
259
  provider: config.provider,
242
260
  label: 'hive:' + id,
243
- prompt: [{ type: 'text', text: renderPrompt(card, lessons) }],
261
+ prompt: [{ type: 'text', text: renderPrompt(card, lessons, claimAgent) }],
244
262
  cwd: repo,
245
263
  parent: owner,
246
264
  signal,
@@ -251,17 +269,17 @@ export function createRoundRunner({ ctx, config, commands, limitFor, checkHook =
251
269
  const detail = outcome.diagnostic ? ': ' + tail(outcome.diagnostic) : '';
252
270
  const reason = 'subagent stopped: ' + outcome.stopReason + detail;
253
271
  await commands.fail(repo, id, { reason, signal, session });
254
- await releaseScope(repo, scope, { signal, session });
272
+ await releaseScope(repo, scope, { signal, session, agent: claimAgent });
255
273
  return { id, state: 'failed', reason };
256
274
  }
257
275
  const verdict = await verify({ repo, before, card, signal, session });
258
276
  if (verdict.ok) {
259
277
  await commands.done(repo, id, { sha: verdict.head, verdict: 'pass', signal, session });
260
- await releaseScope(repo, scope, { signal, session });
278
+ await releaseScope(repo, scope, { signal, session, agent: claimAgent });
261
279
  return { id, state: 'done', sha: verdict.head };
262
280
  }
263
281
  await commands.fail(repo, id, { reason: verdict.reason, signal, session });
264
- await releaseScope(repo, scope, { signal, session });
282
+ await releaseScope(repo, scope, { signal, session, agent: claimAgent });
265
283
  return { id, state: 'failed', reason: verdict.reason };
266
284
  } catch (error) {
267
285
  if (isCapacityError(error)) {
@@ -277,7 +295,7 @@ export function createRoundRunner({ ctx, config, commands, limitFor, checkHook =
277
295
  const environment = error?.deferrable === true
278
296
  || (typeof error?.code === 'string' && error.code.startsWith('hive/no-'));
279
297
  if (!environment) await releaseClaim(repo, id, error, signal, session);
280
- await releaseScope(repo, scope, { signal, session });
298
+ await releaseScope(repo, scope, { signal, session, agent: claimAgent });
281
299
  throw error instanceof RoundError
282
300
  ? error
283
301
  : environment
@@ -350,11 +368,11 @@ export function createRoundRunner({ ctx, config, commands, limitFor, checkHook =
350
368
  if (claim.exitCode !== 0) {
351
369
  return { id, state: 'skipped', reason: tail(claim.stderr || claim.stdout) || 'claim rejected' };
352
370
  }
353
- return await executeCard({ repo, card: fresh, before, owner, signal, session });
371
+ return await executeCard({ repo, card: fresh, before, owner, agent: agentId, signal, session });
354
372
  }
355
373
 
356
374
  const before = await commands.head(repo, { signal, session });
357
- return await executeCard({ repo, card: fresh, before, owner, signal, session });
375
+ return await executeCard({ repo, card: fresh, before, owner, agent: agentId, signal, session });
358
376
  },
359
377
  };
360
378
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hive-runner",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "DSH host plugin for Hive: a resident supervisor that runs one DSH subagent per ready task card, with per-role worker limits, pause/resume and Hive tools.",
5
5
  "type": "module",
6
6
  "main": "./index.js",