@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/dist/main.js CHANGED
@@ -27,7 +27,7 @@ import { readFile } from 'node:fs/promises';
27
27
  import { mkdir, rm } from 'node:fs/promises';
28
28
  import { join } from 'node:path';
29
29
  import { tmpdir } from 'node:os';
30
- import { stopWebDaemon, startWebDaemon, hmhWebUp, readWebPid } from "./web-daemon.js";
30
+ import { stopWebDaemon, startWebDaemon, hmhWebUp, readWebPid, ensureWebDaemon } from "./web-daemon.js";
31
31
  import { chat, homeDir, resolveProvider, initHome, latestSession, listProviders, listSessions, loadConfig, loadTranscript, mcpServerTools, Registry, runLoop, setChatRoute, setLocale, } from '@hmharness/kernel';
32
32
  import { listSkills, listDrafts, promoteSkill, runBench, runEvolution, rollbackSkill, unpromoteSkill, } from '@hmharness/evolution';
33
33
  import { harmonyTools } from '@hmharness/domain-harmony';
@@ -1113,12 +1113,54 @@ flags:
1113
1113
  bridge.onConnectionChange = (connected) => {
1114
1114
  stdout.write(connected ? '\n ✓ 浏览器扩展已连接\n' : '\n ✗ 浏览器扩展断开\n');
1115
1115
  };
1116
- // 侧栏对话面板的大脑:工具环走本桥,provider 走用户配置(routing chat)
1117
- bridge.onChat = (input) => answerChatTurn(input, {
1118
- readPage: () => bridge.command('page.read', undefined, 20_000),
1119
- act: (a) => bridge.command('page.act', { act: a }, 20_000),
1120
- log: (l) => stdout.write(` ${DIM(l)}\n`),
1121
- });
1116
+ // 侧栏对话面板的大脑(round 52):与 BrowserOS 面板收敛为同一个智能体
1117
+ // ——runAgentTask(完整工具注册表+真实系统提示词[记忆/技能/洞察]+按
1118
+ // 浏览器隔离的会话延续);审批门=对话式确认;步骤流实时上屏。旧的
1119
+ // 紧凑循环留作 agent 不可用时的降级路径。
1120
+ const tctx = { cwd: process.cwd(), home: homeDir() };
1121
+ const stepOf = (input) => (l) => {
1122
+ bridge.noteChatActivity(input.origin ?? 'anon', l);
1123
+ stdout.write(` ${DIM('· ' + l)}\n`);
1124
+ };
1125
+ let agentBrain = null;
1126
+ try {
1127
+ const { buildRegistry, runAgentTask } = await import('@hmharness/agent');
1128
+ const { answerWithAgentTurn } = await import("./extension-agent-brain.js");
1129
+ let cached = null;
1130
+ agentBrain = (input) => answerWithAgentTurn(input, {
1131
+ buildRegistry: async () => (cached ??= await buildRegistry({ mcp: true, announce: false })),
1132
+ buildRegistryNative: async () => buildRegistry({ mcp: false, announce: false }),
1133
+ runAgentTask: runAgentTask,
1134
+ ctx: tctx,
1135
+ goto: (url) => bridge.command('page.goto', { url }, 20_000),
1136
+ readPage: () => bridge.command('page.read', undefined, 20_000),
1137
+ step: stepOf(input),
1138
+ log: (l) => stdout.write(` ${DIM(l)}\n`),
1139
+ });
1140
+ stdout.write(' 大脑: 完整 agent(与 BrowserOS/acp-serve 同源)\n');
1141
+ }
1142
+ catch (err) {
1143
+ stdout.write(` 大脑: 紧凑循环(agent 不可用: ${String(err instanceof Error ? err.message : err).slice(0, 80)})\n`);
1144
+ }
1145
+ if (agentBrain) {
1146
+ bridge.onChat = (input) => agentBrain(input);
1147
+ }
1148
+ else {
1149
+ const { readFileTool, writeFileTool, listDirTool, runCommandTool } = await import('@hmharness/agent');
1150
+ bridge.onChat = (input) => answerChatTurn(input, {
1151
+ workspace: process.cwd(),
1152
+ readPage: () => bridge.command('page.read', undefined, 20_000),
1153
+ act: (a) => bridge.command('page.act', { act: a }, 20_000),
1154
+ goto: (url) => bridge.command('page.goto', { url }, 20_000),
1155
+ listTabs: () => bridge.command('tabs.list', undefined, 20_000),
1156
+ readFile: (p) => readFileTool.execute({ path: p }, tctx),
1157
+ writeFile: (p, c) => writeFileTool.execute({ path: p, content: c }, tctx),
1158
+ listDir: (p) => listDirTool.execute({ path: p || '.' }, tctx),
1159
+ runCommand: (cmd, t) => runCommandTool.execute({ command: cmd, ...(t ? { timeout_ms: t } : {}) }, tctx),
1160
+ log: (l) => stdout.write(` ${DIM(l)}\n`),
1161
+ step: stepOf(input),
1162
+ });
1163
+ }
1122
1164
  bridge.onAutoPair = (origin) => {
1123
1165
  stdout.write(`\n ✓ 扩展自动授权: ${origin}(零操作连接)\n`);
1124
1166
  };
@@ -1846,6 +1888,25 @@ flags:
1846
1888
  }
1847
1889
  const t = await uiStrings();
1848
1890
  const sub = rest.find((a) => !a.startsWith('-'));
1891
+ if (sub === 'install-daemon') {
1892
+ // boot auto-start (2026-10-23): the web daemon starts at LOGIN with
1893
+ // no terminal/app needed — phone remote control is always reachable.
1894
+ const { installWebDaemonAutostart } = await import("./web-daemon.js");
1895
+ const path = installWebDaemonAutostart(port, process.argv[1]);
1896
+ stdout.write(`✓ 远程控制守护已设为开机自启(登录即启动,无需打开任何应用)\n`);
1897
+ stdout.write(` 启动项: ${path}\n`);
1898
+ stdout.write(DIM(` 移除: hmh web uninstall-daemon\n`));
1899
+ const ok = await ensureWebDaemon(port);
1900
+ if (ok)
1901
+ stdout.write(`✓ 守护已启动 · 手机随时可连\n`);
1902
+ return;
1903
+ }
1904
+ if (sub === 'uninstall-daemon') {
1905
+ const { uninstallWebDaemonAutostart } = await import("./web-daemon.js");
1906
+ const removed = uninstallWebDaemonAutostart();
1907
+ stdout.write(removed ? `已移除开机自启: ${removed}\n` : `(未安装)\n`);
1908
+ return;
1909
+ }
1849
1910
  if (sub === 'stop') {
1850
1911
  stdout.write(stopWebDaemon() ? t.webStopped + '\n' : t.webNotRunning + '\n');
1851
1912
  return;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @hmharness/cli - tui-mouse (2026-10-22; press-consumption fix 2026-10-24)
3
+ *
4
+ * SGR mouse tracking (DECSET 1000+1002+1006): the terminal reports
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.
13
+ *
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.
16
+ */
17
+ /** Enable mouse tracking: 1000 (press/release/wheel) + 1002 (drag) + 1006 (SGR). */
18
+ export declare const ENABLE_MOUSE = "\u001B[?1000h\u001B[?1002h\u001B[?1006h";
19
+ /** Disable all mouse tracking modes. */
20
+ export declare const DISABLE_MOUSE = "\u001B[?1006l\u001B[?1002l\u001B[?1000l";
21
+ export interface ParsedMouse {
22
+ kind: 'click' | 'wheel' | 'ignore';
23
+ col: number;
24
+ row: number;
25
+ wheelUp: boolean;
26
+ }
27
+ /**
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.
33
+ */
34
+ export declare function parseMouse(chunk: string): [ParsedMouse, string] | null;
35
+ /** True if the chunk LOOKS like the start of a mouse report (may be partial). */
36
+ export declare function isMousePrefix(chunk: string): boolean;
37
+ export interface ClickRegion {
38
+ row: number;
39
+ colStart: number;
40
+ colEnd: number;
41
+ fn: () => void;
42
+ /** higher z wins when regions overlap (later registrations = drawn on top) */
43
+ z: number;
44
+ }
45
+ /** Clear the registry — call at the START of each render frame. */
46
+ export declare function clearRegions(): void;
47
+ /**
48
+ * Register a clickable region. The renderer calls this while drawing each
49
+ * interactive element; z-order follows registration order (later = on top).
50
+ */
51
+ export declare function addClickRegion(row: number, colStart: number, colEnd: number, fn: () => void): void;
52
+ /**
53
+ * Dispatch a click at terminal (col, row). The highest-z region containing
54
+ * the point wins; returns true if any region consumed the click.
55
+ */
56
+ export declare function dispatchClick(col: number, row: number): boolean;
57
+ /** Test helper: current region count. */
58
+ export declare function regionCount(): number;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @hmharness/cli - tui-mouse (2026-10-22; press-consumption fix 2026-10-24)
3
+ *
4
+ * SGR mouse tracking (DECSET 1000+1002+1006): the terminal reports
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.
13
+ *
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.
16
+ */
17
+ /** Enable mouse tracking: 1000 (press/release/wheel) + 1002 (drag) + 1006 (SGR). */
18
+ export const ENABLE_MOUSE = '\x1b[?1000h\x1b[?1002h\x1b[?1006h';
19
+ /** Disable all mouse tracking modes. */
20
+ export const DISABLE_MOUSE = '\x1b[?1006l\x1b[?1002l\x1b[?1000l';
21
+ /** SGR mouse report: ESC[<btn;col;rowM (press) / m (release). */
22
+ const SGR_MOUSE_RE = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])/;
23
+ /**
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.
29
+ */
30
+ export function parseMouse(chunk) {
31
+ const m = SGR_MOUSE_RE.exec(chunk);
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];
48
+ }
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];
64
+ }
65
+ return null;
66
+ }
67
+ /** True if the chunk LOOKS like the start of a mouse report (may be partial). */
68
+ export function isMousePrefix(chunk) {
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
72
+ }
73
+ let regions = [];
74
+ let zCounter = 0;
75
+ /** Clear the registry — call at the START of each render frame. */
76
+ export function clearRegions() {
77
+ regions = [];
78
+ zCounter = 0;
79
+ }
80
+ /**
81
+ * Register a clickable region. The renderer calls this while drawing each
82
+ * interactive element; z-order follows registration order (later = on top).
83
+ */
84
+ export function addClickRegion(row, colStart, colEnd, fn) {
85
+ regions.push({ row, colStart, colEnd, fn, z: zCounter++ });
86
+ }
87
+ /**
88
+ * Dispatch a click at terminal (col, row). The highest-z region containing
89
+ * the point wins; returns true if any region consumed the click.
90
+ */
91
+ export function dispatchClick(col, row) {
92
+ const hits = regions.filter((r) => r.row === row && col >= r.colStart && col <= r.colEnd);
93
+ if (hits.length === 0)
94
+ return false;
95
+ hits.sort((a, b) => b.z - a.z)[0].fn();
96
+ return true;
97
+ }
98
+ /** Test helper: current region count. */
99
+ export function regionCount() {
100
+ return regions.length;
101
+ }
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;
@@ -126,6 +136,8 @@ export declare class TuiRuntime {
126
136
  /** bracketed-paste accumulator: non-null while the 201~ end marker has
127
137
  * not arrived yet; everything buffered is literal insert-on-completion */
128
138
  private pasteBuf;
139
+ /** partial SGR mouse report held across stdin reads (ConPTY fragmentation) */
140
+ private mouseBuf;
129
141
  /** restores the console methods and process handlers captured by the
130
142
  * TUI's terminal ownership (see installConsoleRedirection) */
131
143
  private restoreConsole;
@@ -163,6 +175,27 @@ export declare class TuiRuntime {
163
175
  * the codex alt-screen picker contract. resolve fires on Enter (resume)
164
176
  * or Esc/Ctrl-C (close). */
165
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
+ };
166
199
  openResumePicker(): Promise<{
167
200
  kind: 'resume';
168
201
  row: SessionSummary;
@@ -176,6 +209,17 @@ export declare class TuiRuntime {
176
209
  /** Full-frame picker layout (codex draw_picker): title / search+toolbar /
177
210
  * list window / two hint lines / position footer. */
178
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;
179
223
  /** Ctrl+R history-search modal (B4): query line + matching entries,
180
224
  * newest first; Enter adopts, Esc closes, ^P/^N or arrows move. */
181
225
  private renderHistSearch;
@@ -286,6 +330,8 @@ export declare class TuiRuntime {
286
330
  private onKey;
287
331
  /** insert literal (sanitized paste) text at the caret - the same path
288
332
  * printable typing takes, so caret/history/palette side-effects match */
333
+ /** Mouse wheel drives the transcript scroll (same as arrow keys: 3 lines). */
334
+ private wheelScroll;
289
335
  private insertText;
290
336
  render(): void;
291
337
  private flushFrame;