@hmharness/cli 0.14.9 → 0.14.11
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 +91 -0
- package/dist/tui.d.ts +51 -12
- package/dist/tui.js +157 -37
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import readline from 'node:readline/promises';
|
|
25
25
|
import { stdin, stdout } from 'node:process';
|
|
26
|
+
import { readFile } from 'node:fs/promises';
|
|
26
27
|
import { join } from 'node:path';
|
|
27
28
|
import { stopWebDaemon, startWebDaemon, hmhWebUp, readWebPid } from "./web-daemon.js";
|
|
28
29
|
import { chat, homeDir, resolveProvider, initHome, latestSession, listProviders, listSessions, loadConfig, loadTranscript, mcpServerTools, Registry, runLoop, setChatRoute, setLocale, } from '@hmharness/kernel';
|
|
@@ -984,6 +985,96 @@ flags:
|
|
|
984
985
|
}
|
|
985
986
|
return;
|
|
986
987
|
}
|
|
988
|
+
if (cmd === 'reward') {
|
|
989
|
+
// V3 RL phase (ADR-0010): learned reward model over the human labels
|
|
990
|
+
await initHome();
|
|
991
|
+
const home = homeDir();
|
|
992
|
+
const E = await import('@hmharness/evolution');
|
|
993
|
+
const sub = rest[0] ?? 'report';
|
|
994
|
+
const readJsonl = async (f) => {
|
|
995
|
+
try {
|
|
996
|
+
return (await readFile(f, 'utf8')).trim().split('\n').filter(Boolean).map((l) => JSON.parse(l));
|
|
997
|
+
}
|
|
998
|
+
catch {
|
|
999
|
+
return [];
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
const labels = (await readJsonl(join(home, 'evolution', 'reward-human-labels.jsonl')));
|
|
1003
|
+
const insights = (await readJsonl(join(home, 'insights', 'insights.jsonl')));
|
|
1004
|
+
if (sub === 'fit') {
|
|
1005
|
+
if (labels.length < 10) {
|
|
1006
|
+
stdout.write('need >=10 human labels to fit (have ' + labels.length + ')\n');
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
const m = E.fitRewardModel(labels, insights);
|
|
1010
|
+
await E.saveRewardModel(home, m);
|
|
1011
|
+
stdout.write('reward model fitted on ' + m.nSamples + ' joined labels\n');
|
|
1012
|
+
stdout.write(' weights[outcome, failRate, turns, tools, bias] = ' + m.w.map((v) => v.toFixed(3)).join(', ') + '\n');
|
|
1013
|
+
stdout.write(' train RMSE ' + m.trainRmse + (m.holdoutRmse !== undefined ? ' · holdout RMSE ' + m.holdoutRmse : ' · (no holdout yet)') + '\n');
|
|
1014
|
+
stdout.write(' saved: ' + join(home, 'evolution', 'reward-model.json') + '\n');
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
if (sub === 'report') {
|
|
1018
|
+
const m = await E.loadRewardModel(home);
|
|
1019
|
+
if (!m) {
|
|
1020
|
+
stdout.write('no fitted reward model - run: hmh reward fit\n');
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
stdout.write('reward model @ ' + m.trainedAt + '\n');
|
|
1024
|
+
stdout.write(' samples ' + m.nSamples + ' · train RMSE ' + m.trainRmse + (m.holdoutRmse !== undefined ? ' · holdout RMSE ' + m.holdoutRmse : '') + '\n');
|
|
1025
|
+
stdout.write(' weights [outcome, failRate, turns, tools, bias] = ' + m.w.map((v) => v.toFixed(3)).join(', ') + '\n');
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (sub === 'export-dpo') {
|
|
1029
|
+
const { findSessionFile, readSessionHead, loadTranscript } = await import('@hmharness/kernel');
|
|
1030
|
+
const taskOf = async (session) => {
|
|
1031
|
+
try {
|
|
1032
|
+
const f = await findSessionFile(home, session);
|
|
1033
|
+
if (!f)
|
|
1034
|
+
return '';
|
|
1035
|
+
const h = await readSessionHead(f);
|
|
1036
|
+
return h?.firstUser ?? '';
|
|
1037
|
+
}
|
|
1038
|
+
catch {
|
|
1039
|
+
return '';
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
const answerOf = async (session) => {
|
|
1043
|
+
try {
|
|
1044
|
+
const f = await findSessionFile(home, session);
|
|
1045
|
+
if (!f)
|
|
1046
|
+
return '';
|
|
1047
|
+
const tr = await loadTranscript(f);
|
|
1048
|
+
if (!tr)
|
|
1049
|
+
return '';
|
|
1050
|
+
for (let i = tr.messages.length - 1; i >= 0; i--) {
|
|
1051
|
+
const m = tr.messages[i];
|
|
1052
|
+
if (m.role === 'assistant' && typeof m.content === 'string' && m.content.trim())
|
|
1053
|
+
return m.content;
|
|
1054
|
+
}
|
|
1055
|
+
return '';
|
|
1056
|
+
}
|
|
1057
|
+
catch {
|
|
1058
|
+
return '';
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
const sessions = [...new Set(labels.map((l) => l.session))];
|
|
1062
|
+
const tasks = new Map();
|
|
1063
|
+
const answers = new Map();
|
|
1064
|
+
for (const s2 of sessions) {
|
|
1065
|
+
tasks.set(s2, await taskOf(s2));
|
|
1066
|
+
answers.set(s2, await answerOf(s2));
|
|
1067
|
+
}
|
|
1068
|
+
const pairs = E.exportDpoPairs(labels, insights, (x2) => tasks.get(x2) ?? '', (x2) => answers.get(x2) ?? '');
|
|
1069
|
+
const out = join(home, 'evolution', 'dpo-pairs.jsonl');
|
|
1070
|
+
const { writeFile: wf } = await import('node:fs/promises');
|
|
1071
|
+
await wf(out, pairs.map((p) => JSON.stringify(p)).join('\n') + (pairs.length ? '\n' : ''), 'utf8');
|
|
1072
|
+
stdout.write('DPO pairs: ' + pairs.length + ' -> ' + out + '\n');
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
stdout.write('usage: hmh reward fit | report | export-dpo\n');
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
987
1078
|
if (cmd === 'dataset') {
|
|
988
1079
|
// V2 M10: trajectory -> versioned dataset (filter/dedupe/reward/split)
|
|
989
1080
|
await initHome();
|
package/dist/tui.d.ts
CHANGED
|
@@ -54,6 +54,39 @@ export declare const KEYMAP_DEFAULTS: Record<string, string>;
|
|
|
54
54
|
* wheel-down (+1), anything else (clicks, drags, plain keys) is 0.
|
|
55
55
|
*/
|
|
56
56
|
export declare function parseWheel(data: string): number;
|
|
57
|
+
/**
|
|
58
|
+
* SGR reports can split across stdin chunks (fast wheel bursts fragment in
|
|
59
|
+
* some terminals). If the buffer ends inside a report - a trailing
|
|
60
|
+
* '\x1b[<...' with no terminating M/m yet - slice it off as `pending` for
|
|
61
|
+
* the next chunk and hand back only the complete part.
|
|
62
|
+
*/
|
|
63
|
+
export declare function splitMouseReport(data: string): {
|
|
64
|
+
data: string;
|
|
65
|
+
pending: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Bracketed-paste body cleanup: strip the 200~/201~ markers and any escape
|
|
69
|
+
* sequences (pasted terminal controls must not leak into the input line),
|
|
70
|
+
* and collapse newlines to single spaces - a multi-line paste becomes ONE
|
|
71
|
+
* reviewable input instead of auto-submitting each line as its own command.
|
|
72
|
+
* Capped so a runaway paste cannot balloon the input field.
|
|
73
|
+
*/
|
|
74
|
+
export declare function sanitizePaste(raw: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* /copy clipboard candidates for the platform/session: Wayland first when
|
|
77
|
+
* WAYLAND_DISPLAY is set (xclip does not exist on a pure wl session), then
|
|
78
|
+
* X11's xclip with xsel as fallback. Empty when nothing plausible applies.
|
|
79
|
+
* The caller tries them in order until one spawns; the final "output
|
|
80
|
+
* follows" degrade stays for systems with no clipboard utility at all
|
|
81
|
+
* (e.g. the KaihongOS guest terminal).
|
|
82
|
+
*/
|
|
83
|
+
export declare function clipboardCandidates(platform: string, env: {
|
|
84
|
+
WAYLAND_DISPLAY?: string;
|
|
85
|
+
DISPLAY?: string;
|
|
86
|
+
}): Array<{
|
|
87
|
+
bin: string;
|
|
88
|
+
args: string[];
|
|
89
|
+
}>;
|
|
57
90
|
export declare class TuiRuntime {
|
|
58
91
|
private entries;
|
|
59
92
|
private dirty;
|
|
@@ -87,15 +120,22 @@ export declare class TuiRuntime {
|
|
|
87
120
|
private modeTag;
|
|
88
121
|
/** rows for the `/model ` picker (configured providers first, set by driver) */
|
|
89
122
|
private modelChoices;
|
|
90
|
-
/** Wheel/click handling:
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* selection
|
|
97
|
-
*
|
|
123
|
+
/** Wheel/click handling: SGR mouse reporting is ALWAYS on (enabled with
|
|
124
|
+
* ?1000h+?1006h at startup). Cross-terminal wheel support has to come
|
|
125
|
+
* from explicit reports: only some terminals translate the wheel to
|
|
126
|
+
* arrow keys on the alternate screen, so the wheel would silently do
|
|
127
|
+
* nothing on the others (conhost, several Linux terminals, the
|
|
128
|
+
* KaihongOS terminal). The wheel drives the transcript (or the open
|
|
129
|
+
* palette's selection); clicks only pick rows while a palette is open.
|
|
130
|
+
* Native select/copy stays available via Shift+click, the standard
|
|
131
|
+
* bypass in mainstream terminals. */
|
|
98
132
|
private mouseReported;
|
|
133
|
+
/** tail of an SGR mouse report split across stdin chunks (fast wheel
|
|
134
|
+
* bursts); prepended to the next chunk so parseWheel sees the sequence */
|
|
135
|
+
private mousePending;
|
|
136
|
+
/** bracketed-paste accumulator: non-null while the 201~ end marker has
|
|
137
|
+
* not arrived yet; everything buffered is literal insert-on-completion */
|
|
138
|
+
private pasteBuf;
|
|
99
139
|
/** screen row of each visible palette item (SGR click hit-testing); the
|
|
100
140
|
* render loop records row = frame.length (1-based) as it pushes rows */
|
|
101
141
|
private paletteClickRows;
|
|
@@ -171,10 +211,6 @@ export declare class TuiRuntime {
|
|
|
171
211
|
frameText: string;
|
|
172
212
|
};
|
|
173
213
|
setModeTag(tag: string): void;
|
|
174
|
-
/** Reporting is on ONLY while a palette is open. The palette is a modal:
|
|
175
|
-
* while it shows, clicks choose its rows and the wheel drives its
|
|
176
|
-
* selection; drag-select resumes the moment it closes. */
|
|
177
|
-
private syncMouseReporting;
|
|
178
214
|
/** The palette data source: `/model ` opens the model picker, otherwise
|
|
179
215
|
* slash commands. (/resume submits straight through to the driver, which
|
|
180
216
|
* opens the Codex-style full-frame picker - resume-picker.ts.) Rows are
|
|
@@ -243,6 +279,9 @@ export declare class TuiRuntime {
|
|
|
243
279
|
clearScreen(): void;
|
|
244
280
|
private totalLines;
|
|
245
281
|
private onKey;
|
|
282
|
+
/** insert literal (sanitized paste) text at the caret - the same path
|
|
283
|
+
* printable typing takes, so caret/history/palette side-effects match */
|
|
284
|
+
private insertText;
|
|
246
285
|
render(): void;
|
|
247
286
|
private flushFrame;
|
|
248
287
|
}
|
package/dist/tui.js
CHANGED
|
@@ -228,6 +228,58 @@ export function parseWheel(data) {
|
|
|
228
228
|
return 1;
|
|
229
229
|
return 0;
|
|
230
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* SGR reports can split across stdin chunks (fast wheel bursts fragment in
|
|
233
|
+
* some terminals). If the buffer ends inside a report - a trailing
|
|
234
|
+
* '\x1b[<...' with no terminating M/m yet - slice it off as `pending` for
|
|
235
|
+
* the next chunk and hand back only the complete part.
|
|
236
|
+
*/
|
|
237
|
+
export function splitMouseReport(data) {
|
|
238
|
+
const cut = data.lastIndexOf('\x1b[<');
|
|
239
|
+
if (cut === -1)
|
|
240
|
+
return { data, pending: '' };
|
|
241
|
+
const tail = data.slice(cut);
|
|
242
|
+
return /^\x1b\[<\d+(;\d+)*[Mm]$/.test(tail)
|
|
243
|
+
? { data, pending: '' }
|
|
244
|
+
: { data: data.slice(0, cut), pending: tail };
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Bracketed-paste body cleanup: strip the 200~/201~ markers and any escape
|
|
248
|
+
* sequences (pasted terminal controls must not leak into the input line),
|
|
249
|
+
* and collapse newlines to single spaces - a multi-line paste becomes ONE
|
|
250
|
+
* reviewable input instead of auto-submitting each line as its own command.
|
|
251
|
+
* Capped so a runaway paste cannot balloon the input field.
|
|
252
|
+
*/
|
|
253
|
+
export function sanitizePaste(raw) {
|
|
254
|
+
return raw
|
|
255
|
+
.replace(/\x1b\[[0-9;?]*[a-zA-Z~]/g, '')
|
|
256
|
+
.replace(/\x1b/g, '')
|
|
257
|
+
.replace(/\r\n|\r|\n/g, ' ')
|
|
258
|
+
.replace(/[ \t]+$/, '')
|
|
259
|
+
.slice(0, 262144);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* /copy clipboard candidates for the platform/session: Wayland first when
|
|
263
|
+
* WAYLAND_DISPLAY is set (xclip does not exist on a pure wl session), then
|
|
264
|
+
* X11's xclip with xsel as fallback. Empty when nothing plausible applies.
|
|
265
|
+
* The caller tries them in order until one spawns; the final "output
|
|
266
|
+
* follows" degrade stays for systems with no clipboard utility at all
|
|
267
|
+
* (e.g. the KaihongOS guest terminal).
|
|
268
|
+
*/
|
|
269
|
+
export function clipboardCandidates(platform, env) {
|
|
270
|
+
if (platform === 'win32')
|
|
271
|
+
return [{ bin: 'clip', args: [] }];
|
|
272
|
+
if (platform === 'darwin')
|
|
273
|
+
return [{ bin: 'pbcopy', args: [] }];
|
|
274
|
+
const out = [];
|
|
275
|
+
if (env.WAYLAND_DISPLAY)
|
|
276
|
+
out.push({ bin: 'wl-copy', args: [] });
|
|
277
|
+
if (env.DISPLAY) {
|
|
278
|
+
out.push({ bin: 'xclip', args: ['-selection', 'clipboard'] });
|
|
279
|
+
out.push({ bin: 'xsel', args: ['--clipboard', '--input'] });
|
|
280
|
+
}
|
|
281
|
+
return out;
|
|
282
|
+
}
|
|
231
283
|
export class TuiRuntime {
|
|
232
284
|
entries = [];
|
|
233
285
|
dirty = true;
|
|
@@ -261,15 +313,22 @@ export class TuiRuntime {
|
|
|
261
313
|
modeTag = '';
|
|
262
314
|
/** rows for the `/model ` picker (configured providers first, set by driver) */
|
|
263
315
|
modelChoices = [];
|
|
264
|
-
/** Wheel/click handling:
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* selection
|
|
271
|
-
*
|
|
272
|
-
|
|
316
|
+
/** Wheel/click handling: SGR mouse reporting is ALWAYS on (enabled with
|
|
317
|
+
* ?1000h+?1006h at startup). Cross-terminal wheel support has to come
|
|
318
|
+
* from explicit reports: only some terminals translate the wheel to
|
|
319
|
+
* arrow keys on the alternate screen, so the wheel would silently do
|
|
320
|
+
* nothing on the others (conhost, several Linux terminals, the
|
|
321
|
+
* KaihongOS terminal). The wheel drives the transcript (or the open
|
|
322
|
+
* palette's selection); clicks only pick rows while a palette is open.
|
|
323
|
+
* Native select/copy stays available via Shift+click, the standard
|
|
324
|
+
* bypass in mainstream terminals. */
|
|
325
|
+
mouseReported = true;
|
|
326
|
+
/** tail of an SGR mouse report split across stdin chunks (fast wheel
|
|
327
|
+
* bursts); prepended to the next chunk so parseWheel sees the sequence */
|
|
328
|
+
mousePending = '';
|
|
329
|
+
/** bracketed-paste accumulator: non-null while the 201~ end marker has
|
|
330
|
+
* not arrived yet; everything buffered is literal insert-on-completion */
|
|
331
|
+
pasteBuf = null;
|
|
273
332
|
/** screen row of each visible palette item (SGR click hit-testing); the
|
|
274
333
|
* render loop records row = frame.length (1-based) as it pushes rows */
|
|
275
334
|
paletteClickRows = [];
|
|
@@ -296,8 +355,12 @@ export class TuiRuntime {
|
|
|
296
355
|
constructor() {
|
|
297
356
|
// ?1l forces DECCKM OFF so arrow keys arrive as CSI (\x1b[A) even if a
|
|
298
357
|
// previous program left the terminal in application cursor mode - in
|
|
299
|
-
// that mode arrows arrive as SS3 (\x1bOA) and would be silently dropped
|
|
300
|
-
|
|
358
|
+
// that mode arrows arrive as SS3 (\x1bOA) and would be silently dropped.
|
|
359
|
+
// SGR mouse reporting on from the first frame: the wheel must scroll on
|
|
360
|
+
// every terminal, not only the ones that map wheel->arrows themselves.
|
|
361
|
+
// Bracketed paste (?2004h): multi-line pastes arrive delimited and
|
|
362
|
+
// insert as one reviewable input instead of auto-submitting per line.
|
|
363
|
+
stdout.write('\x1b[?1049h\x1b[?25l\x1b[2J\x1b[?1l\x1b[?1000h\x1b[?1006h\x1b[?2004h');
|
|
301
364
|
stdin.setRawMode?.(true);
|
|
302
365
|
stdin.resume();
|
|
303
366
|
stdin.setEncoding('utf8');
|
|
@@ -545,16 +608,6 @@ export class TuiRuntime {
|
|
|
545
608
|
this.modeTag = tag;
|
|
546
609
|
this.dirty = true;
|
|
547
610
|
}
|
|
548
|
-
/** Reporting is on ONLY while a palette is open. The palette is a modal:
|
|
549
|
-
* while it shows, clicks choose its rows and the wheel drives its
|
|
550
|
-
* selection; drag-select resumes the moment it closes. */
|
|
551
|
-
syncMouseReporting() {
|
|
552
|
-
const want = this.panelItems(this.input).length > 0;
|
|
553
|
-
if (want === this.mouseReported)
|
|
554
|
-
return;
|
|
555
|
-
this.mouseReported = want;
|
|
556
|
-
stdout.write(want ? '\x1b[?1000h\x1b[?1006h' : '\x1b[?1000l\x1b[?1006l');
|
|
557
|
-
}
|
|
558
611
|
/** The palette data source: `/model ` opens the model picker, otherwise
|
|
559
612
|
* slash commands. (/resume submits straight through to the driver, which
|
|
560
613
|
* opens the Codex-style full-frame picker - resume-picker.ts.) Rows are
|
|
@@ -586,7 +639,7 @@ export class TuiRuntime {
|
|
|
586
639
|
clearInterval(this.spinnerTimer);
|
|
587
640
|
// ?1l restores default CSI cursor keys; reporting off whatever the
|
|
588
641
|
// modal state was
|
|
589
|
-
stdout.write((this.mouseReported ? '\x1b[?1000l\x1b[?1006l' : '') + '\x1b[?1l\x1b[?25h\x1b[?1049l');
|
|
642
|
+
stdout.write((this.mouseReported ? '\x1b[?1000l\x1b[?1006l' : '') + '\x1b[?2004l' + '\x1b[?1l\x1b[?25h\x1b[?1049l');
|
|
590
643
|
stdin.setRawMode?.(false);
|
|
591
644
|
stdin.pause();
|
|
592
645
|
}
|
|
@@ -1032,6 +1085,55 @@ export class TuiRuntime {
|
|
|
1032
1085
|
return n;
|
|
1033
1086
|
}
|
|
1034
1087
|
onKey(data) {
|
|
1088
|
+
// reassemble an SGR mouse report that arrived split across stdin chunks
|
|
1089
|
+
// (fast wheel bursts fragment in some terminals) before anything parses
|
|
1090
|
+
if (this.mousePending) {
|
|
1091
|
+
data = this.mousePending + data;
|
|
1092
|
+
this.mousePending = '';
|
|
1093
|
+
}
|
|
1094
|
+
const split = splitMouseReport(data);
|
|
1095
|
+
if (split.pending)
|
|
1096
|
+
this.mousePending = split.pending;
|
|
1097
|
+
if (!split.data)
|
|
1098
|
+
return;
|
|
1099
|
+
data = split.data;
|
|
1100
|
+
// bracketed paste (T22): buffer until the 201~ end marker, then insert
|
|
1101
|
+
// the sanitized body at the caret; keys/bytes outside the markers keep
|
|
1102
|
+
// flowing through the normal path (recursion depth stays 1: indexOf
|
|
1103
|
+
// anchors on the FIRST 200~ so the outer chunk cannot contain another)
|
|
1104
|
+
if (this.pasteBuf !== null) {
|
|
1105
|
+
this.pasteBuf += data;
|
|
1106
|
+
const end = this.pasteBuf.indexOf('\x1b[201~');
|
|
1107
|
+
if (end !== -1) {
|
|
1108
|
+
const done = this.pasteBuf;
|
|
1109
|
+
this.pasteBuf = null;
|
|
1110
|
+
this.insertText(sanitizePaste(done));
|
|
1111
|
+
const after = done.slice(end + 6);
|
|
1112
|
+
if (after)
|
|
1113
|
+
this.onKey(after);
|
|
1114
|
+
}
|
|
1115
|
+
else if (this.pasteBuf.length > 1048576) {
|
|
1116
|
+
this.pasteBuf = null; // runaway paste: drop, never balloon the input
|
|
1117
|
+
}
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
const ps = data.indexOf('\x1b[200~');
|
|
1121
|
+
if (ps !== -1) {
|
|
1122
|
+
const before = data.slice(0, ps);
|
|
1123
|
+
if (before)
|
|
1124
|
+
this.onKey(before);
|
|
1125
|
+
this.pasteBuf = data.slice(ps + 6);
|
|
1126
|
+
const end = this.pasteBuf.indexOf('\x1b[201~');
|
|
1127
|
+
if (end !== -1) {
|
|
1128
|
+
const done = this.pasteBuf;
|
|
1129
|
+
this.pasteBuf = null;
|
|
1130
|
+
this.insertText(sanitizePaste(done));
|
|
1131
|
+
const after = done.slice(end + 6);
|
|
1132
|
+
if (after)
|
|
1133
|
+
this.onKey(after);
|
|
1134
|
+
}
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1035
1137
|
// SS3 application-mode arrows (\x1bOA…H): terminals left in DECCKM by a
|
|
1036
1138
|
// previous program send these; normalize to the CSI forms this UI
|
|
1037
1139
|
// matches so navigation never silently dies
|
|
@@ -1060,9 +1162,10 @@ export class TuiRuntime {
|
|
|
1060
1162
|
this.atPalKey(data);
|
|
1061
1163
|
return;
|
|
1062
1164
|
}
|
|
1063
|
-
// wheel-only mouse routing: 64 = wheel-up, 65 = wheel-down.
|
|
1064
|
-
//
|
|
1065
|
-
//
|
|
1165
|
+
// wheel-only mouse routing: 64 = wheel-up, 65 = wheel-down. Reporting
|
|
1166
|
+
// is always on, so every other report - click, drag, release - is just
|
|
1167
|
+
// swallowed below; the terminal's Shift+click native selection bypasses
|
|
1168
|
+
// the app entirely and keeps working.
|
|
1066
1169
|
const wheel = parseWheel(data);
|
|
1067
1170
|
if (wheel !== 0) {
|
|
1068
1171
|
// an open palette takes the wheel: it moves the selection (the list
|
|
@@ -1343,6 +1446,17 @@ export class TuiRuntime {
|
|
|
1343
1446
|
// '@' opens the file palette (B2); refreshAtPal() is a no-op otherwise
|
|
1344
1447
|
this.refreshAtPal();
|
|
1345
1448
|
}
|
|
1449
|
+
/** insert literal (sanitized paste) text at the caret - the same path
|
|
1450
|
+
* printable typing takes, so caret/history/palette side-effects match */
|
|
1451
|
+
insertText(text) {
|
|
1452
|
+
if (!text)
|
|
1453
|
+
return;
|
|
1454
|
+
this.input = this.input.slice(0, this.caret) + text + this.input.slice(this.caret);
|
|
1455
|
+
this.caret += text.length;
|
|
1456
|
+
this.cmdIdx = 0;
|
|
1457
|
+
this.dirty = true;
|
|
1458
|
+
this.refreshAtPal();
|
|
1459
|
+
}
|
|
1346
1460
|
/* ---------------- rendering ---------------- */
|
|
1347
1461
|
render() {
|
|
1348
1462
|
if (!this.running || !this.dirty)
|
|
@@ -1371,9 +1485,8 @@ export class TuiRuntime {
|
|
|
1371
1485
|
this.flushFrame(frame, H);
|
|
1372
1486
|
return;
|
|
1373
1487
|
}
|
|
1374
|
-
// modal mouse reporting follows the palette (see syncMouseReporting);
|
|
1375
1488
|
// click rows are re-recorded every frame because screen positions move
|
|
1376
|
-
|
|
1489
|
+
// (mouse reporting is always on - see the mouseReported field note)
|
|
1377
1490
|
this.paletteClickRows.length = 0;
|
|
1378
1491
|
const spin = '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'[this.spinnerFrame] ?? ' ';
|
|
1379
1492
|
// Header = pure identity strip: logo · model · cwd · skills (+ mode tag
|
|
@@ -2043,21 +2156,28 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2043
2156
|
rt.addText('(no AI output yet to copy)', 'dim');
|
|
2044
2157
|
return;
|
|
2045
2158
|
}
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
const bin = process.platform === 'win32' ? 'clip'
|
|
2049
|
-
: process.platform === 'darwin' ? 'pbcopy'
|
|
2050
|
-
: 'xclip';
|
|
2051
|
-
const args = bin === 'xclip' ? ['-selection', 'clipboard'] : [];
|
|
2159
|
+
const { spawn } = await import('node:child_process');
|
|
2160
|
+
const tryBin = (bin, args) => new Promise((res) => {
|
|
2052
2161
|
const child = spawn(bin, args, { windowsHide: true, stdio: ['pipe', 'ignore', 'ignore'] });
|
|
2162
|
+
child.on('error', () => res(false));
|
|
2163
|
+
child.stdin.on('error', () => { });
|
|
2053
2164
|
child.stdin.write(lastAiText);
|
|
2054
2165
|
child.stdin.end();
|
|
2055
|
-
|
|
2056
|
-
|
|
2166
|
+
child.on('close', (code) => res(code === 0));
|
|
2167
|
+
});
|
|
2168
|
+
// candidate chain (T16 复案): Wayland wl-copy before X11 xclip/xsel -
|
|
2169
|
+
// a single hard-coded xclip is dead on a pure wl session (Omarchy)
|
|
2170
|
+
let copied = false;
|
|
2171
|
+
for (const c of clipboardCandidates(process.platform, process.env)) {
|
|
2172
|
+
if (await tryBin(c.bin, c.args)) {
|
|
2173
|
+
copied = true;
|
|
2174
|
+
break;
|
|
2175
|
+
}
|
|
2057
2176
|
}
|
|
2058
|
-
|
|
2177
|
+
if (copied)
|
|
2178
|
+
rt.addText(GREEN('✓') + ' ' + t.cmdCopied, 'plain');
|
|
2179
|
+
else
|
|
2059
2180
|
rt.addText('(clipboard tool unavailable — output follows)\n' + lastAiText.slice(0, 2000), 'dim');
|
|
2060
|
-
}
|
|
2061
2181
|
return;
|
|
2062
2182
|
}
|
|
2063
2183
|
if (line === '/plan' || line.startsWith('/plan ')) {
|
package/package.json
CHANGED