@hmharness/cli 0.14.22 → 0.14.24
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/main.js +32 -1
- package/dist/tui.js +39 -6
- package/dist/update-check.d.ts +20 -0
- package/dist/update-check.js +38 -0
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -1155,7 +1155,38 @@ flags:
|
|
|
1155
1155
|
stdout.write('manifest: ' + mf + '\n');
|
|
1156
1156
|
return;
|
|
1157
1157
|
}
|
|
1158
|
-
|
|
1158
|
+
if (sub === 'train-prep') {
|
|
1159
|
+
// RL next step: materialize the exported pairs into a trainer-ready
|
|
1160
|
+
// directory (LLaMA-Factory layout): split files + dataset_info.json -
|
|
1161
|
+
// fine-tuning stays an EXTERNAL step (GPU trainer), this is the feed
|
|
1162
|
+
const pairsFile = join(home, 'evolution', 'dpo-pairs.jsonl');
|
|
1163
|
+
let rows = [];
|
|
1164
|
+
try {
|
|
1165
|
+
rows = (await readFile(pairsFile, 'utf8')).trim().split('\n').filter(Boolean).map((l) => JSON.parse(l));
|
|
1166
|
+
}
|
|
1167
|
+
catch {
|
|
1168
|
+
stdout.write('no dpo-pairs.jsonl - run: hmh reward export-dpo\n');
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
const outDir = rest[1] ? require('node:path').resolve(rest[1]) : join(home, 'evolution', 'dpo-export');
|
|
1172
|
+
const { mkdir, writeFile: wf2 } = await import('node:fs/promises');
|
|
1173
|
+
await mkdir(outDir, { recursive: true });
|
|
1174
|
+
const train = rows.filter((r) => r.split !== 'eval');
|
|
1175
|
+
const evalR = rows.filter((r) => r.split === 'eval');
|
|
1176
|
+
const slim = (r) => JSON.stringify({ prompt: r.prompt, chosen: r.chosen, rejected: r.rejected });
|
|
1177
|
+
await wf2(join(outDir, 'dpo-train.jsonl'), train.map(slim).join('\n') + (train.length ? '\n' : ''), 'utf8');
|
|
1178
|
+
await wf2(join(outDir, 'dpo-eval.jsonl'), evalR.map(slim).join('\n') + (evalR.length ? '\n' : ''), 'utf8');
|
|
1179
|
+
const info = {
|
|
1180
|
+
'hmh-dpo-train': { file_name: 'dpo-train.jsonl', ranking: true, columns: { prompt: 'prompt', chosen: 'chosen', rejected: 'rejected' } },
|
|
1181
|
+
'hmh-dpo-eval': { file_name: 'dpo-eval.jsonl', ranking: true, columns: { prompt: 'prompt', chosen: 'chosen', rejected: 'rejected' } },
|
|
1182
|
+
};
|
|
1183
|
+
await wf2(join(outDir, 'dataset_info.json'), JSON.stringify(info, null, 2) + '\n', 'utf8');
|
|
1184
|
+
stdout.write('trainer-ready export:\n');
|
|
1185
|
+
stdout.write(' ' + outDir + '\n');
|
|
1186
|
+
stdout.write(' train ' + train.length + ' · eval ' + evalR.length + ' (prompt-grouped split; see docs/rl-training.md)\n');
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
stdout.write('usage: hmh reward fit | report | export-dpo | train-prep [dir]\n');
|
|
1159
1190
|
return;
|
|
1160
1191
|
}
|
|
1161
1192
|
if (cmd === 'dataset') {
|
package/dist/tui.js
CHANGED
|
@@ -736,10 +736,20 @@ export class TuiRuntime {
|
|
|
736
736
|
addUser(text) {
|
|
737
737
|
const width = Math.max(20, (stdout.columns || 100) - 2);
|
|
738
738
|
const lines = [''];
|
|
739
|
-
|
|
739
|
+
const wrapped = wrapTo(text.replace(/\n+/g, ' '), width);
|
|
740
|
+
// long prompts fold to two lines + a count marker (user ask 2026-09-21:
|
|
741
|
+
// a pasted prompt used to eat half the screen); the driver archives the
|
|
742
|
+
// full text into the Ctrl+T replay so nothing is lost
|
|
743
|
+
const shown = wrapped.length > 2 ? wrapped.slice(0, 2) : wrapped;
|
|
744
|
+
for (const l of shown) {
|
|
740
745
|
const pad = Math.max(1, width - strWidth(l));
|
|
741
746
|
lines.push(' '.repeat(pad) + BOLD(l));
|
|
742
747
|
}
|
|
748
|
+
if (wrapped.length > 2) {
|
|
749
|
+
const note = this.t.tuiUserFolded(wrapped.length - 2);
|
|
750
|
+
const pad = Math.max(1, width - strWidth(note));
|
|
751
|
+
lines.push(' '.repeat(pad) + DIM(note));
|
|
752
|
+
}
|
|
743
753
|
lines.push('');
|
|
744
754
|
this.entries.push({ lines });
|
|
745
755
|
this.scrollFromBottom = 0;
|
|
@@ -1775,10 +1785,24 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1775
1785
|
// update reminder: cached (1/day) registry check, resolved async into the
|
|
1776
1786
|
// transcript via addText (frame-safe); offline stays silent
|
|
1777
1787
|
{
|
|
1778
|
-
|
|
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");
|
|
1779
1793
|
const { createRequire } = await import('node:module');
|
|
1780
1794
|
const current = createRequire(import.meta.url)('../package.json').version;
|
|
1781
|
-
|
|
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
|
+
}
|
|
1782
1806
|
}
|
|
1783
1807
|
let history = [];
|
|
1784
1808
|
// Codex thread semantics: one rollout file per conversation. The first task
|
|
@@ -1982,6 +2006,9 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1982
2006
|
}
|
|
1983
2007
|
async function runSingleTask(line, forkFrom, forkResume) {
|
|
1984
2008
|
rt.addUser(line);
|
|
2009
|
+
// the folded echo hides everything past line 2 - keep the full prompt
|
|
2010
|
+
// retrievable in the Ctrl+T replay
|
|
2011
|
+
fullToolLog.push({ name: 'user', output: line.slice(0, 4000) });
|
|
1985
2012
|
rt.setBusy(true, t.running);
|
|
1986
2013
|
currentAbort = new AbortController();
|
|
1987
2014
|
const injectCh = { queue: [], active: false };
|
|
@@ -1992,6 +2019,10 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1992
2019
|
: [];
|
|
1993
2020
|
const resumeBase = [...planDirective, ...(forkResume ?? history)];
|
|
1994
2021
|
let appender = null;
|
|
2022
|
+
let reasoningBuf = '';
|
|
2023
|
+
const foldThinking = () => { if (reasoningBuf.trim()) {
|
|
2024
|
+
fullToolLog.push({ name: 'thinking', output: reasoningBuf.slice(0, 8000) });
|
|
2025
|
+
} reasoningBuf = ''; rt.foldThinking(); };
|
|
1995
2026
|
let kind = null;
|
|
1996
2027
|
try {
|
|
1997
2028
|
const result = await runAgentTask({
|
|
@@ -2010,8 +2041,10 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2010
2041
|
approvalAsk: (name, args) => rt.requestApproval(name, args),
|
|
2011
2042
|
events: {
|
|
2012
2043
|
onLine: (l) => { if (kind === 'reasoning')
|
|
2013
|
-
|
|
2044
|
+
foldThinking(); appender = null; kind = null; rt.addText(l, 'dim'); },
|
|
2014
2045
|
onDelta: (k, chunk) => {
|
|
2046
|
+
if (k === 'reasoning')
|
|
2047
|
+
reasoningBuf += chunk;
|
|
2015
2048
|
if (k === 'reset') {
|
|
2016
2049
|
// provider retry after a mid-stream cut: drop the half answer
|
|
2017
2050
|
appender?.drop?.();
|
|
@@ -2021,7 +2054,7 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2021
2054
|
}
|
|
2022
2055
|
if (k !== kind) {
|
|
2023
2056
|
if (kind === 'reasoning')
|
|
2024
|
-
|
|
2057
|
+
foldThinking();
|
|
2025
2058
|
appender = rt.startStream(k === 'reasoning' ? 'think' : 'say');
|
|
2026
2059
|
kind = k;
|
|
2027
2060
|
}
|
|
@@ -2029,7 +2062,7 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2029
2062
|
},
|
|
2030
2063
|
onToolCall: (name, args) => {
|
|
2031
2064
|
if (kind === 'reasoning')
|
|
2032
|
-
|
|
2065
|
+
foldThinking();
|
|
2033
2066
|
appender = null;
|
|
2034
2067
|
kind = null;
|
|
2035
2068
|
const brief = name === 'run_command' && typeof args.command === 'string'
|
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.24",
|
|
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
|
}
|