@hmharness/cli 0.23.38 → 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/tui-mouse.d.ts +18 -14
- package/dist/tui-mouse.js +51 -29
- package/dist/tui.d.ts +43 -1
- package/dist/tui.js +268 -10
- package/package.json +15 -15
- package/release-notes.json +5 -0
|
@@ -63,9 +63,9 @@ let PACKAGES = ['cli', 'web', 'agent', 'kernel', 'sandbox', 'evolution',
|
|
|
63
63
|
// The release bot keeps versions synced; the NAMES must cover the full
|
|
64
64
|
// first-party set so the offline path cannot produce an incomplete tree.
|
|
65
65
|
const FALLBACK_PINS = {
|
|
66
|
-
cli: '0.23.
|
|
67
|
-
sandbox: '0.23.
|
|
68
|
-
evaluation: '0.23.
|
|
66
|
+
cli: '0.23.39', web: '0.23.39', agent: '0.23.39', kernel: '0.23.39',
|
|
67
|
+
sandbox: '0.23.39', evolution: '0.23.39', 'domain-ops': '0.23.39',
|
|
68
|
+
evaluation: '0.23.39', observability: '0.23.39', 'domain-harmony': '0.23.39',
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
// ---------- helpers ---------------------------------------------------------
|
package/dist/tui-mouse.d.ts
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @hmharness/cli - tui-mouse (2026-10-22
|
|
2
|
+
* @hmharness/cli - tui-mouse (2026-10-22; press-consumption fix 2026-10-24)
|
|
3
3
|
*
|
|
4
4
|
* SGR mouse tracking (DECSET 1000+1002+1006): the terminal reports
|
|
5
|
-
* ESC[<button;col;
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* ESC[<button;col;rowM (press) / m (release). A LEFT-BUTTON RELEASE without
|
|
6
|
+
* drag is a click (dsh-TUI's contract). CRITICAL LESSON (v0.23.38 shipped a
|
|
7
|
+
* dead click path): a click is reported as TWO sequences - press then
|
|
8
|
+
* release. The press sequence MUST be consumed too; letting it fall through
|
|
9
|
+
* to key handling made the leading ESC close the palette, so every click
|
|
10
|
+
* behaved like Esc and clicks "didn't work". parseMouse therefore returns
|
|
11
|
+
* kind:'ignore' for consumed-but-not-click reports (press, drag, non-left
|
|
12
|
+
* buttons) - NEVER null for a complete mouse report.
|
|
9
13
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* start of every frame, so the registry is always one frame fresh.
|
|
14
|
+
* X10 fallback (mode 1000 terminals without SGR): ESC[M + 3 raw bytes.
|
|
15
|
+
* X10 has no per-button release; a left PRESS is treated as the click.
|
|
13
16
|
*/
|
|
14
|
-
/** Enable
|
|
17
|
+
/** Enable mouse tracking: 1000 (press/release/wheel) + 1002 (drag) + 1006 (SGR). */
|
|
15
18
|
export declare const ENABLE_MOUSE = "\u001B[?1000h\u001B[?1002h\u001B[?1006h";
|
|
16
19
|
/** Disable all mouse tracking modes. */
|
|
17
20
|
export declare const DISABLE_MOUSE = "\u001B[?1006l\u001B[?1002l\u001B[?1000l";
|
|
18
21
|
export interface ParsedMouse {
|
|
19
|
-
kind: 'click' | 'wheel';
|
|
22
|
+
kind: 'click' | 'wheel' | 'ignore';
|
|
20
23
|
col: number;
|
|
21
24
|
row: number;
|
|
22
25
|
wheelUp: boolean;
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
|
-
* Try to parse
|
|
26
|
-
* Returns [event, rest-of-chunk] or null
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* Try to parse ONE mouse sequence from the head of the chunk.
|
|
29
|
+
* Returns [event, rest-of-chunk] or null when the chunk does not START with
|
|
30
|
+
* a complete mouse report. Complete-but-uninteresting reports (press, drag,
|
|
31
|
+
* non-left buttons) return kind:'ignore' so the caller consumes them -
|
|
32
|
+
* returning null for those is how v0.23.38 broke clicks.
|
|
29
33
|
*/
|
|
30
34
|
export declare function parseMouse(chunk: string): [ParsedMouse, string] | null;
|
|
31
35
|
/** True if the chunk LOOKS like the start of a mouse report (may be partial). */
|
package/dist/tui-mouse.js
CHANGED
|
@@ -1,52 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @hmharness/cli - tui-mouse (2026-10-22
|
|
2
|
+
* @hmharness/cli - tui-mouse (2026-10-22; press-consumption fix 2026-10-24)
|
|
3
3
|
*
|
|
4
4
|
* SGR mouse tracking (DECSET 1000+1002+1006): the terminal reports
|
|
5
|
-
* ESC[<button;col;
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* ESC[<button;col;rowM (press) / m (release). A LEFT-BUTTON RELEASE without
|
|
6
|
+
* drag is a click (dsh-TUI's contract). CRITICAL LESSON (v0.23.38 shipped a
|
|
7
|
+
* dead click path): a click is reported as TWO sequences - press then
|
|
8
|
+
* release. The press sequence MUST be consumed too; letting it fall through
|
|
9
|
+
* to key handling made the leading ESC close the palette, so every click
|
|
10
|
+
* behaved like Esc and clicks "didn't work". parseMouse therefore returns
|
|
11
|
+
* kind:'ignore' for consumed-but-not-click reports (press, drag, non-left
|
|
12
|
+
* buttons) - NEVER null for a complete mouse report.
|
|
9
13
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* start of every frame, so the registry is always one frame fresh.
|
|
14
|
+
* X10 fallback (mode 1000 terminals without SGR): ESC[M + 3 raw bytes.
|
|
15
|
+
* X10 has no per-button release; a left PRESS is treated as the click.
|
|
13
16
|
*/
|
|
14
|
-
/** Enable
|
|
17
|
+
/** Enable mouse tracking: 1000 (press/release/wheel) + 1002 (drag) + 1006 (SGR). */
|
|
15
18
|
export const ENABLE_MOUSE = '\x1b[?1000h\x1b[?1002h\x1b[?1006h';
|
|
16
19
|
/** Disable all mouse tracking modes. */
|
|
17
20
|
export const DISABLE_MOUSE = '\x1b[?1006l\x1b[?1002l\x1b[?1000l';
|
|
18
21
|
/** SGR mouse report: ESC[<btn;col;rowM (press) / m (release). */
|
|
19
22
|
const SGR_MOUSE_RE = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])/;
|
|
20
23
|
/**
|
|
21
|
-
* Try to parse
|
|
22
|
-
* Returns [event, rest-of-chunk] or null
|
|
23
|
-
*
|
|
24
|
-
*
|
|
24
|
+
* Try to parse ONE mouse sequence from the head of the chunk.
|
|
25
|
+
* Returns [event, rest-of-chunk] or null when the chunk does not START with
|
|
26
|
+
* a complete mouse report. Complete-but-uninteresting reports (press, drag,
|
|
27
|
+
* non-left buttons) return kind:'ignore' so the caller consumes them -
|
|
28
|
+
* returning null for those is how v0.23.38 broke clicks.
|
|
25
29
|
*/
|
|
26
30
|
export function parseMouse(chunk) {
|
|
27
31
|
const m = SGR_MOUSE_RE.exec(chunk);
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
if (m) {
|
|
33
|
+
const button = parseInt(m[1], 10);
|
|
34
|
+
const col = parseInt(m[2], 10) - 1; // SGR is 1-indexed, we 0-index
|
|
35
|
+
const row = parseInt(m[3], 10) - 1;
|
|
36
|
+
const isRelease = m[4] === 'm';
|
|
37
|
+
const rest = chunk.slice(m[0].length);
|
|
38
|
+
// wheel: button bit 6 set; low bits 0=up 1=down
|
|
39
|
+
if ((button & 0x40) !== 0) {
|
|
40
|
+
return [{ kind: 'wheel', col, row, wheelUp: (button & 0x01) === 0 }, rest];
|
|
41
|
+
}
|
|
42
|
+
// left button (low bits 0) RELEASE = click
|
|
43
|
+
if ((button & 0x03) === 0 && isRelease) {
|
|
44
|
+
return [{ kind: 'click', col, row, wheelUp: false }, rest];
|
|
45
|
+
}
|
|
46
|
+
// press / drag-motion / right / middle: consumed, no event
|
|
47
|
+
return [{ kind: 'ignore', col, row, wheelUp: false }, rest];
|
|
38
48
|
}
|
|
39
|
-
//
|
|
40
|
-
if ((
|
|
41
|
-
|
|
49
|
+
// X10 legacy report: ESC[M + Cb/Cx/Cy raw bytes (each +32)
|
|
50
|
+
if (chunk.startsWith('\x1b[M') && chunk.length >= 6) {
|
|
51
|
+
const button = chunk.charCodeAt(3) - 32;
|
|
52
|
+
const col = chunk.charCodeAt(4) - 32 - 1; // X10 coords are 1-indexed like SGR
|
|
53
|
+
const row = chunk.charCodeAt(5) - 32 - 1;
|
|
54
|
+
const rest = chunk.slice(6);
|
|
55
|
+
if ((button & 0x40) !== 0) {
|
|
56
|
+
return [{ kind: 'wheel', col, row, wheelUp: (button & 0x01) === 0 }, rest];
|
|
57
|
+
}
|
|
58
|
+
// X10 cannot say WHICH button released; a left PRESS is the best click
|
|
59
|
+
// signal available (drag pairs would double-fire, motion bit excludes)
|
|
60
|
+
if ((button & 0x20) === 0 && (button & 0x03) === 0) {
|
|
61
|
+
return [{ kind: 'click', col, row, wheelUp: false }, rest];
|
|
62
|
+
}
|
|
63
|
+
return [{ kind: 'ignore', col, row, wheelUp: false }, rest];
|
|
42
64
|
}
|
|
43
|
-
// press events, right/middle button, drag-motion: consumed silently
|
|
44
65
|
return null;
|
|
45
66
|
}
|
|
46
67
|
/** True if the chunk LOOKS like the start of a mouse report (may be partial). */
|
|
47
68
|
export function isMousePrefix(chunk) {
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
return /^\x1b\[<\d+(?:;\d*){0,2}[Mm]?/.test(chunk)
|
|
70
|
+
|| /^\x1b\[<\d*$/.test(chunk)
|
|
71
|
+
|| chunk === '\x1b[M'.slice(0, chunk.length) && chunk.length >= 2; // partial X10 head
|
|
50
72
|
}
|
|
51
73
|
let regions = [];
|
|
52
74
|
let zCounter = 0;
|
package/dist/tui.d.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { type SessionSummary } from '@hmharness/kernel';
|
|
1
|
+
import { type HmhConfig, type SessionSummary } from '@hmharness/kernel';
|
|
2
2
|
import { type Locale } from '@hmharness/agent';
|
|
3
3
|
interface Entry {
|
|
4
4
|
lines: string[];
|
|
5
5
|
}
|
|
6
6
|
/** desc keys index into Strings (agent i18n); matched by name at runtime. */
|
|
7
|
+
/** a provider row in the /config modal list */
|
|
8
|
+
export type ConfigProviderRow = {
|
|
9
|
+
name: string;
|
|
10
|
+
model: string;
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
purposes: string;
|
|
13
|
+
};
|
|
14
|
+
/** Build the /config provider table from config: purposes from routing
|
|
15
|
+
* (chat/vision/evolve/bench/judge). Pure — unit-testable. */
|
|
16
|
+
export declare function configProviderRows(cfg: HmhConfig): ConfigProviderRow[];
|
|
7
17
|
export declare const COMMANDS: Array<{
|
|
8
18
|
name: string;
|
|
9
19
|
key: string;
|
|
@@ -165,6 +175,27 @@ export declare class TuiRuntime {
|
|
|
165
175
|
* the codex alt-screen picker contract. resolve fires on Enter (resume)
|
|
166
176
|
* or Esc/Ctrl-C (close). */
|
|
167
177
|
private resumeModal;
|
|
178
|
+
private configListRows;
|
|
179
|
+
private configModal;
|
|
180
|
+
private saveProviderCb;
|
|
181
|
+
/** Driver wires the real save (kernel saveProvider) + list refresh here. */
|
|
182
|
+
onSaveProvider(fn: NonNullable<TuiRuntime['saveProviderCb']>): void;
|
|
183
|
+
/** Open the modal with a provider snapshot (driver loads it). */
|
|
184
|
+
openConfigModal(rows: ConfigProviderRow[]): void;
|
|
185
|
+
/** Headless-test probe: modal shape for assertions. */
|
|
186
|
+
configProbe(): {
|
|
187
|
+
open: boolean;
|
|
188
|
+
mode: string;
|
|
189
|
+
rows: string[];
|
|
190
|
+
sel: number;
|
|
191
|
+
fields?: Array<{
|
|
192
|
+
label: string;
|
|
193
|
+
value: string;
|
|
194
|
+
masked: boolean;
|
|
195
|
+
}>;
|
|
196
|
+
fi?: number;
|
|
197
|
+
note: string;
|
|
198
|
+
};
|
|
168
199
|
openResumePicker(): Promise<{
|
|
169
200
|
kind: 'resume';
|
|
170
201
|
row: SessionSummary;
|
|
@@ -178,6 +209,17 @@ export declare class TuiRuntime {
|
|
|
178
209
|
/** Full-frame picker layout (codex draw_picker): title / search+toolbar /
|
|
179
210
|
* list window / two hint lines / position footer. */
|
|
180
211
|
private renderResumePicker;
|
|
212
|
+
/** Full-frame provider editor: list view (click/Enter a row to edit) or
|
|
213
|
+
* form view (fields, key masked, blank key = keep stored). Mouse clicks
|
|
214
|
+
* dispatch through the shared region registry like every other modal. */
|
|
215
|
+
private renderConfigModal;
|
|
216
|
+
/** Open the edit form for row gi (-1 = new provider). Keeps a snapshot of
|
|
217
|
+
* the list for the back button (refreshed again after every save). */
|
|
218
|
+
private openConfigForm;
|
|
219
|
+
/** Validate + persist the form via the driver-wired save callback. */
|
|
220
|
+
private saveConfigForm;
|
|
221
|
+
/** Keyboard input for the config modal (modal owns every event). */
|
|
222
|
+
private configInput;
|
|
181
223
|
/** Ctrl+R history-search modal (B4): query line + matching entries,
|
|
182
224
|
* newest first; Enter adopts, Esc closes, ^P/^N or arrows move. */
|
|
183
225
|
private renderHistSearch;
|
package/dist/tui.js
CHANGED
|
@@ -14,7 +14,7 @@ import { stdin, stdout } from 'node:process';
|
|
|
14
14
|
import { basename } from 'node:path';
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
16
|
import { parseMouse, isMousePrefix, dispatchClick, clearRegions, addClickRegion } from "./tui-mouse.js";
|
|
17
|
-
import { loadConfig, homeDir, resolveProvider, listProviders, setChatRoute, setLocale, PROVIDER_PRESETS, addProviders, detectLocalProviders, latestSession, listSessions, loadTranscript, transcriptChars, compactMessages, adaptiveContextChars, getGoal, setGoal, clearGoal, isProviderAuthError } from '@hmharness/kernel';
|
|
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';
|
|
18
18
|
import { listDrafts, listSkills, runBench, runEvolution } from '@hmharness/evolution';
|
|
19
19
|
import { buildRegistry, runAgentTask, strings } from '@hmharness/agent';
|
|
20
20
|
import { ensureWebDaemon, DEFAULT_WEB_PORT } from "./web-daemon.js";
|
|
@@ -90,13 +90,31 @@ function truncateTo(s, width) {
|
|
|
90
90
|
}
|
|
91
91
|
return out;
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
|
|
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
|
+
}
|
|
95
112
|
export const COMMANDS = [
|
|
96
113
|
{ name: '/help', key: 'cmdHelp' },
|
|
97
114
|
{ name: '/tools', key: 'cmdTools' },
|
|
98
115
|
{ name: '/skills', key: 'cmdSkills' },
|
|
99
116
|
{ name: '/model', key: 'cmdModel' },
|
|
117
|
+
{ name: '/config', key: 'cmdConfig' },
|
|
100
118
|
{ name: '/lang', key: 'cmdLang' },
|
|
101
119
|
{ name: '/yolo', key: 'cmdYolo' },
|
|
102
120
|
{ name: '/providers', key: 'cmdProviders' },
|
|
@@ -408,6 +426,33 @@ export class TuiRuntime {
|
|
|
408
426
|
* the codex alt-screen picker contract. resolve fires on Enter (resume)
|
|
409
427
|
* or Esc/Ctrl-C (close). */
|
|
410
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
|
+
}
|
|
411
456
|
openResumePicker() {
|
|
412
457
|
if (this.resumeModal)
|
|
413
458
|
return Promise.resolve(null);
|
|
@@ -515,6 +560,184 @@ export class TuiRuntime {
|
|
|
515
560
|
const posLine = t.pickerPos(pos, vis.length, vis.length ? String(Math.round((pos / vis.length) * 100)) : '0');
|
|
516
561
|
frame.push(' '.repeat(Math.max(0, W - posLine.length - 1)) + DIM(posLine));
|
|
517
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
|
+
}
|
|
518
741
|
/** Ctrl+R history-search modal (B4): query line + matching entries,
|
|
519
742
|
* newest first; Enter adopts, Esc closes, ^P/^N or arrows move. */
|
|
520
743
|
renderHistSearch(frame, W, H) {
|
|
@@ -1157,11 +1380,13 @@ export class TuiRuntime {
|
|
|
1157
1380
|
return n;
|
|
1158
1381
|
}
|
|
1159
1382
|
onKey(data) {
|
|
1160
|
-
// SGR mouse events (dsh-TUI style, 2026-10-22):
|
|
1161
|
-
// key processing
|
|
1162
|
-
//
|
|
1163
|
-
// the
|
|
1164
|
-
//
|
|
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.
|
|
1165
1390
|
{
|
|
1166
1391
|
let chunk = data;
|
|
1167
1392
|
for (;;) {
|
|
@@ -1176,11 +1401,12 @@ export class TuiRuntime {
|
|
|
1176
1401
|
dispatchClick(ev.col, ev.row);
|
|
1177
1402
|
else if (ev.kind === 'wheel')
|
|
1178
1403
|
this.wheelScroll(ev.wheelUp);
|
|
1404
|
+
// 'ignore' = press/drag/other-button: consumed, no event
|
|
1179
1405
|
chunk = rest;
|
|
1180
1406
|
continue;
|
|
1181
1407
|
}
|
|
1182
|
-
// partial
|
|
1183
|
-
if (/^\x1b\[<\d*$/.test(chunk)) {
|
|
1408
|
+
// partial report head (ConPTY fragmentation): hold for the rest
|
|
1409
|
+
if (/^\x1b\[<\d*$/.test(chunk) || /^\x1b\[M?$/.test(chunk)) {
|
|
1184
1410
|
this.mouseBuf = chunk;
|
|
1185
1411
|
return;
|
|
1186
1412
|
}
|
|
@@ -1251,6 +1477,12 @@ export class TuiRuntime {
|
|
|
1251
1477
|
this.pickerInput(key);
|
|
1252
1478
|
return;
|
|
1253
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
|
+
}
|
|
1254
1486
|
// M2 modals own the keys while open (history search, transcript overlay,
|
|
1255
1487
|
// @-file palette) — each closes on its own Esc
|
|
1256
1488
|
if (this.histSearch) {
|
|
@@ -1560,6 +1792,11 @@ export class TuiRuntime {
|
|
|
1560
1792
|
this.flushFrame(frame, H);
|
|
1561
1793
|
return;
|
|
1562
1794
|
}
|
|
1795
|
+
if (this.configModal) {
|
|
1796
|
+
this.renderConfigModal(frame, W, H);
|
|
1797
|
+
this.flushFrame(frame, H);
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1563
1800
|
if (this.histSearch) {
|
|
1564
1801
|
this.renderHistSearch(frame, W, H);
|
|
1565
1802
|
this.flushFrame(frame, H);
|
|
@@ -1642,6 +1879,9 @@ export class TuiRuntime {
|
|
|
1642
1879
|
const c = cmdHits[gi];
|
|
1643
1880
|
const sel = gi === this.cmdIdx;
|
|
1644
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(); });
|
|
1645
1885
|
}
|
|
1646
1886
|
frame.push(DIM(truncateTo(' ' + this.t.panelHint, W - 1)));
|
|
1647
1887
|
}
|
|
@@ -1930,6 +2170,19 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1930
2170
|
rt.addText(rest.slice(0, 2000), 'dim');
|
|
1931
2171
|
fullToolLog.push({ name: 'shell', output: String(r.output).slice(0, 4000) });
|
|
1932
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
|
+
});
|
|
1933
2186
|
rt.onSubmit(() => {
|
|
1934
2187
|
const line = rt.consumeInput().trim();
|
|
1935
2188
|
if (!line) {
|
|
@@ -2730,6 +2983,11 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2730
2983
|
}
|
|
2731
2984
|
return;
|
|
2732
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
|
+
}
|
|
2733
2991
|
if (line === '/providers' || line === '/providers scan') {
|
|
2734
2992
|
rt.setBusy(true, '/providers scan');
|
|
2735
2993
|
try {
|
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
|
}
|