dsh-hive-runner 1.0.17 → 1.0.19

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,49 @@ 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.19] - 2026-12-05
11
+
12
+ ### Fixed
13
+
14
+ - Task titles are mechanically validated before any card is created: `hive_tasks`
15
+ `add`/`edit`, every `split` replacement card (and `hive_intervene` cards through the
16
+ same command layer) reject titles starting with a repository/stage prefix plus id or
17
+ a bare numeric id plus colon, with the exact rule text `标题只写结果本身:不要仓库/阶段
18
+ 前缀与编号(编号由 id 承载),例如用『实现背景音乐生成』而不是『ai/A5:实现背景音乐生成』`.
19
+ - The `hive_tasks` tool description and `title` parameter now carry the rule so the
20
+ model rewrites the title immediately instead of retrying the same shape.
21
+
22
+ ### Tests
23
+
24
+ - Prefix/id rejection, normal result-only titles, split child validation, and the tool
25
+ description rule; 277 tests pass.
26
+
27
+ ## [1.0.18] - 2026-12-05
28
+
29
+ ### Fixed
30
+
31
+ - Long-running guidance now points at agent work: `长驻服务用 service 任务声明
32
+ (.hive/services.yaml),由 worker 用 setsid/nohup 启动并由 supervisor 守护`.
33
+ - Service-role worker prompts now carry the full start contract: the declared
34
+ command, `setsid nohup <command> >> .hive/services/<name>.log 2>&1 &`, the
35
+ `.hive/services/<name>.json` PID/port/health record, and the health-URL acceptance.
36
+ The runner loads `.hive/services.yaml` for service cards/tags and injects the real
37
+ declaration; the supervisor patrol probes and re-dispatches on outage.
38
+ - `startService` creates `.hive/services/` before the shell opens the log redirect, so
39
+ the detached process starts reliably.
40
+
41
+ ### Tests
42
+
43
+ - Real end-to-end service lifecycle: temp repo + services.yaml -> supervisor dispatches
44
+ a service card -> detached process listens -> worker returns and the service stays
45
+ alive -> kill -> patrol audit creates the restart card -> restart recovers the port.
46
+ Also verifies the service declaration reaches the round runner's worker prompt.
47
+ 274 tests pass.
48
+
49
+ ### Published
50
+
51
+ - npm: `dsh-hive-runner@1.0.18` on 2026-12-05.
52
+
10
53
  ## [1.0.17] - 2026-12-05
11
54
 
12
55
  ### Added
@@ -33,6 +76,10 @@ iterations of the plugin before this repository was published.
33
76
  detached start/PID record, health acceptance, down/recovery redispatch and failed-card
34
77
  reopen. 271 tests pass.
35
78
 
79
+ ### Published
80
+
81
+ - npm: `dsh-hive-runner@1.0.17` on 2026-12-05.
82
+
36
83
  ## [1.0.16] - 2026-12-05
37
84
 
38
85
  ### 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/SPEC.md CHANGED
@@ -237,6 +237,10 @@ for `idleBackoffMs` without consuming the failure budget.
237
237
  All tools return a JSON string. `repo` defaults to `config.cwd` and must be a configured
238
238
  repository unless it is that default.
239
239
 
240
+ Task titles contain only the result: `hive_tasks add/edit` and every `split` card reject
241
+ repository/stage prefixes and `编号:` prefixes (the id carries the number), e.g.
242
+ `实现背景音乐生成`, not `ai/A5:实现背景音乐生成`.
243
+
240
244
  | Tool | Parameters | Output |
241
245
  | --- | --- | --- |
242
246
  | `hive_run_round` | `repo`, `ttl`, `agent` | Per-task results, role state and remaining queue |
package/index.js CHANGED
@@ -567,6 +567,7 @@ export function apply(ctx, config = {}) {
567
567
  + 'supersede marks a task (including a claimed/running one) as superseded without changing its state and requires a reason; '
568
568
  + 'reopen resets any task to pending with an attempt+1 and an optional reason; retry moves a failed task back to pending; '
569
569
  + 'rm deletes a task (the CLI refuses a claimed task — reopen or wait for the claim to expire first). '
570
+ + 'TITLE RULE (enforced for add/edit/split cards): write only the result itself — no repo/stage prefix and no number prefix; the id carries the number. Use 『实现背景音乐生成』, never 『ai/A5:实现背景音乐生成』. '
570
571
  + 'The queen uses these for ordering, splitting, goal evolution and remediation; workers alone claim and finish tasks.',
571
572
  parameters: {
572
573
  repo: repoParameter,
@@ -578,7 +579,7 @@ export function apply(ctx, config = {}) {
578
579
  id: { type: 'string', description: 'Task id (show/edit/split/supersede/reopen/retry/rm).' },
579
580
  state: { type: 'string', enum: ['pending', 'claimed', 'done', 'failed'], description: 'list: state filter.' },
580
581
  role: { type: 'string', description: 'list/add/edit: role filter or new role for the task(s).' },
581
- title: { type: 'string', description: 'add/edit: task title.' },
582
+ title: { type: 'string', description: 'add/edit: task title — only the result itself; never a repo/stage prefix or number prefix (the id carries it), e.g. 实现背景音乐生成 not ai/A5:实现背景音乐生成.' },
582
583
  goal: { type: 'string', description: 'add: goal of the task (hive-tasks 1.9 edit cannot change it).' },
583
584
  scope: { type: 'array', items: { type: 'string' }, description: 'add/edit: paths or resource keys (edit replaces the list; the runner translates it to scope add/remove).' },
584
585
  after: { type: 'array', items: { type: 'string' }, description: 'add/edit: task ids that must be done first (edit replaces the list).' },
package/lib/commands.js CHANGED
@@ -23,6 +23,25 @@ export class HiveCommandError extends Error {
23
23
  }
24
24
  }
25
25
 
26
+ /** Exact title rule shown to the model and used in the mechanical rejection. */
27
+ export const TASK_TITLE_MESSAGE = '标题只写结果本身:不要仓库/阶段前缀与编号(编号由 id 承载),例如用『实现背景音乐生成』而不是『ai/A5:实现背景音乐生成』';
28
+
29
+ const PREFIXED_TITLE_RE = /^[^\s::/]+\/[^\s::]*\d+\s*[::]/u;
30
+ const NUMBERED_TITLE_RE = /^(?:[A-Za-z]+[-_]?)?\d+\s*[::]/u;
31
+
32
+ /**
33
+ * Reject repository/stage prefixes and numeric ids in task titles. The id
34
+ * carries the number; the title must describe only the result.
35
+ * @param {string} title
36
+ * @returns {string} the trimmed title
37
+ */
38
+ export function validateTaskTitle(title) {
39
+ const value = typeof title === 'string' ? title.trim() : '';
40
+ if (PREFIXED_TITLE_RE.test(value) || NUMBERED_TITLE_RE.test(value)) {
41
+ throw new HiveCommandError('hive/invalid-argument', TASK_TITLE_MESSAGE);
42
+ }
43
+ return value;
44
+ }
26
45
  export const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
27
46
  export const AGENT_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
28
47
  export const TTL_RE = /^\d{1,4}[smhd]$/;
@@ -221,7 +240,7 @@ export function buildCommand(verb, args = {}, bins = {}) {
221
240
  + (role === null ? '' : ' --role ' + quote(role));
222
241
  }
223
242
  case 'add': {
224
- const title = textArg(args.title, 'add.title', 300);
243
+ const title = validateTaskTitle(textArg(args.title, 'add.title', 300));
225
244
  const parts = [tasks, 'add', '--json', '--title', quote(title)];
226
245
  const role = args.role === undefined || args.role === null || args.role === ''
227
246
  ? null
@@ -256,7 +275,7 @@ export function buildCommand(verb, args = {}, bins = {}) {
256
275
  const parts = [tasks, 'edit', quote(id), '--json'];
257
276
  let changes = 0;
258
277
  const title = optionalText(args.title, 'edit.title', 300);
259
- if (title !== null) { parts.push('--title', quote(title)); changes += 1; }
278
+ if (title !== null) { parts.push('--title', quote(validateTaskTitle(title))); changes += 1; }
260
279
  if (args.role !== undefined && args.role !== null && args.role !== '') {
261
280
  parts.push('--role', quote(needMatch(CARD_ROLE_RE, args.role, 'edit.role')));
262
281
  changes += 1;
@@ -318,7 +337,7 @@ export function buildCommand(verb, args = {}, bins = {}) {
318
337
  );
319
338
  }
320
339
  }
321
- const card = { title: textArg(entry.title, 'split.cards[' + index + '].title', 300) };
340
+ const card = { title: validateTaskTitle(textArg(entry.title, 'split.cards[' + index + '].title', 300)) };
322
341
  if (entry.role !== undefined) card.role = needMatch(CARD_ROLE_RE, entry.role, 'split.cards[' + index + '].role');
323
342
  if (entry.scope !== undefined) card.scope = listArg(entry.scope, 'split.cards[' + index + '].scope');
324
343
  if (entry.acceptance !== undefined) card.acceptance = textArg(entry.acceptance, 'split.cards[' + index + '].acceptance');
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.19",
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",