dsh-hive-runner 1.0.17 → 1.0.18

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,28 @@ 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
+ ## [1.0.18] - 2026-12-05
11
+
12
+ ### Fixed
13
+
14
+ - Long-running guidance now points at agent work: `长驻服务用 service 任务声明
15
+ (.hive/services.yaml),由 worker 用 setsid/nohup 启动并由 supervisor 守护`.
16
+ - Service-role worker prompts now carry the full start contract: the declared
17
+ command, `setsid nohup <command> >> .hive/services/<name>.log 2>&1 &`, the
18
+ `.hive/services/<name>.json` PID/port/health record, and the health-URL acceptance.
19
+ The runner loads `.hive/services.yaml` for service cards/tags and injects the real
20
+ declaration; the supervisor patrol probes and re-dispatches on outage.
21
+ - `startService` creates `.hive/services/` before the shell opens the log redirect, so
22
+ the detached process starts reliably.
23
+
24
+ ### Tests
25
+
26
+ - Real end-to-end service lifecycle: temp repo + services.yaml -> supervisor dispatches
27
+ a service card -> detached process listens -> worker returns and the service stays
28
+ alive -> kill -> patrol audit creates the restart card -> restart recovers the port.
29
+ Also verifies the service declaration reaches the round runner's worker prompt.
30
+ 274 tests pass.
31
+
10
32
  ## [1.0.17] - 2026-12-05
11
33
 
12
34
  ### Added
@@ -33,6 +55,10 @@ iterations of the plugin before this repository was published.
33
55
  detached start/PID record, health acceptance, down/recovery redispatch and failed-card
34
56
  reopen. 271 tests pass.
35
57
 
58
+ ### Published
59
+
60
+ - npm: `dsh-hive-runner@1.0.17` on 2026-12-05.
61
+
36
62
  ## [1.0.16] - 2026-12-05
37
63
 
38
64
  ### Fixed — hard repository isolation (release blocker)
package/README.md CHANGED
@@ -169,7 +169,8 @@ flushed on the next patrol/registration.
169
169
 
170
170
  Long-running processes are agent work, not a human step. A repository can declare
171
171
  its services in `.hive/services.yaml` (`name`, `command`, `port`, optional 127.0.0.1
172
- `health`). A `service`-role card starts one with a detached
172
+ `health`). A `service`-role card's worker prompt carries the declared start command;
173
+ the worker starts it in the exact detached form
173
174
  `setsid nohup <command> >> .hive/services/<name>.log 2>&1 &` and records
174
175
  `.hive/services/<name>.json` (PID/port). The acceptance command is a local health
175
176
  check, so the card can be done while the service keeps running. The patrol reads the
package/lib/ops.js CHANGED
@@ -18,7 +18,7 @@ export const OPS_MAX_OUTPUT_BYTES = 64 * 1024;
18
18
  /** Hard timeout for one hive_ops command. */
19
19
  export const OPS_TIMEOUT_MS = 120_000;
20
20
  /** Exact message for dev/serve/watch attempts. */
21
- export const OPS_LONG_RUNNING_MESSAGE = '长驻服务由面板/宿主启动或建 ops 任务';
21
+ export const OPS_LONG_RUNNING_MESSAGE = '长驻服务用 service 任务声明(.hive/services.yaml),由 worker 用 setsid/nohup 启动并由 supervisor 守护';
22
22
 
23
23
  /** The complete action enum. Nothing outside this list is callable. */
24
24
  export const OPS_ACTIONS = Object.freeze([
package/lib/round.js CHANGED
@@ -22,6 +22,7 @@ import { HiveCommandError, tail } from './commands.js';
22
22
  import { assertMergeOnCommitHook } from './hooks.js';
23
23
  import { acquireHiveAgentEnv } from './host-env.js';
24
24
  import { isCapacityError } from './queue.js';
25
+ import { loadServiceDeclarations, serviceStartCommand } from './services.js';
25
26
  import { writeRunRecord } from './runs.js';
26
27
 
27
28
  /** Reopen reason used when the supervisor recovers a claim after a restart. */
@@ -45,7 +46,7 @@ export class RoundError extends Error {
45
46
  * @param {Array<{ text: string, status?: string, scope?: string }>} [lessons] recalled hive lessons
46
47
  * @returns {string}
47
48
  */
48
- export function renderPrompt(card, lessons = [], claimAgent) {
49
+ export function renderPrompt(card, lessons = [], claimAgent, serviceInfo = null) {
49
50
  const lines = [
50
51
  '# Task ' + card.id + ': ' + card.title,
51
52
  '',
@@ -69,6 +70,23 @@ export function renderPrompt(card, lessons = [], claimAgent) {
69
70
  lines.push('');
70
71
  }
71
72
  if (card.acceptance) lines.push('## Acceptance (the runner will run this)', ' ' + card.acceptance, '');
73
+ // Long-running services are started by a service-role worker, not by a human
74
+ // and not through hive_ops. The prompt carries the exact detached-start and
75
+ // metadata contract so the worker cannot invent a foreground process.
76
+ if (card.role === 'service' || serviceInfo !== null) {
77
+ const name = serviceInfo?.name ?? '<name>';
78
+ const command = serviceInfo?.command ?? '<declared command>';
79
+ const port = serviceInfo?.port ?? '<port>';
80
+ const health = serviceInfo?.health ?? 'http://127.0.0.1:<port>';
81
+ const start = serviceInfo?.startCommand ?? 'setsid nohup <command> >> .hive/services/<name>.log 2>&1 &';
82
+ lines.push('## Long-running service contract (mandatory)');
83
+ lines.push('1. Only the service declared in `.hive/services.yaml` may be started; never run an undeclared command and never start dev/serve/watch through `hive_ops`.');
84
+ lines.push('2. Start it detached exactly like this: `' + start + '`');
85
+ lines.push('3. Immediately write `.hive/services/' + name + '.json` with `{"name":"' + name + '","command":"' + command + '","port":' + port + ',"health":"' + health + '","pid":<PID>}` so the supervisor can find and restart it.');
86
+ lines.push('4. Acceptance is the local health check: `curl -sf ' + health + ' >/dev/null` (the runner runs it). The process must outlive this worker session; do not stop it in the background or wait for it in the foreground.');
87
+ lines.push('5. The supervisor patrol probes the declared port; when the process dies it creates or reopens a service card to restart it. Do not edit source files outside the declared service scope.');
88
+ lines.push('');
89
+ }
72
90
  // Reopen reasons are the queen's guidance channel: they lead the prompt so a
73
91
  // retried worker reads the diagnosis and the instruction before the goal.
74
92
  if (card.reason) lines.push('## Queen guidance for this attempt (previous outcome)', card.reason, '');
@@ -552,6 +570,28 @@ export function createRoundRunner({
552
570
  // is still running.
553
571
  recordRun(repo, run);
554
572
  const lessons = recall.lessons;
573
+ // A service-role card gets the exact detached-start contract and the
574
+ // declared command/port/health from .hive/services.yaml.
575
+ let serviceInfo = null;
576
+ const cardTags = Array.isArray(card.tags) ? card.tags : [];
577
+ if (card.role === 'service' || cardTags.includes('service')) {
578
+ try {
579
+ const declarations = loadServiceDeclarations(repo);
580
+ const tag = cardTags.find((entry) => typeof entry === 'string' && entry.startsWith('service:'));
581
+ const name = tag === undefined ? null : tag.slice('service:'.length);
582
+ const declaration = declarations.find((entry) => entry.name === name)
583
+ ?? (declarations.length === 1 ? declarations[0] : null);
584
+ if (declaration !== null) {
585
+ serviceInfo = {
586
+ ...declaration,
587
+ startCommand: serviceStartCommand(declaration),
588
+ recordPath: '.hive/services/' + declaration.name + '.json',
589
+ };
590
+ }
591
+ } catch (error) {
592
+ log('warn', 'card ' + id + ' could not read .hive/services.yaml: ' + messageOf(error));
593
+ }
594
+ }
555
595
  // Workers run in-process; DSH's bash tool inherits ambient env. Inject the
556
596
  // claim identity and this card's instance while the worker is alive, so
557
597
  // its own `hive guard` / `hive release` calls agree with the runner's.
@@ -590,7 +630,7 @@ export function createRoundRunner({
590
630
  service.startActivation({
591
631
  provider: config.provider,
592
632
  label: 'hive:' + id,
593
- prompt: [{ type: 'text', text: renderPrompt(card, lessons, claimAgent) }],
633
+ prompt: [{ type: 'text', text: renderPrompt(card, lessons, claimAgent, serviceInfo) }],
594
634
  cwd: repo,
595
635
  parent: owner,
596
636
  signal: workerSignal,
package/lib/services.js CHANGED
@@ -171,6 +171,8 @@ export async function startService({ repo, name, run, now = () => Date.now(), ap
171
171
  if (typeof run !== 'function') throw new TypeError('startService: run is required');
172
172
  const declaration = findService(repo, name);
173
173
  const command = serviceStartCommand(declaration);
174
+ // The redirect target must exist before the detached shell opens it.
175
+ fs.mkdirSync(path.join(repo, SERVICES_DIR), { recursive: true });
174
176
  const result = await run(command, { workdir: repo });
175
177
  if (result?.timedOut === true) throw new Error('service start timed out: ' + name);
176
178
  const pid = Number.parseInt(String(result?.stdout ?? '').trim(), 10);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hive-runner",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
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",