@hmharness/cli 0.23.37 → 0.23.39
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/board/install-kaihongos.cjs +3 -3
- package/dist/extension-agent-brain.d.ts +50 -0
- package/dist/extension-agent-brain.js +119 -0
- package/dist/extension-chat.d.ts +29 -8
- package/dist/extension-chat.js +270 -51
- package/dist/main.js +68 -7
- package/dist/tui-mouse.d.ts +58 -0
- package/dist/tui-mouse.js +101 -0
- package/dist/tui.d.ts +47 -1
- package/dist/tui.js +337 -4
- package/dist/web-daemon.d.ts +6 -0
- package/dist/web-daemon.js +116 -1
- package/package.json +15 -15
- package/release-notes.json +10 -0
package/dist/tui.js
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
import { stdin, stdout } from 'node:process';
|
|
14
14
|
import { basename } from 'node:path';
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
|
-
import {
|
|
16
|
+
import { parseMouse, isMousePrefix, dispatchClick, clearRegions, addClickRegion } from "./tui-mouse.js";
|
|
17
|
+
import { loadConfig, homeDir, resolveProvider, listProviders, saveProvider, setChatRoute, setLocale, PROVIDER_PRESETS, addProviders, detectLocalProviders, latestSession, listSessions, loadTranscript, transcriptChars, compactMessages, adaptiveContextChars, getGoal, setGoal, clearGoal, isProviderAuthError } from '@hmharness/kernel';
|
|
17
18
|
import { listDrafts, listSkills, runBench, runEvolution } from '@hmharness/evolution';
|
|
18
19
|
import { buildRegistry, runAgentTask, strings } from '@hmharness/agent';
|
|
19
20
|
import { ensureWebDaemon, DEFAULT_WEB_PORT } from "./web-daemon.js";
|
|
@@ -89,13 +90,31 @@ function truncateTo(s, width) {
|
|
|
89
90
|
}
|
|
90
91
|
return out;
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
/** Build the /config provider table from config: purposes from routing
|
|
94
|
+
* (chat/vision/evolve/bench/judge). Pure — unit-testable. */
|
|
95
|
+
export function configProviderRows(cfg) {
|
|
96
|
+
const purposesOf = (name) => {
|
|
97
|
+
const r = cfg.routing ?? {};
|
|
98
|
+
const tags = [];
|
|
99
|
+
for (const [purpose, target] of Object.entries(r)) {
|
|
100
|
+
if (target === name)
|
|
101
|
+
tags.push(purpose);
|
|
102
|
+
}
|
|
103
|
+
return tags.join('/');
|
|
104
|
+
};
|
|
105
|
+
const entries = Object.entries(cfg.providers ?? {});
|
|
106
|
+
if (entries.length === 0) {
|
|
107
|
+
const p = cfg.provider;
|
|
108
|
+
return p?.baseUrl ? [{ name: 'default', model: p.model, baseUrl: p.baseUrl, purposes: 'chat' }] : [];
|
|
109
|
+
}
|
|
110
|
+
return entries.map(([name, p]) => ({ name, model: p.model, baseUrl: p.baseUrl, purposes: purposesOf(name) || '—' }));
|
|
111
|
+
}
|
|
94
112
|
export const COMMANDS = [
|
|
95
113
|
{ name: '/help', key: 'cmdHelp' },
|
|
96
114
|
{ name: '/tools', key: 'cmdTools' },
|
|
97
115
|
{ name: '/skills', key: 'cmdSkills' },
|
|
98
116
|
{ name: '/model', key: 'cmdModel' },
|
|
117
|
+
{ name: '/config', key: 'cmdConfig' },
|
|
99
118
|
{ name: '/lang', key: 'cmdLang' },
|
|
100
119
|
{ name: '/yolo', key: 'cmdYolo' },
|
|
101
120
|
{ name: '/providers', key: 'cmdProviders' },
|
|
@@ -319,6 +338,8 @@ export class TuiRuntime {
|
|
|
319
338
|
/** bracketed-paste accumulator: non-null while the 201~ end marker has
|
|
320
339
|
* not arrived yet; everything buffered is literal insert-on-completion */
|
|
321
340
|
pasteBuf = null;
|
|
341
|
+
/** partial SGR mouse report held across stdin reads (ConPTY fragmentation) */
|
|
342
|
+
mouseBuf = null;
|
|
322
343
|
/** restores the console methods and process handlers captured by the
|
|
323
344
|
* TUI's terminal ownership (see installConsoleRedirection) */
|
|
324
345
|
restoreConsole = null;
|
|
@@ -351,7 +372,7 @@ export class TuiRuntime {
|
|
|
351
372
|
// keys itself - no click capture, native selection stays native.
|
|
352
373
|
// Bracketed paste (?2004h): multi-line pastes arrive delimited and
|
|
353
374
|
// insert as one reviewable input instead of auto-submitting per line.
|
|
354
|
-
stdout.write('\x1b[?1049h\x1b[?25l\x1b[2J\x1b[?1l\x1b[?1007h\x1b[?2004h');
|
|
375
|
+
stdout.write('\x1b[?1049h\x1b[?25l\x1b[2J\x1b[?1l\x1b[?1007h\x1b[?2004h\x1b[?1000h\x1b[?1002h\x1b[?1006h');
|
|
355
376
|
stdin.setRawMode?.(true);
|
|
356
377
|
stdin.resume();
|
|
357
378
|
stdin.setEncoding('utf8');
|
|
@@ -405,6 +426,33 @@ export class TuiRuntime {
|
|
|
405
426
|
* the codex alt-screen picker contract. resolve fires on Enter (resume)
|
|
406
427
|
* or Esc/Ctrl-C (close). */
|
|
407
428
|
resumeModal = null;
|
|
429
|
+
/* ---------------- /config: one-stop provider & key editor ---------------- */
|
|
430
|
+
configListRows = [];
|
|
431
|
+
configModal = null;
|
|
432
|
+
saveProviderCb = null;
|
|
433
|
+
/** Driver wires the real save (kernel saveProvider) + list refresh here. */
|
|
434
|
+
onSaveProvider(fn) {
|
|
435
|
+
this.saveProviderCb = fn;
|
|
436
|
+
}
|
|
437
|
+
/** Open the modal with a provider snapshot (driver loads it). */
|
|
438
|
+
openConfigModal(rows) {
|
|
439
|
+
this.configModal = { mode: 'list', sel: 0, rows, note: '', busy: false };
|
|
440
|
+
this.dirty = true;
|
|
441
|
+
}
|
|
442
|
+
/** Headless-test probe: modal shape for assertions. */
|
|
443
|
+
configProbe() {
|
|
444
|
+
const m = this.configModal;
|
|
445
|
+
if (!m)
|
|
446
|
+
return { open: false, mode: '', rows: [], sel: -1, note: '' };
|
|
447
|
+
if (m.mode === 'list')
|
|
448
|
+
return { open: true, mode: 'list', rows: m.rows.map((r) => r.name), sel: m.sel, note: m.note };
|
|
449
|
+
const labels = [this.t.cfgFieldName, this.t.cfgFieldBaseUrl, this.t.cfgFieldModel, this.t.cfgFieldKey];
|
|
450
|
+
const vals = [m.fields.name, m.fields.baseUrl, m.fields.model, m.fields.key];
|
|
451
|
+
return {
|
|
452
|
+
open: true, mode: 'form', rows: [], sel: -1, fi: m.fi, note: m.note,
|
|
453
|
+
fields: labels.map((label, i) => ({ label, value: i === 3 ? '•'.repeat(vals[i].length) : vals[i], masked: i === 3 })),
|
|
454
|
+
};
|
|
455
|
+
}
|
|
408
456
|
openResumePicker() {
|
|
409
457
|
if (this.resumeModal)
|
|
410
458
|
return Promise.resolve(null);
|
|
@@ -495,6 +543,9 @@ export class TuiRuntime {
|
|
|
495
543
|
const sel = from + i === st.selected;
|
|
496
544
|
const plain = truncateTo(formatRow(vis[from + i], sel, W - 1), W - 1);
|
|
497
545
|
frame.push(sel ? '\x1b[7m' + plain + ' '.repeat(Math.max(0, W - 1 - strWidth(plain))) + '\x1b[27m' : ' ' + plain);
|
|
546
|
+
// mouse click region: this row picks that session
|
|
547
|
+
const pickRow = frame.length - 1;
|
|
548
|
+
addClickRegion(pickRow, 0, W - 1, () => { st.selected = from + i; this.pickerInput('return'); });
|
|
498
549
|
}
|
|
499
550
|
if (st.loading)
|
|
500
551
|
frame.push(DIM(' ' + (vis.length === 0 ? t.pickerLoading : t.pickerMore)));
|
|
@@ -509,6 +560,184 @@ export class TuiRuntime {
|
|
|
509
560
|
const posLine = t.pickerPos(pos, vis.length, vis.length ? String(Math.round((pos / vis.length) * 100)) : '0');
|
|
510
561
|
frame.push(' '.repeat(Math.max(0, W - posLine.length - 1)) + DIM(posLine));
|
|
511
562
|
}
|
|
563
|
+
/* ---------------- /config modal: render + input ---------------- */
|
|
564
|
+
/** Full-frame provider editor: list view (click/Enter a row to edit) or
|
|
565
|
+
* form view (fields, key masked, blank key = keep stored). Mouse clicks
|
|
566
|
+
* dispatch through the shared region registry like every other modal. */
|
|
567
|
+
renderConfigModal(frame, W, H) {
|
|
568
|
+
const m = this.configModal;
|
|
569
|
+
const t = this.t;
|
|
570
|
+
const count = ` ${m.mode === 'list' ? String(m.rows.length) : '编辑'} `;
|
|
571
|
+
frame.push(truncateTo(BOLD(' ' + t.cfgTitle) + ' '.repeat(Math.max(1, W - strWidth(t.cfgTitle) - count.length - 1)) + DIM(count), W));
|
|
572
|
+
frame.push(DIM('─'.repeat(W)));
|
|
573
|
+
if (m.mode === 'list') {
|
|
574
|
+
frame.push(DIM(truncateTo(` ${t.cfgFieldName.padEnd(12)}${t.cfgFieldModel.padEnd(16)}${t.cfgFieldBaseUrl.padEnd(30)}${t.cfgColUse}`, W - 1)));
|
|
575
|
+
const rows = m.rows;
|
|
576
|
+
const listH = Math.max(3, H - 6);
|
|
577
|
+
const from = rows.length > listH - 1 ? Math.max(0, Math.min(m.sel - Math.floor((listH - 1) / 2), rows.length - (listH - 1))) : 0;
|
|
578
|
+
for (let i = 0; i < listH - 1 && from + i < rows.length; i++) {
|
|
579
|
+
const gi = from + i;
|
|
580
|
+
const r = rows[gi];
|
|
581
|
+
const sel = gi === m.sel;
|
|
582
|
+
const line = truncateTo(` ${r.name.padEnd(12)}${r.model.slice(0, 15).padEnd(16)}${r.baseUrl.replace(/^https?:\/\//, '').slice(0, 28).padEnd(30)}${r.purposes}`, W - 1);
|
|
583
|
+
frame.push(sel ? '\x1b[7m' + line + ' '.repeat(Math.max(0, W - 1 - strWidth(line))) + '\x1b[27m' : ' ' + line);
|
|
584
|
+
const row = frame.length - 1;
|
|
585
|
+
addClickRegion(row, 0, W - 1, () => { this.openConfigForm(gi); });
|
|
586
|
+
}
|
|
587
|
+
const newLine = ' ' + CYAN(t.cfgNewRow);
|
|
588
|
+
frame.push(m.sel === rows.length ? '\x1b[7m' + newLine + ' '.repeat(Math.max(0, W - 1 - strWidth(newLine))) + '\x1b[27m' : ' ' + newLine);
|
|
589
|
+
addClickRegion(frame.length - 1, 0, W - 1, () => { this.openConfigForm(-1); });
|
|
590
|
+
if (m.note)
|
|
591
|
+
frame.push(m.note.startsWith('✓') ? GREEN(m.note) : RED(truncateTo(m.note, W - 1)));
|
|
592
|
+
frame.push(DIM('─'.repeat(W)));
|
|
593
|
+
frame.push(DIM(truncateTo(' ' + t.cfgListHint, W - 1)));
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
// form view
|
|
597
|
+
const labels = [t.cfgFieldName, t.cfgFieldBaseUrl, t.cfgFieldModel, t.cfgFieldKey];
|
|
598
|
+
const vals = [m.fields.name, m.fields.baseUrl, m.fields.model, m.fields.key];
|
|
599
|
+
for (let i = 0; i < 4; i++) {
|
|
600
|
+
const active = i === m.fi;
|
|
601
|
+
const shown = i === 3 ? '•'.repeat(vals[i].length) : vals[i];
|
|
602
|
+
const caret = active ? '▏' : ' ';
|
|
603
|
+
const body = ` ${labels[i].padEnd(10)}${caret}${shown}`;
|
|
604
|
+
const line = active ? CYAN(truncateTo(body, W - 1)) : DIM(truncateTo(body, W - 1));
|
|
605
|
+
frame.push(line);
|
|
606
|
+
addClickRegion(frame.length - 1, 0, W - 1, () => { if (this.configModal?.mode === 'form') {
|
|
607
|
+
this.configModal.fi = i;
|
|
608
|
+
this.dirty = true;
|
|
609
|
+
} });
|
|
610
|
+
}
|
|
611
|
+
frame.push(DIM(truncateTo(' ' + t.cfgKeyNote, W - 1)));
|
|
612
|
+
if (m.note)
|
|
613
|
+
frame.push(m.note.startsWith('✓') ? GREEN(m.note) : RED(truncateTo(m.note, W - 1)));
|
|
614
|
+
frame.push(DIM('─'.repeat(W)));
|
|
615
|
+
const back = ' ' + DIM(t.cfgBackRow);
|
|
616
|
+
const save = ' ' + GREEN(BOLD(t.cfgSaveRow));
|
|
617
|
+
frame.push(back);
|
|
618
|
+
addClickRegion(frame.length - 1, 0, W - 1, () => { if (this.configModal?.mode === 'form') {
|
|
619
|
+
this.configModal = { mode: 'list', sel: 0, rows: this.configListRows, note: '', busy: false };
|
|
620
|
+
this.dirty = true;
|
|
621
|
+
} });
|
|
622
|
+
frame.push(save);
|
|
623
|
+
addClickRegion(frame.length - 1, 0, W - 1, () => { void this.saveConfigForm(); });
|
|
624
|
+
frame.push(DIM(truncateTo(' ' + t.cfgFormHint, W - 1)));
|
|
625
|
+
}
|
|
626
|
+
/** Open the edit form for row gi (-1 = new provider). Keeps a snapshot of
|
|
627
|
+
* the list for the back button (refreshed again after every save). */
|
|
628
|
+
openConfigForm(gi) {
|
|
629
|
+
const m = this.configModal;
|
|
630
|
+
if (!m || m.mode !== 'list')
|
|
631
|
+
return;
|
|
632
|
+
this.configListRows = m.rows;
|
|
633
|
+
const r = gi >= 0 ? m.rows[gi] : undefined;
|
|
634
|
+
this.configModal = {
|
|
635
|
+
mode: 'form',
|
|
636
|
+
orig: r?.name ?? '',
|
|
637
|
+
fields: { name: r?.name ?? '', baseUrl: r?.baseUrl ?? 'https://', model: r?.model ?? '', key: '' },
|
|
638
|
+
fi: gi >= 0 ? 1 : 0, // editing existing: start at baseUrl (name rarely changes)
|
|
639
|
+
note: '',
|
|
640
|
+
busy: false,
|
|
641
|
+
};
|
|
642
|
+
this.dirty = true;
|
|
643
|
+
}
|
|
644
|
+
/** Validate + persist the form via the driver-wired save callback. */
|
|
645
|
+
async saveConfigForm() {
|
|
646
|
+
const m = this.configModal;
|
|
647
|
+
if (!m || m.mode !== 'form' || m.busy)
|
|
648
|
+
return;
|
|
649
|
+
if (!m.fields.name.trim() || !m.fields.baseUrl.trim() || !m.fields.model.trim()) {
|
|
650
|
+
m.note = '名称 / 地址 / 模型 均不能为空';
|
|
651
|
+
this.dirty = true;
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
m.busy = true;
|
|
655
|
+
this.dirty = true;
|
|
656
|
+
const res = this.saveProviderCb
|
|
657
|
+
? await this.saveProviderCb(m.fields.name.trim(), { baseUrl: m.fields.baseUrl.trim(), model: m.fields.model.trim(), ...(m.fields.key ? { apiKey: m.fields.key } : {}) })
|
|
658
|
+
: { ok: false, rows: [], error: 'save not wired' };
|
|
659
|
+
const listRows = res.rows.length ? res.rows : this.configListRows;
|
|
660
|
+
if (res.ok) {
|
|
661
|
+
this.configModal = { mode: 'list', sel: Math.max(0, listRows.findIndex((r) => r.name === m.fields.name.trim())), rows: listRows, note: this.t.cfgSavedOk + ' · ' + m.fields.name.trim(), busy: false };
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
m.busy = false;
|
|
665
|
+
m.note = res.error ?? 'save failed';
|
|
666
|
+
}
|
|
667
|
+
this.dirty = true;
|
|
668
|
+
}
|
|
669
|
+
/** Keyboard input for the config modal (modal owns every event). */
|
|
670
|
+
configInput(data) {
|
|
671
|
+
const m = this.configModal;
|
|
672
|
+
if (!m || m.busy)
|
|
673
|
+
return;
|
|
674
|
+
if (data === '\x1b' || data === '\x03') { // Esc / Ctrl-C
|
|
675
|
+
if (m.mode === 'form') {
|
|
676
|
+
const rows = this.configListRows;
|
|
677
|
+
this.configModal = { mode: 'list', sel: 0, rows, note: '', busy: false };
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
this.configModal = null;
|
|
681
|
+
}
|
|
682
|
+
this.dirty = true;
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (m.mode === 'list') {
|
|
686
|
+
const total = m.rows.length + 1; // + new-provider row
|
|
687
|
+
if (data === '\x1b[A' || data === 'k') {
|
|
688
|
+
m.sel = Math.max(0, m.sel - 1);
|
|
689
|
+
this.dirty = true;
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (data === '\x1b[B' || data === 'j') {
|
|
693
|
+
m.sel = Math.min(total - 1, m.sel + 1);
|
|
694
|
+
this.dirty = true;
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
if (data === '\r' || data === '\n') {
|
|
698
|
+
this.openConfigForm(m.sel >= m.rows.length ? -1 : m.sel);
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
// form mode
|
|
704
|
+
const labels = [this.t.cfgFieldName, this.t.cfgFieldBaseUrl, this.t.cfgFieldModel, this.t.cfgFieldKey];
|
|
705
|
+
void labels;
|
|
706
|
+
if (data === '\x1b[A') {
|
|
707
|
+
m.fi = Math.max(0, m.fi - 1);
|
|
708
|
+
this.dirty = true;
|
|
709
|
+
return;
|
|
710
|
+
} // up = prev field
|
|
711
|
+
if (data === '\x1b[B' || data === '\t') { // down/tab = next; on last, save
|
|
712
|
+
if (m.fi < 3) {
|
|
713
|
+
m.fi++;
|
|
714
|
+
this.dirty = true;
|
|
715
|
+
}
|
|
716
|
+
else
|
|
717
|
+
void this.saveConfigForm();
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
if (data === '\r' || data === '\n') {
|
|
721
|
+
void this.saveConfigForm();
|
|
722
|
+
return;
|
|
723
|
+
} // Enter saves from any field
|
|
724
|
+
if (data === '\x7f' || data === '\b') { // backspace on the active field
|
|
725
|
+
const keys = ['name', 'baseUrl', 'model', 'key'];
|
|
726
|
+
const f = keys[m.fi];
|
|
727
|
+
m.fields[f] = m.fields[f].slice(0, -1);
|
|
728
|
+
this.dirty = true;
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
// printable run: append to the active field (name disallows spaces)
|
|
732
|
+
const run = data.replace(/[\x00-\x1f\x7f]/g, '');
|
|
733
|
+
if (run) {
|
|
734
|
+
const keys = ['name', 'baseUrl', 'model', 'key'];
|
|
735
|
+
const f = keys[m.fi];
|
|
736
|
+
const add = f === 'name' ? run.replace(/\s/g, '') : run;
|
|
737
|
+
m.fields[f] += add;
|
|
738
|
+
this.dirty = true;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
512
741
|
/** Ctrl+R history-search modal (B4): query line + matching entries,
|
|
513
742
|
* newest first; Enter adopts, Esc closes, ^P/^N or arrows move. */
|
|
514
743
|
renderHistSearch(frame, W, H) {
|
|
@@ -1151,6 +1380,53 @@ export class TuiRuntime {
|
|
|
1151
1380
|
return n;
|
|
1152
1381
|
}
|
|
1153
1382
|
onKey(data) {
|
|
1383
|
+
// SGR mouse events (dsh-TUI style, 2026-10-22; press-fix 2026-10-24):
|
|
1384
|
+
// intercept BEFORE any key processing. A click is PRESS+RELEASE - the
|
|
1385
|
+
// press must be CONSUMED (v0.23.38 let it fall through: the leading ESC
|
|
1386
|
+
// closed the palette, so clicks acted like Esc and "didn't work").
|
|
1387
|
+
// parseMouse now returns kind:'ignore' for press/drag/other-button
|
|
1388
|
+
// reports; every complete mouse report is consumed here. X10 legacy
|
|
1389
|
+
// reports (ESC[M + 3 bytes) parse as clicks on left press.
|
|
1390
|
+
{
|
|
1391
|
+
let chunk = data;
|
|
1392
|
+
for (;;) {
|
|
1393
|
+
if (chunk === '' || chunk[0] !== '\x1b')
|
|
1394
|
+
break;
|
|
1395
|
+
if (!isMousePrefix(chunk))
|
|
1396
|
+
break;
|
|
1397
|
+
const parsed = parseMouse(chunk);
|
|
1398
|
+
if (parsed) {
|
|
1399
|
+
const [ev, rest] = parsed;
|
|
1400
|
+
if (ev.kind === 'click')
|
|
1401
|
+
dispatchClick(ev.col, ev.row);
|
|
1402
|
+
else if (ev.kind === 'wheel')
|
|
1403
|
+
this.wheelScroll(ev.wheelUp);
|
|
1404
|
+
// 'ignore' = press/drag/other-button: consumed, no event
|
|
1405
|
+
chunk = rest;
|
|
1406
|
+
continue;
|
|
1407
|
+
}
|
|
1408
|
+
// partial report head (ConPTY fragmentation): hold for the rest
|
|
1409
|
+
if (/^\x1b\[<\d*$/.test(chunk) || /^\x1b\[M?$/.test(chunk)) {
|
|
1410
|
+
this.mouseBuf = chunk;
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
break;
|
|
1414
|
+
}
|
|
1415
|
+
if (this.mouseBuf !== null) {
|
|
1416
|
+
const joined = this.mouseBuf + chunk;
|
|
1417
|
+
this.mouseBuf = null;
|
|
1418
|
+
if (joined !== data) {
|
|
1419
|
+
this.onKey(joined);
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
chunk = joined;
|
|
1423
|
+
}
|
|
1424
|
+
if (chunk !== data) {
|
|
1425
|
+
if (chunk === '')
|
|
1426
|
+
return;
|
|
1427
|
+
data = chunk;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1154
1430
|
// bracketed paste (T22): buffer until the 201~ end marker, then insert
|
|
1155
1431
|
// the sanitized body at the caret; keys/bytes outside the markers keep
|
|
1156
1432
|
// flowing through the normal path (recursion depth stays 1: indexOf
|
|
@@ -1201,6 +1477,12 @@ export class TuiRuntime {
|
|
|
1201
1477
|
this.pickerInput(key);
|
|
1202
1478
|
return;
|
|
1203
1479
|
}
|
|
1480
|
+
// config modal owns every event while open (/config: provider list +
|
|
1481
|
+
// edit form; mouse-clickable rows via the shared region registry)
|
|
1482
|
+
if (this.configModal) {
|
|
1483
|
+
this.configInput(data);
|
|
1484
|
+
return;
|
|
1485
|
+
}
|
|
1204
1486
|
// M2 modals own the keys while open (history search, transcript overlay,
|
|
1205
1487
|
// @-file palette) — each closes on its own Esc
|
|
1206
1488
|
if (this.histSearch) {
|
|
@@ -1467,6 +1749,26 @@ export class TuiRuntime {
|
|
|
1467
1749
|
}
|
|
1468
1750
|
/** insert literal (sanitized paste) text at the caret - the same path
|
|
1469
1751
|
* printable typing takes, so caret/history/palette side-effects match */
|
|
1752
|
+
/** Mouse wheel drives the transcript scroll (same as arrow keys: 3 lines). */
|
|
1753
|
+
wheelScroll(up) {
|
|
1754
|
+
if (this.overlay) {
|
|
1755
|
+
this.overlay.top = Math.max(0, this.overlay.top + (up ? -3 : 3));
|
|
1756
|
+
this.dirty = true;
|
|
1757
|
+
return;
|
|
1758
|
+
}
|
|
1759
|
+
if (up) {
|
|
1760
|
+
if (this.scrollFromBottom < this.totalLines()) {
|
|
1761
|
+
this.scrollFromBottom = Math.min(this.totalLines(), this.scrollFromBottom + 3);
|
|
1762
|
+
this.dirty = true;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
else {
|
|
1766
|
+
if (this.scrollFromBottom > 0) {
|
|
1767
|
+
this.scrollFromBottom = Math.max(0, this.scrollFromBottom - 3);
|
|
1768
|
+
this.dirty = true;
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1470
1772
|
insertText(text) {
|
|
1471
1773
|
if (!text)
|
|
1472
1774
|
return;
|
|
@@ -1484,11 +1786,17 @@ export class TuiRuntime {
|
|
|
1484
1786
|
const W = stdout.columns || 100;
|
|
1485
1787
|
const H = stdout.rows || 30;
|
|
1486
1788
|
const frame = [];
|
|
1789
|
+
clearRegions(); // mouse click regions are re-registered fresh each frame
|
|
1487
1790
|
if (this.resumeModal) {
|
|
1488
1791
|
this.renderResumePicker(frame, W, H);
|
|
1489
1792
|
this.flushFrame(frame, H);
|
|
1490
1793
|
return;
|
|
1491
1794
|
}
|
|
1795
|
+
if (this.configModal) {
|
|
1796
|
+
this.renderConfigModal(frame, W, H);
|
|
1797
|
+
this.flushFrame(frame, H);
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1492
1800
|
if (this.histSearch) {
|
|
1493
1801
|
this.renderHistSearch(frame, W, H);
|
|
1494
1802
|
this.flushFrame(frame, H);
|
|
@@ -1548,6 +1856,10 @@ export class TuiRuntime {
|
|
|
1548
1856
|
const argsTxt = JSON.stringify(this.approval.args);
|
|
1549
1857
|
frame.push(YELLOW(this.t.tuiApproval) + ' ' + YELLOW(BOLD(this.approval.name)) + ' ' + DIM(truncateTo(argsTxt, Math.max(0, W - 24))));
|
|
1550
1858
|
frame.push(` [y] ${GREEN(this.t.tuiApprove)} [n] ${RED(this.t.tuiDeny)} ${DIM(this.t.tuiApprovalHint)}`);
|
|
1859
|
+
// mouse click regions for the approval buttons
|
|
1860
|
+
const apprRow = frame.length - 1;
|
|
1861
|
+
addClickRegion(apprRow, 2, 5, () => this.approvalResolve?.(true));
|
|
1862
|
+
addClickRegion(apprRow, 12, 15, () => this.approvalResolve?.(false));
|
|
1551
1863
|
frame.push(DIM('─'.repeat(W)));
|
|
1552
1864
|
}
|
|
1553
1865
|
// busy status line right above the input box (same position as the web
|
|
@@ -1567,6 +1879,9 @@ export class TuiRuntime {
|
|
|
1567
1879
|
const c = cmdHits[gi];
|
|
1568
1880
|
const sel = gi === this.cmdIdx;
|
|
1569
1881
|
frame.push(truncateTo((sel ? '› ' : ' ') + (sel ? CYAN(c.name) : DIM(c.name)) + ' ' + DIM(truncateTo(c.desc, 46)), W - 1));
|
|
1882
|
+
// mouse click region: this palette row selects + runs the command
|
|
1883
|
+
const palRow = frame.length - 1;
|
|
1884
|
+
addClickRegion(palRow, 0, W - 1, () => { this.cmdIdx = gi; this.pickHighlighted(); });
|
|
1570
1885
|
}
|
|
1571
1886
|
frame.push(DIM(truncateTo(' ' + this.t.panelHint, W - 1)));
|
|
1572
1887
|
}
|
|
@@ -1855,6 +2170,19 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1855
2170
|
rt.addText(rest.slice(0, 2000), 'dim');
|
|
1856
2171
|
fullToolLog.push({ name: 'shell', output: String(r.output).slice(0, 4000) });
|
|
1857
2172
|
}
|
|
2173
|
+
// /config save channel: kernel saveProvider + refreshed rows back to the
|
|
2174
|
+
// modal; blank key = keep stored (saveProvider contract)
|
|
2175
|
+
rt.onSaveProvider(async (name, patch) => {
|
|
2176
|
+
try {
|
|
2177
|
+
const fresh = await saveProvider(name, patch);
|
|
2178
|
+
cfg = { ...cfg, provider: fresh.provider, providers: fresh.providers, routing: fresh.routing };
|
|
2179
|
+
rt.setModelChoices(listProviders(cfg).map((p) => ({ name: p.name, desc: `${p.model}${p.purposes.length ? ' (' + p.purposes.join('/') + ')' : ''}` })));
|
|
2180
|
+
return { ok: true, rows: configProviderRows(cfg) };
|
|
2181
|
+
}
|
|
2182
|
+
catch (err) {
|
|
2183
|
+
return { ok: false, rows: [], error: String(err instanceof Error ? err.message : err).slice(0, 160) };
|
|
2184
|
+
}
|
|
2185
|
+
});
|
|
1858
2186
|
rt.onSubmit(() => {
|
|
1859
2187
|
const line = rt.consumeInput().trim();
|
|
1860
2188
|
if (!line) {
|
|
@@ -2655,6 +2983,11 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2655
2983
|
}
|
|
2656
2984
|
return;
|
|
2657
2985
|
}
|
|
2986
|
+
if (line === '/config' || line.startsWith('/config')) {
|
|
2987
|
+
// one-stop visual editor: providers + API keys, mouse-clickable rows
|
|
2988
|
+
rt.openConfigModal(configProviderRows(cfg));
|
|
2989
|
+
return;
|
|
2990
|
+
}
|
|
2658
2991
|
if (line === '/providers' || line === '/providers scan') {
|
|
2659
2992
|
rt.setBusy(true, '/providers scan');
|
|
2660
2993
|
try {
|
package/dist/web-daemon.d.ts
CHANGED
|
@@ -43,3 +43,9 @@ export declare function startWebDaemon(port?: number, entry?: string, extraArgs?
|
|
|
43
43
|
already: boolean;
|
|
44
44
|
pid: number;
|
|
45
45
|
};
|
|
46
|
+
/** Install the boot auto-start for the CURRENT user. Idempotent. */
|
|
47
|
+
export declare function installWebDaemonAutostart(port?: number, entry?: string): string;
|
|
48
|
+
/** Remove the boot auto-start. Returns the removed file path or ''. */
|
|
49
|
+
export declare function uninstallWebDaemonAutostart(): string;
|
|
50
|
+
/** Check if the boot auto-start is installed. */
|
|
51
|
+
export declare function webDaemonAutostartInstalled(): boolean;
|
package/dist/web-daemon.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { spawn } from 'node:child_process';
|
|
14
14
|
import { execSync } from 'node:child_process';
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
|
-
import { openSync, readFileSync, unlinkSync, writeFileSync, closeSync } from 'node:fs';
|
|
16
|
+
import { openSync, readFileSync, unlinkSync, writeFileSync, closeSync, mkdirSync, existsSync } from 'node:fs';
|
|
17
17
|
import { join } from 'node:path';
|
|
18
18
|
import { homeDir } from '@hmharness/kernel';
|
|
19
19
|
export const DEFAULT_WEB_PORT = 7788;
|
|
@@ -251,3 +251,118 @@ export function startWebDaemon(port = DEFAULT_WEB_PORT, entry = process.argv[1],
|
|
|
251
251
|
return { already: true, pid };
|
|
252
252
|
return { already: false, pid: spawnWebDaemon(port, entry, extraArgs) };
|
|
253
253
|
}
|
|
254
|
+
/* ---- Boot auto-start (2026-10-23 user request) ----
|
|
255
|
+
* The web daemon normally starts lazily — when a CLI command or the TUI
|
|
256
|
+
* brings it up. For phone remote control to work "even when no app is
|
|
257
|
+
* open", the daemon must come up at LOGIN with no user action.
|
|
258
|
+
*
|
|
259
|
+
* Windows: a .cmd shortcut in the user's Startup folder (no admin rights
|
|
260
|
+
* needed, starts at every logon).
|
|
261
|
+
* macOS: a LaunchAgent plist (~/Library/LaunchAgents).
|
|
262
|
+
* Linux: a systemd user unit (loginctl enable-linger for boot-start).
|
|
263
|
+
* All three run `node <entry> web start --port=<port>` invisibly.
|
|
264
|
+
*/
|
|
265
|
+
function startupDir() {
|
|
266
|
+
if (process.platform === 'win32') {
|
|
267
|
+
return join(process.env.APPDATA ?? '', 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup');
|
|
268
|
+
}
|
|
269
|
+
if (process.platform === 'darwin') {
|
|
270
|
+
return join(process.env.HOME ?? '', 'Library', 'LaunchAgents');
|
|
271
|
+
}
|
|
272
|
+
return join(process.env.HOME ?? '', '.config', 'systemd', 'user');
|
|
273
|
+
}
|
|
274
|
+
function autostartLabel() {
|
|
275
|
+
return 'hmharness-web-daemon';
|
|
276
|
+
}
|
|
277
|
+
/** Install the boot auto-start for the CURRENT user. Idempotent. */
|
|
278
|
+
export function installWebDaemonAutostart(port = DEFAULT_WEB_PORT, entry = process.argv[1]) {
|
|
279
|
+
const dir = startupDir();
|
|
280
|
+
if (process.platform === 'win32') {
|
|
281
|
+
mkdirSync(dir, { recursive: true });
|
|
282
|
+
const cmdPath = join(dir, `${autostartLabel()}.cmd`);
|
|
283
|
+
const nodeExe = process.execPath.replace(/\\/g, '\\\\');
|
|
284
|
+
const entryPath = entry.replace(/\\/g, '\\\\');
|
|
285
|
+
writeFileSync(cmdPath, [
|
|
286
|
+
`@echo off`,
|
|
287
|
+
`"${nodeExe}" "${entryPath}" web start --port=${port} > NUL 2>&1`,
|
|
288
|
+
].join('\r\n'), 'utf8');
|
|
289
|
+
return cmdPath;
|
|
290
|
+
}
|
|
291
|
+
if (process.platform === 'darwin') {
|
|
292
|
+
mkdirSync(dir, { recursive: true });
|
|
293
|
+
const plist = join(dir, `${autostartLabel()}.plist`);
|
|
294
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
295
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
296
|
+
<plist version="1.0"><dict>
|
|
297
|
+
<key>Label</key><string>${autostartLabel()}</string>
|
|
298
|
+
<key>ProgramArguments</key><array>
|
|
299
|
+
<string>${process.execPath}</string>
|
|
300
|
+
<string>${entry}</string>
|
|
301
|
+
<string>web</string>
|
|
302
|
+
<string>start</string>
|
|
303
|
+
<string>--port=${port}</string>
|
|
304
|
+
</array>
|
|
305
|
+
<key>RunAtLoad</key><true/>
|
|
306
|
+
<key>StandardOutPath</key><string>${join(homeDir(), 'web.log')}</string>
|
|
307
|
+
<key>StandardErrorPath</key><string>${join(homeDir(), 'web.log')}</string>
|
|
308
|
+
</dict></plist>`;
|
|
309
|
+
writeFileSync(plist, xml, 'utf8');
|
|
310
|
+
return plist;
|
|
311
|
+
}
|
|
312
|
+
// Linux: systemd user unit
|
|
313
|
+
mkdirSync(dir, { recursive: true });
|
|
314
|
+
const unit = join(dir, `${autostartLabel()}.service`);
|
|
315
|
+
writeFileSync(unit, [
|
|
316
|
+
`[Unit]`,
|
|
317
|
+
`Description=hmharness web daemon (phone remote control)`,
|
|
318
|
+
``,
|
|
319
|
+
`[Service]`,
|
|
320
|
+
`Type=oneshot`,
|
|
321
|
+
`RemainAfterExit=yes`,
|
|
322
|
+
`ExecStart=${process.execPath} ${entry} web start --port=${port}`,
|
|
323
|
+
``,
|
|
324
|
+
`[Install]`,
|
|
325
|
+
`WantedBy=default.target`,
|
|
326
|
+
].join('\n'), 'utf8');
|
|
327
|
+
try {
|
|
328
|
+
execSync('systemctl --user daemon-reload', { timeout: 10_000 });
|
|
329
|
+
}
|
|
330
|
+
catch { /* best effort */ }
|
|
331
|
+
try {
|
|
332
|
+
execSync(`systemctl --user enable ${autostartLabel()}`, { timeout: 10_000 });
|
|
333
|
+
}
|
|
334
|
+
catch { /* best effort */ }
|
|
335
|
+
return unit;
|
|
336
|
+
}
|
|
337
|
+
/** Remove the boot auto-start. Returns the removed file path or ''. */
|
|
338
|
+
export function uninstallWebDaemonAutostart() {
|
|
339
|
+
const dir = startupDir();
|
|
340
|
+
const candidates = [
|
|
341
|
+
join(dir, `${autostartLabel()}.cmd`),
|
|
342
|
+
join(dir, `${autostartLabel()}.plist`),
|
|
343
|
+
join(dir, `${autostartLabel()}.service`),
|
|
344
|
+
];
|
|
345
|
+
for (const c of candidates) {
|
|
346
|
+
if (existsSync(c)) {
|
|
347
|
+
try {
|
|
348
|
+
unlinkSync(c);
|
|
349
|
+
}
|
|
350
|
+
catch { /* locked */ }
|
|
351
|
+
if (process.platform === 'linux') {
|
|
352
|
+
try {
|
|
353
|
+
execSync(`systemctl --user disable ${autostartLabel()}`, { timeout: 10_000 });
|
|
354
|
+
}
|
|
355
|
+
catch { /* best effort */ }
|
|
356
|
+
}
|
|
357
|
+
return c;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return '';
|
|
361
|
+
}
|
|
362
|
+
/** Check if the boot auto-start is installed. */
|
|
363
|
+
export function webDaemonAutostartInstalled() {
|
|
364
|
+
const dir = startupDir();
|
|
365
|
+
return existsSync(join(dir, `${autostartLabel()}.cmd`))
|
|
366
|
+
|| existsSync(join(dir, `${autostartLabel()}.plist`))
|
|
367
|
+
|| existsSync(join(dir, `${autostartLabel()}.service`));
|
|
368
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.39",
|
|
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,20 +45,20 @@
|
|
|
45
45
|
"build": "tsc -p tsconfig.build.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@hmharness/agent": "0.23.
|
|
49
|
-
"@hmharness/browser": "0.23.
|
|
50
|
-
"@hmharness/cognitive": "0.23.
|
|
51
|
-
"@hmharness/domain-harmony": "0.23.
|
|
52
|
-
"@hmharness/domain-ops": "0.23.
|
|
53
|
-
"@hmharness/environments": "0.23.
|
|
54
|
-
"@hmharness/evaluation": "0.23.
|
|
55
|
-
"@hmharness/evolution": "0.23.
|
|
56
|
-
"@hmharness/extension": "0.23.
|
|
57
|
-
"@hmharness/kernel": "0.23.
|
|
58
|
-
"@hmharness/observability": "0.23.
|
|
59
|
-
"@hmharness/sandbox": "0.23.
|
|
60
|
-
"@hmharness/web": "0.23.
|
|
48
|
+
"@hmharness/agent": "0.23.39",
|
|
49
|
+
"@hmharness/browser": "0.23.39",
|
|
50
|
+
"@hmharness/cognitive": "0.23.39",
|
|
51
|
+
"@hmharness/domain-harmony": "0.23.39",
|
|
52
|
+
"@hmharness/domain-ops": "0.23.39",
|
|
53
|
+
"@hmharness/environments": "0.23.39",
|
|
54
|
+
"@hmharness/evaluation": "0.23.39",
|
|
55
|
+
"@hmharness/evolution": "0.23.39",
|
|
56
|
+
"@hmharness/extension": "0.23.39",
|
|
57
|
+
"@hmharness/kernel": "0.23.39",
|
|
58
|
+
"@hmharness/observability": "0.23.39",
|
|
59
|
+
"@hmharness/sandbox": "0.23.39",
|
|
60
|
+
"@hmharness/web": "0.23.39",
|
|
61
61
|
"qrcode": "^1.5.4",
|
|
62
|
-
"@hmharness/lsp": "0.23.
|
|
62
|
+
"@hmharness/lsp": "0.23.39"
|
|
63
63
|
}
|
|
64
64
|
}
|
package/release-notes.json
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"notes": [
|
|
3
|
+
{
|
|
4
|
+
"v": "0.23.39",
|
|
5
|
+
"date": "2026-10-24",
|
|
6
|
+
"note": "鼠标点击假死根修(按下序列被当 Esc 的 bug)+ /config 一键密钥配置(可视化编辑 provider/模型/密钥,鼠标可点)"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"v": "0.23.38",
|
|
10
|
+
"date": "2026-10-23",
|
|
11
|
+
"note": "默认多模态(发图给多模态模型直接看原图,仅纯文本模型走辅助识别);TUI 鼠标点击(命令面板/审批/会话选择/滚轮);远程控制永久生效+开机自启(hmh web install-daemon)"
|
|
12
|
+
},
|
|
3
13
|
{
|
|
4
14
|
"v": "0.23.37",
|
|
5
15
|
"date": "2026-10-21",
|