@hmharness/cli 0.14.20 → 0.14.22

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 CHANGED
@@ -1129,16 +1129,17 @@ flags:
1129
1129
  const { writeFile: wf } = await import('node:fs/promises');
1130
1130
  // dataset form (J1): deterministic 80/20 split annotated per row,
1131
1131
  // leakage audit, and a versioned manifest beside the pairs file
1132
- const split = E.splitDpoPairs(pairs);
1132
+ const uniq = E.dedupeDpoPairs(pairs);
1133
+ const split = E.splitDpoPairs(uniq);
1133
1134
  const audit = E.auditDpoPairs(split.train, split.eval);
1134
- const rows = pairs.map((p) => JSON.stringify({ ...p, split: split.eval.includes(p) ? 'eval' : 'train' }));
1135
+ const rows = uniq.map((p) => JSON.stringify({ ...p, split: split.eval.includes(p) ? 'eval' : 'train' }));
1135
1136
  await wf(out, rows.join('\n') + (rows.length ? '\n' : ''), 'utf8');
1136
1137
  const bySrc = {};
1137
1138
  for (const p of pairs)
1138
1139
  bySrc[p.source ?? 'unmarked'] = (bySrc[p.source ?? 'unmarked'] || 0) + 1;
1139
1140
  const manifest = {
1140
1141
  version: 'dpo-' + new Date().toISOString().slice(0, 10).replaceAll('-', '') + '-' + new Date().toISOString().slice(11, 16).replace(':', ''),
1141
- pairsTotal: pairs.length,
1142
+ pairsTotal: uniq.length,
1142
1143
  bySource: bySrc,
1143
1144
  train: split.train.length,
1144
1145
  eval: split.eval.length,
@@ -1147,7 +1148,7 @@ flags:
1147
1148
  };
1148
1149
  const mf = join(home, 'evolution', 'dpo-manifest.json');
1149
1150
  await wf(mf, JSON.stringify(manifest, null, 2) + '\n', 'utf8');
1150
- stdout.write('DPO pairs: ' + pairs.length + ' ' + JSON.stringify(bySrc) + ' (train ' + split.train.length + ' / eval ' + split.eval.length + ') -> ' + out + '\n');
1151
+ stdout.write('DPO pairs: ' + uniq.length + ' (raw ' + pairs.length + ', dupes dropped ' + (pairs.length - uniq.length) + ') ' + JSON.stringify(bySrc) + ' (train ' + split.train.length + ' / eval ' + split.eval.length + ') -> ' + out + '\n');
1151
1152
  stdout.write('audit: ' + JSON.stringify(audit) + '\n');
1152
1153
  if (audit.emptyPrompt || audit.emptyAnswer || audit.duplicatePairs || audit.evalPromptsLeakedIntoTrain)
1153
1154
  stdout.write(YELLOW('⚠ audit not clean - fix the flagged rows before training') + '\n');
package/dist/tui.d.ts CHANGED
@@ -140,6 +140,10 @@ export declare class TuiRuntime {
140
140
  /** bracketed-paste accumulator: non-null while the 201~ end marker has
141
141
  * not arrived yet; everything buffered is literal insert-on-completion */
142
142
  private pasteBuf;
143
+ /** restores the console methods and process handlers captured by the
144
+ * TUI's terminal ownership (see installConsoleRedirection) */
145
+ private restoreConsole;
146
+ private fatalHandler;
143
147
  /** screen row of each visible palette item (SGR click hit-testing); the
144
148
  * render loop records row = frame.length (1-based) as it pushes rows */
145
149
  private paletteClickRows;
@@ -163,6 +167,8 @@ export declare class TuiRuntime {
163
167
  /** last user-submitted line, for Esc-Esc edit-and-fork (T13) */
164
168
  private lastUserMsg;
165
169
  constructor();
170
+ /** Route console.* and fatal-process dumps into the transcript. */
171
+ private installConsoleRedirection;
166
172
  setModelChoices(list: Array<{
167
173
  name: string;
168
174
  desc: string;
package/dist/tui.js CHANGED
@@ -335,6 +335,10 @@ export class TuiRuntime {
335
335
  /** bracketed-paste accumulator: non-null while the 201~ end marker has
336
336
  * not arrived yet; everything buffered is literal insert-on-completion */
337
337
  pasteBuf = null;
338
+ /** restores the console methods and process handlers captured by the
339
+ * TUI's terminal ownership (see installConsoleRedirection) */
340
+ restoreConsole = null;
341
+ fatalHandler = null;
338
342
  /** screen row of each visible palette item (SGR click hit-testing); the
339
343
  * render loop records row = frame.length (1-based) as it pushes rows */
340
344
  paletteClickRows = [];
@@ -373,6 +377,35 @@ export class TuiRuntime {
373
377
  stdin.on('data', (d) => this.onKey(d));
374
378
  stdout.on('resize', () => { this.dirty = true; });
375
379
  this.renderTimer = setInterval(() => this.render(), 90);
380
+ // The TUI owns the terminal while it runs (user-reported on host + every
381
+ // VM): stray console output - MCP attach notices, library warnings,
382
+ // provider retries - sprayed over the alternate screen and froze the
383
+ // picture (nothing marked the frame dirty) until a keypress repainted.
384
+ // Every console line now lands in the transcript instead, scrollable
385
+ // like any other output; restored in destroy().
386
+ this.installConsoleRedirection();
387
+ }
388
+ /** Route console.* and fatal-process dumps into the transcript. */
389
+ installConsoleRedirection() {
390
+ const fmt = (a) => a.map((x) => (typeof x === 'string' ? x : JSON.stringify(x, null, 0) ?? String(x))).join(' ');
391
+ const prev = {
392
+ log: console.log.bind(console),
393
+ info: console.info.bind(console),
394
+ warn: console.warn.bind(console),
395
+ error: console.error.bind(console),
396
+ debug: console.debug.bind(console),
397
+ };
398
+ this.restoreConsole = () => { console.log = prev.log; console.info = prev.info; console.warn = prev.warn; console.error = prev.error; console.debug = prev.debug; };
399
+ console.log = (...a) => { this.addText(fmt(a).trim(), 'dim'); };
400
+ console.info = (...a) => { this.addText(fmt(a).trim(), 'dim'); };
401
+ console.debug = (...a) => { this.addText(fmt(a).trim(), 'dim'); };
402
+ console.warn = (...a) => { this.addText(fmt(a), 'err'); };
403
+ console.error = (...a) => { this.addText(fmt(a), 'err'); };
404
+ // Node's default dump for these would tear up the alternate screen too
405
+ this.fatalHandler = (err) => { this.addText('process: ' + String(err).slice(0, 500), 'err'); };
406
+ process.on('unhandledRejection', this.fatalHandler);
407
+ process.on('uncaughtException', this.fatalHandler);
408
+ process.on('warning', this.fatalHandler);
376
409
  }
377
410
  setModelChoices(list) {
378
411
  this.modelChoices = list;
@@ -667,6 +700,12 @@ export class TuiRuntime {
667
700
  // ?1l restores default CSI cursor keys; reporting off whatever the
668
701
  // modal state was
669
702
  stdout.write((this.mouseReported ? '\x1b[?1000l\x1b[?1006l' : '') + '\x1b[?2004l\x1b[?1007l' + '\x1b[?1l\x1b[?25h\x1b[?1049l');
703
+ this.restoreConsole?.();
704
+ if (this.fatalHandler) {
705
+ process.off('unhandledRejection', this.fatalHandler);
706
+ process.off('uncaughtException', this.fatalHandler);
707
+ process.off('warning', this.fatalHandler);
708
+ }
670
709
  stdin.setRawMode?.(false);
671
710
  stdin.pause();
672
711
  }
@@ -2004,10 +2043,14 @@ export async function tui(yes, noWeb = false, opts = {}) {
2004
2043
  // M4 B8: tool call + result = one collapsible cell (folded summary
2005
2044
  // by default; `z` with an empty input expands the last one)
2006
2045
  rt.addToolCell(` ${dot} ${CYAN(name)} ${DIM('⎿ ' + first.trim().slice(0, 100))}`, output);
2007
- // M4 B9: outputs far beyond a screen auto-enter the pager overlay
2008
- // (the user can always q/Esc back to the stream)
2009
- if (output.split('\n').length > 2 * Math.max(20, (stdout.rows || 30))) {
2010
- rt.showOverlay(`${name} output (${output.split('\n').length} lines)`, output.split('\n'));
2046
+ // M4 B9 (T18 复案 2026-09-21): outputs beyond a screen NO LONGER
2047
+ // auto-open the full-screen pager - on every system it read as a
2048
+ // break-in (a wall of raw output hijacking the screen while the
2049
+ // task ran on underneath, 'frozen' until Esc). The folded cell
2050
+ // plus this hint line keep the escape hatches visible instead.
2051
+ const outLines = output.split('\n').length;
2052
+ if (outLines > 2 * Math.max(20, (stdout.rows || 30))) {
2053
+ rt.addText(' ' + DIM(t.tuiLongOutputHint(name, outLines)), 'plain');
2011
2054
  }
2012
2055
  // retain the FULL output for the Ctrl+T transcript overlay (B5);
2013
2056
  // the transcript itself keeps only the folded first line
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/cli",
3
- "version": "0.14.20",
3
+ "version": "0.14.22",
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",
@@ -45,10 +45,10 @@
45
45
  "dependencies": {
46
46
  "@hmharness/kernel": "0.9.2",
47
47
  "@hmharness/observability": "0.7.0",
48
- "@hmharness/evolution": "0.14.14",
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.11",
51
+ "@hmharness/agent": "0.14.12",
52
52
  "@hmharness/evaluation": "0.8.0",
53
53
  "@hmharness/web": "0.9.2"
54
54
  }