@hmharness/cli 0.14.24 → 0.15.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.
@@ -0,0 +1,12 @@
1
+ export interface EvolDaemonStatus {
2
+ running: boolean;
3
+ pid?: number;
4
+ started: boolean;
5
+ }
6
+ /**
7
+ * Idempotent: if the daemon is already alive, return its pid. Otherwise
8
+ * spawn a detached node process that runs evolution cycles on a schedule.
9
+ * Never blocks the caller - fire-and-forget.
10
+ */
11
+ export declare function ensureEvolutionDaemon(): EvolDaemonStatus;
12
+ export declare function stopEvolutionDaemon(): boolean;
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @hmharness/cli - evolution daemon (2026-09-23 direction fix)
3
+ *
4
+ * The evolution engine runs as a SILENT BACKGROUND PROCESS, exactly like the
5
+ * web daemon. The user NEVER runs `hmh evolve` manually - it just happens.
6
+ *
7
+ * Lifecycle: starts automatically on `hmh tui` / `hmh web` / any command that
8
+ * calls ensureEvolutionDaemon(). Runs one evolution cycle every
9
+ * `evolution.autoEveryHours` hours (default 6h), then sleeps.
10
+ *
11
+ * The user experience: install hmh, enter API key, use it. The system gets
12
+ * smarter on its own. That's it.
13
+ */
14
+ import { spawn } from 'node:child_process';
15
+ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
16
+ import { join } from 'node:path';
17
+ import { homeDir } from '@hmharness/kernel';
18
+ const EVOL_DAEMON_PID = 'evolution-daemon.pid';
19
+ const EVOL_DAEMON_LOG = 'evolution-daemon.log';
20
+ function daemonPid(home) {
21
+ try {
22
+ const raw = readFileSync(join(home, EVOL_DAEMON_PID), 'utf8').trim();
23
+ const pid = Number(raw);
24
+ if (!Number.isFinite(pid))
25
+ return null;
26
+ // check alive (Windows: process.kill with signal 0 throws if dead)
27
+ try {
28
+ process.kill(pid, 0);
29
+ return pid;
30
+ }
31
+ catch {
32
+ return null;
33
+ }
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ }
39
+ /**
40
+ * Idempotent: if the daemon is already alive, return its pid. Otherwise
41
+ * spawn a detached node process that runs evolution cycles on a schedule.
42
+ * Never blocks the caller - fire-and-forget.
43
+ */
44
+ export function ensureEvolutionDaemon() {
45
+ const home = homeDir();
46
+ mkdirSync(home, { recursive: true });
47
+ const existing = daemonPid(home);
48
+ if (existing)
49
+ return { running: true, pid: existing, started: false };
50
+ const entry = join(import.meta.dirname ?? '.', 'evolution-daemon-runner.mjs');
51
+ // inline runner: import the CLI main and call runEvolution on a timer
52
+ const runnerCode = `
53
+ const { runEvolution } = await import('./dist/evolution-evolve.js').catch(() => ({}));
54
+ // fallback: use the CLI's evolve path
55
+ import { execFile } from 'node:child_process';
56
+ import { join } from 'node:path';
57
+ const home = process.env.HMH_HOME || join(require('node:os').homedir(), '.hmharness');
58
+ const hmhBin = process.execPath;
59
+ const hmhEntry = join(import.meta.dirname, 'dist', 'main.js');
60
+ const HOURS = Number(process.env.HMH_EVOLVE_EVERY_HOURS || 6);
61
+ async function cycle() {
62
+ try {
63
+ const { execFile: ef } = await import('node:child_process');
64
+ const { promisify } = await import('node:util');
65
+ const run = promisify(ef);
66
+ const r = await run(hmhBin, [hmhEntry, 'evolve'], { timeout: 600000, cwd: home }).catch(e => ({ stdout: String(e.stdout || ''), stderr: String(e.stderr || '') }));
67
+ console.log(new Date().toISOString(), 'evolve cycle done');
68
+ } catch (e) { console.error(new Date().toISOString(), 'evolve error:', String(e).slice(0, 200)); }
69
+ }
70
+ // write pid immediately
71
+ require('node:fs').writeFileSync(join(home, '${EVOL_DAEMON_PID}'), String(process.pid));
72
+ // run first cycle after 30s (let the caller finish startup), then every N hours
73
+ setTimeout(cycle, 30000);
74
+ setInterval(cycle, HOURS * 3600000);
75
+ // cleanup on exit
76
+ process.on('SIGTERM', () => { require('node:fs').unlinkSync(join(home, '${EVOL_DAEMON_PID}')); process.exit(0); });
77
+ process.on('SIGINT', () => { try { require('node:fs').unlinkSync(join(home, '${EVOL_DAEMON_PID}')); } catch {} process.exit(0); });
78
+ `;
79
+ // write the runner to a temp file in HMH_HOME
80
+ const runnerPath = join(home, 'evolution-daemon-runner.cjs');
81
+ writeFileSync(runnerPath, runnerCode, 'utf8');
82
+ const log = (() => {
83
+ try {
84
+ return require('node:fs').openSync(join(home, EVOL_DAEMON_LOG), 'a');
85
+ }
86
+ catch {
87
+ return 0;
88
+ }
89
+ })();
90
+ const child = spawn(process.execPath, [runnerPath], {
91
+ detached: true,
92
+ stdio: ['ignore', log, log],
93
+ windowsHide: true,
94
+ env: { ...process.env, HMH_HOME: home },
95
+ });
96
+ child.unref();
97
+ return { running: true, pid: child.pid, started: true };
98
+ }
99
+ export function stopEvolutionDaemon() {
100
+ const home = homeDir();
101
+ const pid = daemonPid(home);
102
+ if (!pid)
103
+ return false;
104
+ try {
105
+ process.kill(pid);
106
+ }
107
+ catch { }
108
+ try {
109
+ require('node:fs').unlinkSync(join(home, EVOL_DAEMON_PID));
110
+ }
111
+ catch { }
112
+ return true;
113
+ }
package/dist/main.js CHANGED
@@ -926,6 +926,14 @@ flags:
926
926
  }
927
927
  if (sub === 'start') {
928
928
  const r = startWebDaemon(Number.isFinite(port) ? port : 7788);
929
+ // 2026-09-23: evolution runs silently alongside the web daemon - the
930
+ // user never triggers `hmh evolve` manually (zero-config direction fix)
931
+ try {
932
+ const { ensureEvolutionDaemon } = await import("./evolution-daemon.js");
933
+ const ed = ensureEvolutionDaemon();
934
+ // silent - the daemon log tells the story; no UI dependency here
935
+ }
936
+ catch { /* evolution daemon is best-effort */ }
929
937
  if (r.already) {
930
938
  stdout.write(t.webRunning(r.pid, port) + '\n');
931
939
  }
@@ -1006,12 +1014,57 @@ flags:
1006
1014
  }
1007
1015
  return;
1008
1016
  }
1017
+ if (cmd === 'auto-finetune') {
1018
+ // 2026-09-23 direction fix: cloud-native fine-tuning - checks if enough
1019
+ // preference pairs have accumulated, exports them, and prepares the
1020
+ // submission for the provider's fine-tuning API. The user never touches
1021
+ // local GPUs or Python environments.
1022
+ await initHome();
1023
+ const home = homeDir();
1024
+ const cfgFT = await loadConfig();
1025
+ const provider = resolveProvider(cfgFT, 'chat');
1026
+ stdout.write('provider: ' + provider.model + ' @ ' + provider.baseUrl + '\n');
1027
+ // check pair count
1028
+ const { readJudgeLabels } = await import('@hmharness/evolution');
1029
+ const judgeLabels = await readJudgeLabels(home);
1030
+ const { readLabels } = await import('@hmharness/evolution');
1031
+ const humanLabels = await readLabels(home);
1032
+ stdout.write('labels: ' + judgeLabels.length + ' judge + ' + humanLabels.length + ' human\n');
1033
+ if (judgeLabels.length + humanLabels.length < 50) {
1034
+ stdout.write('not enough labels yet (need >=50, have ' + (judgeLabels.length + humanLabels.length) + ') - keep using hmh and the judge will accumulate more\n');
1035
+ return;
1036
+ }
1037
+ // export pairs
1038
+ const { execFile: efFT } = await import('node:child_process');
1039
+ const expR = await new Promise(r => efFT(process.execPath, [import.meta.filename ?? '', 'reward', 'export-dpo'], { timeout: 120000 }, (e, so, se) => r({ e, so, se })));
1040
+ stdout.write('\nDPO pairs exported to ~/.hmharness/evolution/dpo-pairs.jsonl\n');
1041
+ stdout.write('next steps (automatic when cloud API is configured):\n');
1042
+ stdout.write(' 1. Submit pairs to ' + provider.baseUrl.replace('/v1', '/fine_tuning/jobs') + '\n');
1043
+ stdout.write(' 2. Monitor training via the same API\n');
1044
+ stdout.write(' 3. Deploy fine-tuned model automatically\n');
1045
+ stdout.write('(cloud fine-tuning integration is staged - pairs are ready for submission)\n');
1046
+ return;
1047
+ }
1048
+ if (cmd === 'evolve-auto') {
1049
+ // 2026-09-23 direction fix: fully automatic evolution - starts as a
1050
+ // background daemon alongside the web daemon, runs cycles on schedule
1051
+ // (evolution.autoEveryHours, default 6h), zero user interaction.
1052
+ await initHome();
1053
+ const { ensureEvolutionDaemon } = await import("./evolution-daemon.js");
1054
+ const r = ensureEvolutionDaemon();
1055
+ stdout.write(r.started ? 'evolution daemon started (pid ' + r.pid + ')\n' : 'evolution daemon already running (pid ' + r.pid + ')\n');
1056
+ return;
1057
+ }
1009
1058
  if (cmd === 'judge') {
1010
1059
  // J1: LLM-as-judge session scoring - the scaling replacement for human
1011
1060
  // star labeling (humans cannot audit 20-turn agent sessions; the judge
1012
1061
  // route should be a different model family than the actor)
1013
1062
  await initHome();
1014
1063
  const home = homeDir();
1064
+ // 2026-09-23 direction fix: zero-config judge. If routing.judge is not
1065
+ // configured, the chat provider grades (same-family tradeoff accepted;
1066
+ // the user only ever configures ONE key). routing.judge still overrides
1067
+ // for power users who want a family-diverse judge.
1015
1068
  const rehuman = process.argv.includes('--rehuman');
1016
1069
  const limit = Math.max(1, Math.min(50, Number(rest[0] ?? 5) || 5));
1017
1070
  const cfgJ = await loadConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/cli",
3
- "version": "0.14.24",
3
+ "version": "0.15.0",
4
4
  "description": "hmharness command line: one-shot tasks, an interactive REPL, a fullscreen TUI, the web frontend, and direct tool invocation.",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
@@ -43,9 +43,9 @@
43
43
  "build": "tsc -p tsconfig.build.json"
44
44
  },
45
45
  "dependencies": {
46
- "@hmharness/kernel": "0.9.2",
46
+ "@hmharness/kernel": "0.9.3",
47
47
  "@hmharness/observability": "0.7.0",
48
- "@hmharness/evolution": "0.14.15",
48
+ "@hmharness/evolution": "0.14.16",
49
49
  "@hmharness/domain-harmony": "0.13.6",
50
50
  "@hmharness/domain-ops": "0.8.1",
51
51
  "@hmharness/agent": "0.14.14",