@hmharness/cli 0.18.2 → 0.18.4
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 +33 -0
- package/dist/tui.d.ts +19 -0
- package/dist/tui.js +82 -5
- package/package.json +4 -4
package/dist/main.js
CHANGED
|
@@ -1622,6 +1622,39 @@ flags:
|
|
|
1622
1622
|
stdout.write('usage: hmh experiment [list|show <id>|run <id> [--cases=N]|promote <id> [--human]|rollback <target>]\n');
|
|
1623
1623
|
return;
|
|
1624
1624
|
}
|
|
1625
|
+
if (cmd === 'export') {
|
|
1626
|
+
// One-click export (2026-09-25, user request): session transcript -> a
|
|
1627
|
+
// single readable Markdown file. Shared builder with the web endpoint;
|
|
1628
|
+
// TUI exposes it as /export on the same session it is replaying.
|
|
1629
|
+
await initHome();
|
|
1630
|
+
const home = homeDir();
|
|
1631
|
+
let file = null;
|
|
1632
|
+
if (rest.includes('--last') || !arg)
|
|
1633
|
+
file = (await listSessions(home, { cwd: process.cwd(), limit: 1 })).items[0]?.file ?? null;
|
|
1634
|
+
else
|
|
1635
|
+
file = await latestSession(home, arg);
|
|
1636
|
+
if (!file) {
|
|
1637
|
+
stdout.write('没有可导出的会话——先使用 hmh 产生一次对话。\n');
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
const tr = await loadTranscript(file);
|
|
1641
|
+
if (!tr) {
|
|
1642
|
+
stdout.write('会话文件无法解析:' + file + '\n');
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
const { exportSessionMarkdown } = await import('@hmharness/kernel');
|
|
1646
|
+
const md = exportSessionMarkdown(tr);
|
|
1647
|
+
const dir = join(home, 'exports');
|
|
1648
|
+
const { mkdir } = await import('node:fs/promises');
|
|
1649
|
+
await mkdir(dir, { recursive: true });
|
|
1650
|
+
const name = (tr.id || 'session').replace(/[^a-zA-Z0-9_:.@-]/g, '') + '.md';
|
|
1651
|
+
const out = join(dir, name);
|
|
1652
|
+
const { writeFile } = await import('node:fs/promises');
|
|
1653
|
+
await writeFile(out, md, 'utf8');
|
|
1654
|
+
stdout.write(GREEN('✓') + ' 已导出 ' + tr.messages.length + ' 条消息 → ' + out + '\n');
|
|
1655
|
+
stdout.write(DIM('完整用户输入与回复都在文件里;工具输出超过 4000 字符自动截断。\n'));
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1625
1658
|
if (cmd === 'resume') {
|
|
1626
1659
|
await initHome();
|
|
1627
1660
|
const home = homeDir();
|
package/dist/tui.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type SessionSummary } from '@hmharness/kernel';
|
|
2
2
|
import { type Locale } from '@hmharness/agent';
|
|
3
|
+
interface Entry {
|
|
4
|
+
lines: string[];
|
|
5
|
+
}
|
|
3
6
|
/** desc keys index into Strings (agent i18n); matched by name at runtime. */
|
|
4
7
|
export declare const COMMANDS: Array<{
|
|
5
8
|
name: string;
|
|
@@ -243,6 +246,12 @@ export declare class TuiRuntime {
|
|
|
243
246
|
/** The user's own input, chat-style: separated by a blank line above and
|
|
244
247
|
* below, right-aligned to the terminal width so it reads as "the human
|
|
245
248
|
* side" against left-aligned model output. */
|
|
249
|
+
/** User input renders as a right-aligned chat bubble (2026-09-25 user
|
|
250
|
+
* feedback: folded long inputs "were not on the right"). The wrap width
|
|
251
|
+
* is 70% of the terminal (floor 40) - a full-width wrap made line 2+
|
|
252
|
+
* start at the left margin, which read as left-aligned text. The block
|
|
253
|
+
* always ENDS at the right edge either way; short prompts sit clearly
|
|
254
|
+
* on the right against left-aligned model output. */
|
|
246
255
|
addUser(text: string): void;
|
|
247
256
|
startStream(kind: 'think' | 'say'): ((chunk: string) => void) & {
|
|
248
257
|
drop: () => void;
|
|
@@ -286,6 +295,15 @@ export declare class TuiRuntime {
|
|
|
286
295
|
* LAST cell to its full output. */
|
|
287
296
|
addToolCell(folded: string, full: string): void;
|
|
288
297
|
toggleLastCell(): boolean;
|
|
298
|
+
/** In-progress tool call: ONE line that the result later REPLACES in
|
|
299
|
+
* place (2026-09-25 user request: consecutive tool calls used to cost
|
|
300
|
+
* two transcript lines each - the `● name args` line plus the folded
|
|
301
|
+
* `⎿ result` line - and a run of ten calls buried the conversation).
|
|
302
|
+
* Returns the mutable entry so settleToolCall() can swap it. */
|
|
303
|
+
startToolCall(display: string): Entry;
|
|
304
|
+
/** Fold a settled tool call onto its start line and register it as a
|
|
305
|
+
* z-expandable cell (same cell semantics as addToolCell). */
|
|
306
|
+
settleToolCall(entry: Entry, folded: string, full: string): void;
|
|
289
307
|
/** Light zero-dep markdown line color for STREAMED text: headings cyan,
|
|
290
308
|
* list markers dim, fences dim, blockquotes dim; everything else plain.
|
|
291
309
|
* Applied per completed line so already-stable rows never reflow. */
|
|
@@ -307,3 +325,4 @@ export declare class TuiRuntime {
|
|
|
307
325
|
export declare function tui(yes: boolean, noWeb?: boolean, opts?: {
|
|
308
326
|
resumeAtStart?: boolean;
|
|
309
327
|
}): Promise<void>;
|
|
328
|
+
export {};
|
package/dist/tui.js
CHANGED
|
@@ -112,6 +112,7 @@ export const COMMANDS = [
|
|
|
112
112
|
{ name: '/new', key: 'cmdNew' },
|
|
113
113
|
{ name: '/fork', key: 'cmdFork' },
|
|
114
114
|
{ name: '/copy', key: 'cmdCopy' },
|
|
115
|
+
{ name: '/export', key: 'cmdExport' },
|
|
115
116
|
{ name: '/mouse', key: 'cmdMouse' },
|
|
116
117
|
{ name: '/plan', key: 'cmdPlan' },
|
|
117
118
|
{ name: '/goal', key: 'cmdGoal' },
|
|
@@ -733,10 +734,17 @@ export class TuiRuntime {
|
|
|
733
734
|
/** The user's own input, chat-style: separated by a blank line above and
|
|
734
735
|
* below, right-aligned to the terminal width so it reads as "the human
|
|
735
736
|
* side" against left-aligned model output. */
|
|
737
|
+
/** User input renders as a right-aligned chat bubble (2026-09-25 user
|
|
738
|
+
* feedback: folded long inputs "were not on the right"). The wrap width
|
|
739
|
+
* is 70% of the terminal (floor 40) - a full-width wrap made line 2+
|
|
740
|
+
* start at the left margin, which read as left-aligned text. The block
|
|
741
|
+
* always ENDS at the right edge either way; short prompts sit clearly
|
|
742
|
+
* on the right against left-aligned model output. */
|
|
736
743
|
addUser(text) {
|
|
737
744
|
const width = Math.max(20, (stdout.columns || 100) - 2);
|
|
745
|
+
const blockW = Math.max(40, Math.floor(width * 0.7));
|
|
738
746
|
const lines = [''];
|
|
739
|
-
const wrapped = wrapTo(text.replace(/\n+/g, ' '),
|
|
747
|
+
const wrapped = wrapTo(text.replace(/\n+/g, ' '), blockW);
|
|
740
748
|
// long prompts fold to two lines + a count marker (UX requirement 2026-09-21:
|
|
741
749
|
// a pasted prompt used to eat half the screen); the driver archives the
|
|
742
750
|
// full text into the Ctrl+T replay so nothing is lost
|
|
@@ -983,6 +991,27 @@ export class TuiRuntime {
|
|
|
983
991
|
this.dirty = true;
|
|
984
992
|
return true;
|
|
985
993
|
}
|
|
994
|
+
/** In-progress tool call: ONE line that the result later REPLACES in
|
|
995
|
+
* place (2026-09-25 user request: consecutive tool calls used to cost
|
|
996
|
+
* two transcript lines each - the `● name args` line plus the folded
|
|
997
|
+
* `⎿ result` line - and a run of ten calls buried the conversation).
|
|
998
|
+
* Returns the mutable entry so settleToolCall() can swap it. */
|
|
999
|
+
startToolCall(display) {
|
|
1000
|
+
const width = Math.max(20, (stdout.columns || 100) - 2);
|
|
1001
|
+
const entry = { lines: wrapTo(display, width) };
|
|
1002
|
+
this.entries.push(entry);
|
|
1003
|
+
this.scrollFromBottom = 0;
|
|
1004
|
+
this.dirty = true;
|
|
1005
|
+
return entry;
|
|
1006
|
+
}
|
|
1007
|
+
/** Fold a settled tool call onto its start line and register it as a
|
|
1008
|
+
* z-expandable cell (same cell semantics as addToolCell). */
|
|
1009
|
+
settleToolCall(entry, folded, full) {
|
|
1010
|
+
const width = Math.max(20, (stdout.columns || 100) - 2);
|
|
1011
|
+
entry.lines = wrapTo(folded, width).map((l) => DIM(l));
|
|
1012
|
+
this.toolCells.push({ entry, full, folded, expanded: false });
|
|
1013
|
+
this.dirty = true;
|
|
1014
|
+
}
|
|
986
1015
|
/* ---------------- M4: streaming markdown colorizer (B10) ---------------- */
|
|
987
1016
|
/** Light zero-dep markdown line color for STREAMED text: headings cyan,
|
|
988
1017
|
* list markers dim, fences dim, blockquotes dim; everything else plain.
|
|
@@ -2024,6 +2053,10 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2024
2053
|
fullToolLog.push({ name: 'thinking', output: reasoningBuf.slice(0, 8000) });
|
|
2025
2054
|
} reasoningBuf = ''; rt.foldThinking(); };
|
|
2026
2055
|
let kind = null;
|
|
2056
|
+
// the in-flight tool call's transcript entry: the result REPLACES it
|
|
2057
|
+
// in place (one line per call, 2026-09-25)
|
|
2058
|
+
let pendingToolEntry = null;
|
|
2059
|
+
let pendingToolName = null;
|
|
2027
2060
|
try {
|
|
2028
2061
|
const result = await runAgentTask({
|
|
2029
2062
|
task: line,
|
|
@@ -2068,14 +2101,24 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2068
2101
|
const brief = name === 'run_command' && typeof args.command === 'string'
|
|
2069
2102
|
? args.command
|
|
2070
2103
|
: JSON.stringify(args);
|
|
2071
|
-
|
|
2104
|
+
// ONE line per call (2026-09-25): the running `● name args` line
|
|
2105
|
+
// is REPLACED in place by the folded result line on settle, so a
|
|
2106
|
+
// run of N calls costs N transcript lines, not 2N
|
|
2107
|
+
pendingToolEntry = rt.startToolCall(`${YELLOW('●')} ${CYAN(name)} ${DIM(brief.replace(/\s+/g, ' ').slice(0, 90))}`);
|
|
2108
|
+
pendingToolName = name;
|
|
2072
2109
|
},
|
|
2073
2110
|
onToolResult: (name, output, isError) => {
|
|
2074
2111
|
const dot = isError ? RED('✗') : GREEN('•');
|
|
2075
2112
|
const first = output.split('\n').find((l) => l.trim()) ?? '';
|
|
2076
|
-
// M4 B8:
|
|
2077
|
-
//
|
|
2078
|
-
|
|
2113
|
+
// M4 B8 + 2026-09-25: the call line settles INTO the folded cell
|
|
2114
|
+
// (one line per call; `z` with an empty input expands the last)
|
|
2115
|
+
const folded = ` ${dot} ${CYAN(name)} ${DIM('⎿ ' + first.trim().slice(0, 100))}`;
|
|
2116
|
+
if (pendingToolEntry && pendingToolName === name)
|
|
2117
|
+
rt.settleToolCall(pendingToolEntry, folded, output);
|
|
2118
|
+
else
|
|
2119
|
+
rt.addToolCell(folded, output);
|
|
2120
|
+
pendingToolEntry = null;
|
|
2121
|
+
pendingToolName = null;
|
|
2079
2122
|
// M4 B9 (T18 复案 2026-09-21): outputs beyond a screen NO LONGER
|
|
2080
2123
|
// auto-open the full-screen pager - on every system it read as a
|
|
2081
2124
|
// break-in (a wall of raw output hijacking the screen while the
|
|
@@ -2288,6 +2331,40 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2288
2331
|
rt.addText('(clipboard tool unavailable — output follows)\n' + lastAiText.slice(0, 2000), 'dim');
|
|
2289
2332
|
return;
|
|
2290
2333
|
}
|
|
2334
|
+
if (line === '/export') {
|
|
2335
|
+
// One-click export (2026-09-25): the CURRENT session (replayed or
|
|
2336
|
+
// fresh) becomes one Markdown file under ~/.hmharness/exports -
|
|
2337
|
+
// full user inputs and replies, folded tool output. Same builder as
|
|
2338
|
+
// `hmh export` and the web session view's download button.
|
|
2339
|
+
try {
|
|
2340
|
+
const { homeDir, findSessionFile, loadTranscript, exportSessionMarkdown } = await import('@hmharness/kernel');
|
|
2341
|
+
const home = homeDir();
|
|
2342
|
+
const sid = currentSessionId;
|
|
2343
|
+
const K = await import('@hmharness/kernel');
|
|
2344
|
+
const file = sid ? await findSessionFile(home, sid) : await K.latestSession(home, '');
|
|
2345
|
+
if (!file) {
|
|
2346
|
+
rt.addText('还没有可导出的会话内容。', 'dim');
|
|
2347
|
+
return;
|
|
2348
|
+
}
|
|
2349
|
+
const tr = await loadTranscript(file);
|
|
2350
|
+
if (!tr) {
|
|
2351
|
+
rt.addText('会话文件无法解析,稍后再试。', 'dim');
|
|
2352
|
+
return;
|
|
2353
|
+
}
|
|
2354
|
+
const md = exportSessionMarkdown(tr);
|
|
2355
|
+
const { mkdir, writeFile } = await import('node:fs/promises');
|
|
2356
|
+
const { join } = await import('node:path');
|
|
2357
|
+
const dir = join(home, 'exports');
|
|
2358
|
+
await mkdir(dir, { recursive: true });
|
|
2359
|
+
const out = join(dir, ((tr.id || 'session').replace(/[^a-zA-Z0-9_:.@-]/g, '')) + '.md');
|
|
2360
|
+
await writeFile(out, md, 'utf8');
|
|
2361
|
+
rt.addText(GREEN('✓') + ' 会话已导出(' + tr.messages.length + ' 条消息)→ ' + out, 'plain');
|
|
2362
|
+
}
|
|
2363
|
+
catch (err) {
|
|
2364
|
+
rt.addText('导出失败:' + String(err).slice(0, 120), 'dim');
|
|
2365
|
+
}
|
|
2366
|
+
return;
|
|
2367
|
+
}
|
|
2291
2368
|
if (line === '/mouse') {
|
|
2292
2369
|
// T23: full-time capture toggle for terminals without wheel
|
|
2293
2370
|
// translation (?1007 already covers the wheel on mainstream ones);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.4",
|
|
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",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"build": "tsc -p tsconfig.build.json"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@hmharness/kernel": "0.9.
|
|
46
|
+
"@hmharness/kernel": "0.9.7",
|
|
47
47
|
"@hmharness/observability": "0.7.4",
|
|
48
48
|
"@hmharness/evolution": "0.14.25",
|
|
49
49
|
"@hmharness/domain-harmony": "0.13.8",
|
|
50
50
|
"@hmharness/domain-ops": "0.8.3",
|
|
51
|
-
"@hmharness/agent": "0.14.
|
|
51
|
+
"@hmharness/agent": "0.14.19",
|
|
52
52
|
"@hmharness/evaluation": "0.8.6",
|
|
53
|
-
"@hmharness/web": "0.9.
|
|
53
|
+
"@hmharness/web": "0.9.6",
|
|
54
54
|
"@hmharness/sandbox": "0.8.5"
|
|
55
55
|
}
|
|
56
56
|
}
|