@hmharness/cli 0.14.23 → 0.14.25
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/dist/evolution-daemon.d.ts +12 -0
- package/dist/evolution-daemon.js +113 -0
- package/dist/main.js +85 -1
- package/dist/tui.js +16 -2
- package/dist/update-check.d.ts +20 -0
- package/dist/update-check.js +38 -0
- package/package.json +2 -2
|
@@ -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();
|
|
@@ -1155,7 +1208,38 @@ flags:
|
|
|
1155
1208
|
stdout.write('manifest: ' + mf + '\n');
|
|
1156
1209
|
return;
|
|
1157
1210
|
}
|
|
1158
|
-
|
|
1211
|
+
if (sub === 'train-prep') {
|
|
1212
|
+
// RL next step: materialize the exported pairs into a trainer-ready
|
|
1213
|
+
// directory (LLaMA-Factory layout): split files + dataset_info.json -
|
|
1214
|
+
// fine-tuning stays an EXTERNAL step (GPU trainer), this is the feed
|
|
1215
|
+
const pairsFile = join(home, 'evolution', 'dpo-pairs.jsonl');
|
|
1216
|
+
let rows = [];
|
|
1217
|
+
try {
|
|
1218
|
+
rows = (await readFile(pairsFile, 'utf8')).trim().split('\n').filter(Boolean).map((l) => JSON.parse(l));
|
|
1219
|
+
}
|
|
1220
|
+
catch {
|
|
1221
|
+
stdout.write('no dpo-pairs.jsonl - run: hmh reward export-dpo\n');
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
const outDir = rest[1] ? require('node:path').resolve(rest[1]) : join(home, 'evolution', 'dpo-export');
|
|
1225
|
+
const { mkdir, writeFile: wf2 } = await import('node:fs/promises');
|
|
1226
|
+
await mkdir(outDir, { recursive: true });
|
|
1227
|
+
const train = rows.filter((r) => r.split !== 'eval');
|
|
1228
|
+
const evalR = rows.filter((r) => r.split === 'eval');
|
|
1229
|
+
const slim = (r) => JSON.stringify({ prompt: r.prompt, chosen: r.chosen, rejected: r.rejected });
|
|
1230
|
+
await wf2(join(outDir, 'dpo-train.jsonl'), train.map(slim).join('\n') + (train.length ? '\n' : ''), 'utf8');
|
|
1231
|
+
await wf2(join(outDir, 'dpo-eval.jsonl'), evalR.map(slim).join('\n') + (evalR.length ? '\n' : ''), 'utf8');
|
|
1232
|
+
const info = {
|
|
1233
|
+
'hmh-dpo-train': { file_name: 'dpo-train.jsonl', ranking: true, columns: { prompt: 'prompt', chosen: 'chosen', rejected: 'rejected' } },
|
|
1234
|
+
'hmh-dpo-eval': { file_name: 'dpo-eval.jsonl', ranking: true, columns: { prompt: 'prompt', chosen: 'chosen', rejected: 'rejected' } },
|
|
1235
|
+
};
|
|
1236
|
+
await wf2(join(outDir, 'dataset_info.json'), JSON.stringify(info, null, 2) + '\n', 'utf8');
|
|
1237
|
+
stdout.write('trainer-ready export:\n');
|
|
1238
|
+
stdout.write(' ' + outDir + '\n');
|
|
1239
|
+
stdout.write(' train ' + train.length + ' · eval ' + evalR.length + ' (prompt-grouped split; see docs/rl-training.md)\n');
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
stdout.write('usage: hmh reward fit | report | export-dpo | train-prep [dir]\n');
|
|
1159
1243
|
return;
|
|
1160
1244
|
}
|
|
1161
1245
|
if (cmd === 'dataset') {
|
package/dist/tui.js
CHANGED
|
@@ -1785,10 +1785,24 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1785
1785
|
// update reminder: cached (1/day) registry check, resolved async into the
|
|
1786
1786
|
// transcript via addText (frame-safe); offline stays silent
|
|
1787
1787
|
{
|
|
1788
|
-
|
|
1788
|
+
// 2026-09-21 user direction: updates are ZERO-ACTION - a newer version
|
|
1789
|
+
// installs itself in the background (detached npm, next launch picks it
|
|
1790
|
+
// up; never swaps files under the running process) and we only SAY so.
|
|
1791
|
+
// Opt out with config.json tui.autoUpdate=false (falls back to the hint).
|
|
1792
|
+
const { notifyUpdate, autoUpdate } = await import("./update-check.js");
|
|
1789
1793
|
const { createRequire } = await import('node:module');
|
|
1790
1794
|
const current = createRequire(import.meta.url)('../package.json').version;
|
|
1791
|
-
|
|
1795
|
+
if (cfg.tui?.autoUpdate === false) {
|
|
1796
|
+
void notifyUpdate(home, current, (latest) => rt.addText(`↑ ${t.updateHint(latest)}`, 'dim'));
|
|
1797
|
+
}
|
|
1798
|
+
else {
|
|
1799
|
+
void autoUpdate({
|
|
1800
|
+
home,
|
|
1801
|
+
current,
|
|
1802
|
+
say: (latest) => rt.addText(t.tuiAutoUpdating(latest), 'dim'),
|
|
1803
|
+
sayFail: (why) => rt.addText(t.tuiAutoUpdateFailed(why), 'dim'),
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1792
1806
|
}
|
|
1793
1807
|
let history = [];
|
|
1794
1808
|
// Codex thread semantics: one rollout file per conversation. The first task
|
package/dist/update-check.d.ts
CHANGED
|
@@ -17,3 +17,23 @@ export declare function checkForUpdate(opts: {
|
|
|
17
17
|
/** Fire-and-forget wrapper for interactive frontends: resolve-and-say, or
|
|
18
18
|
* say nothing at all. Never rejects. */
|
|
19
19
|
export declare function notifyUpdate(home: string, current: string, say: (line: string) => void): Promise<void>;
|
|
20
|
+
/** Background self-update (user direction 2026-09-21: zero-action updates,
|
|
21
|
+
* notify only). NEVER swaps files under the running process - npm runs
|
|
22
|
+
* detached and the new version is picked up on the NEXT launch, so a
|
|
23
|
+
* mid-session install cannot corrupt the live TUI (Windows also locks
|
|
24
|
+
* files in use, and this machine EPERMs on locked writes). A lock file
|
|
25
|
+
* keeps concurrent hmh instances from racing one npm install. */
|
|
26
|
+
export declare function autoUpdate(opts: {
|
|
27
|
+
home: string;
|
|
28
|
+
current: string;
|
|
29
|
+
say: (line: string) => void;
|
|
30
|
+
sayFail?: (line: string) => void;
|
|
31
|
+
spawnImpl?: (cmd: string, args: string[], o: {
|
|
32
|
+
detached: boolean;
|
|
33
|
+
stdio: unknown;
|
|
34
|
+
cwd: string;
|
|
35
|
+
}) => {
|
|
36
|
+
unref: () => void;
|
|
37
|
+
};
|
|
38
|
+
now?: number;
|
|
39
|
+
}): Promise<void>;
|
package/dist/update-check.js
CHANGED
|
@@ -65,3 +65,41 @@ export async function notifyUpdate(home, current, say) {
|
|
|
65
65
|
}
|
|
66
66
|
catch { /* never surface update-check failures */ }
|
|
67
67
|
}
|
|
68
|
+
/** Background self-update (user direction 2026-09-21: zero-action updates,
|
|
69
|
+
* notify only). NEVER swaps files under the running process - npm runs
|
|
70
|
+
* detached and the new version is picked up on the NEXT launch, so a
|
|
71
|
+
* mid-session install cannot corrupt the live TUI (Windows also locks
|
|
72
|
+
* files in use, and this machine EPERMs on locked writes). A lock file
|
|
73
|
+
* keeps concurrent hmh instances from racing one npm install. */
|
|
74
|
+
export async function autoUpdate(opts) {
|
|
75
|
+
try {
|
|
76
|
+
const info = await checkForUpdate({ home: opts.home, current: opts.current, now: opts.now });
|
|
77
|
+
if (!info)
|
|
78
|
+
return;
|
|
79
|
+
const { open } = await import('node:fs/promises');
|
|
80
|
+
const lockFile = join(opts.home, 'updating.lck');
|
|
81
|
+
const now = opts.now ?? Date.now();
|
|
82
|
+
try {
|
|
83
|
+
const prev = JSON.parse(await readFile(lockFile, 'utf8'));
|
|
84
|
+
if (now - prev.time < 10 * 60_000) {
|
|
85
|
+
opts.say?.(info.latest + ' (another hmh is already updating)');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch { /* no lock */ }
|
|
90
|
+
await mkdir(opts.home, { recursive: true });
|
|
91
|
+
const log = await open(join(opts.home, 'update.log'), 'a');
|
|
92
|
+
const spawnFn = opts.spawnImpl ?? ((await import('node:child_process')).spawn);
|
|
93
|
+
const child = spawnFn('npm', ['install', '-g', '@hmharness/cli@' + info.latest, '--registry=https://registry.npmjs.org/', '--no-fund', '--no-audit'], {
|
|
94
|
+
detached: true,
|
|
95
|
+
stdio: ['ignore', log.fd, log.fd],
|
|
96
|
+
cwd: opts.home,
|
|
97
|
+
});
|
|
98
|
+
child.unref();
|
|
99
|
+
await writeFile(lockFile, JSON.stringify({ time: now, to: info.latest }), 'utf8');
|
|
100
|
+
opts.say(info.latest);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
opts.sayFail?.(String(err).slice(0, 80));
|
|
104
|
+
}
|
|
105
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.25",
|
|
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",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@hmharness/evolution": "0.14.15",
|
|
49
49
|
"@hmharness/domain-harmony": "0.13.6",
|
|
50
50
|
"@hmharness/domain-ops": "0.8.1",
|
|
51
|
-
"@hmharness/agent": "0.14.
|
|
51
|
+
"@hmharness/agent": "0.14.14",
|
|
52
52
|
"@hmharness/evaluation": "0.8.0",
|
|
53
53
|
"@hmharness/web": "0.9.2"
|
|
54
54
|
}
|