@hmharness/cli 0.18.1 → 0.18.3
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 +66 -36
- package/dist/tui.d.ts +6 -0
- package/dist/tui.js +43 -1
- package/package.json +5 -5
package/dist/main.js
CHANGED
|
@@ -36,16 +36,10 @@ const CYAN = (s) => `\x1b[36m${s}\x1b[0m`;
|
|
|
36
36
|
const YELLOW = (s) => `\x1b[33m${s}\x1b[0m`;
|
|
37
37
|
const GREEN = (s) => `\x1b[32m${s}\x1b[0m`;
|
|
38
38
|
const RED = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
for (const p of Object.values(cfg.providers ?? {})) {
|
|
44
|
-
if (p.baseUrl?.includes('bigmodel.cn') && p.apiKey)
|
|
45
|
-
return { apiKey: p.apiKey, baseUrl: p.baseUrl, model: p.model };
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
39
|
+
/** Fine-tuning is provider-agnostic (helper deleted 2026-09-25): the
|
|
40
|
+
* auto-finetune command resolves the backend from the user's configured
|
|
41
|
+
* providers via CF.resolveFineTuneBackend - chat route first. Zhipu is one
|
|
42
|
+
* supported dialect, not a design target. */
|
|
49
43
|
async function uiStrings() {
|
|
50
44
|
const cfg = await loadConfig();
|
|
51
45
|
return strings((cfg.locale ?? 'zh'));
|
|
@@ -1025,25 +1019,28 @@ flags:
|
|
|
1025
1019
|
return;
|
|
1026
1020
|
}
|
|
1027
1021
|
if (cmd === 'auto-finetune') {
|
|
1028
|
-
// 2026-09-25: the cloud fine-tuning loop is CLOSED
|
|
1029
|
-
// the accumulated DPO pairs, converts them to the
|
|
1030
|
-
// format and uploads train/validation files (free)
|
|
1031
|
-
// staged for one-command submission. Job creation
|
|
1032
|
-
// --submit. The user never
|
|
1022
|
+
// 2026-09-25: the cloud fine-tuning loop is CLOSED and PROVIDER-AGNOSTIC.
|
|
1023
|
+
// Default run exports the accumulated DPO pairs, converts them to the
|
|
1024
|
+
// matched backend's row format and uploads train/validation files (free)
|
|
1025
|
+
// - everything is then staged for one-command submission. Job creation
|
|
1026
|
+
// is PAID, so it needs --submit. The user never picks a provider, model
|
|
1027
|
+
// or local GPU stack: the chat-route provider is matched against the
|
|
1028
|
+
// backend registry automatically (Zhipu is one dialect, not the design).
|
|
1033
1029
|
await initHome();
|
|
1034
1030
|
const home = homeDir();
|
|
1035
1031
|
const CF = await import('@hmharness/evolution');
|
|
1036
1032
|
const flag = (name) => (rest.find((a) => a.startsWith(`--${name}=`)) ?? '').split('=').slice(1).join('=');
|
|
1033
|
+
const supportedList = CF.FINE_TUNE_BACKENDS.map((b) => b.label).join('、');
|
|
1034
|
+
const cfgFT = await loadConfig();
|
|
1035
|
+
const ft = CF.resolveFineTuneBackend(cfgFT.providers, cfgFT.routing?.chat);
|
|
1037
1036
|
if (rest.includes('--status')) {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
if (!zp) {
|
|
1041
|
-
stdout.write(RED('未找到智谱 provider(config.json providers 中需有 baseUrl 含 bigmodel.cn 的条目,如 glm)\n'));
|
|
1037
|
+
if (!ft) {
|
|
1038
|
+
stdout.write('云端微调:你当前配置的模型供应商暂不支持微调(已支持:' + supportedList + ')。其余功能不受影响。\n');
|
|
1042
1039
|
return;
|
|
1043
1040
|
}
|
|
1044
|
-
const jobs = await CF.listFineTuneJobs({ apiKey:
|
|
1041
|
+
const jobs = await CF.listFineTuneJobs({ backend: ft.backend, apiKey: ft.apiKey, baseUrl: ft.baseUrl, limit: 10 });
|
|
1045
1042
|
const local = await CF.readLocalFineTuneJobs(home);
|
|
1046
|
-
stdout.write('
|
|
1043
|
+
stdout.write('云端微调任务(' + ft.backend.label + ',最近 ' + jobs.length + ' 条):\n');
|
|
1047
1044
|
for (const j of jobs)
|
|
1048
1045
|
stdout.write(' ' + (j.id ?? '?').padEnd(38) + ' ' + String(j.status ?? '?').padEnd(12) + ' ' + String(j.model ?? '') + (j.fine_tuned_model ? ' → ' + j.fine_tuned_model : '') + '\n');
|
|
1049
1046
|
if (local.length) {
|
|
@@ -1055,13 +1052,13 @@ flags:
|
|
|
1055
1052
|
stdout.write('(还没有任何微调任务)\n');
|
|
1056
1053
|
return;
|
|
1057
1054
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
stdout.write(RED('未找到智谱 provider:请在 config.json 的 providers 里配置 glm(baseUrl 含 bigmodel.cn)。只需这一个密钥。\n'));
|
|
1055
|
+
if (!ft) {
|
|
1056
|
+
// a clean STATUS, never an error: unsupported provider is normal life
|
|
1057
|
+
stdout.write('云端微调暂未对你当前配置的模型供应商开放(已支持:' + supportedList + ')。\n');
|
|
1058
|
+
stdout.write(DIM('继续正常使用即可——评审、进化等其他能力照常工作;后续版本会接入更多微调后端。\n'));
|
|
1063
1059
|
return;
|
|
1064
1060
|
}
|
|
1061
|
+
stdout.write('微调后端:' + ft.backend.label + '(provider ' + ft.providerName + ')\n');
|
|
1065
1062
|
// unattended safety rails (2026-09-25 "configure one key, forget it"):
|
|
1066
1063
|
// kill-switch finetune.auto=false, at most one active cloud job, and a
|
|
1067
1064
|
// cooldown between submissions - the daemon calls this same command, so
|
|
@@ -1083,7 +1080,7 @@ flags:
|
|
|
1083
1080
|
return;
|
|
1084
1081
|
}
|
|
1085
1082
|
try {
|
|
1086
|
-
const running = (await CF.listFineTuneJobs({ apiKey:
|
|
1083
|
+
const running = (await CF.listFineTuneJobs({ backend: ft.backend, apiKey: ft.apiKey, baseUrl: ft.baseUrl, limit: 20 }))
|
|
1087
1084
|
.some((j) => ['queued', 'running', 'pending', 'training'].includes(String(j.status ?? '').toLowerCase()));
|
|
1088
1085
|
if (running) {
|
|
1089
1086
|
stdout.write(DIM('云端已有进行中的微调任务——本次跳过\n'));
|
|
@@ -1093,8 +1090,8 @@ flags:
|
|
|
1093
1090
|
catch { /* status check failed - fail open to the gates below */ }
|
|
1094
1091
|
}
|
|
1095
1092
|
// 2026-09-25 user call: novices never pick a fine-tune base. Try the
|
|
1096
|
-
// user's MAIN model first (glm-5.3
|
|
1097
|
-
// silently fall down the
|
|
1093
|
+
// user's MAIN model first (on this account glm-5.3 answers 微调功能未开放),
|
|
1094
|
+
// then silently fall down the backend's ladder. --model= stays as override.
|
|
1098
1095
|
const forced = flag('model');
|
|
1099
1096
|
let model;
|
|
1100
1097
|
if (forced) {
|
|
@@ -1103,10 +1100,10 @@ flags:
|
|
|
1103
1100
|
}
|
|
1104
1101
|
else {
|
|
1105
1102
|
model = await CF.pickFineTuneModel({
|
|
1106
|
-
apiKey:
|
|
1103
|
+
backend: ft.backend, apiKey: ft.apiKey, baseUrl: ft.baseUrl, mainModel: ft.model,
|
|
1107
1104
|
log: (l) => stdout.write(DIM(l + '\n')),
|
|
1108
1105
|
});
|
|
1109
|
-
stdout.write('云端微调模型:' + model + (model !==
|
|
1106
|
+
stdout.write('云端微调模型:' + model + (model !== ft.model ? DIM('(主模型 ' + ft.model + ' 暂不可微调,已自动改用)') : '') + '\n');
|
|
1110
1107
|
}
|
|
1111
1108
|
// labels gate (same as before)
|
|
1112
1109
|
const judgeLabels = await CF.readJudgeLabels(home);
|
|
@@ -1139,18 +1136,18 @@ flags:
|
|
|
1139
1136
|
const trainRows = rows.filter((r) => r.split !== 'eval').slice(0, maxPairs);
|
|
1140
1137
|
const evalRows = rows.filter((r) => r.split === 'eval').slice(0, 1000); // validation loss needs a sample, not the whole set
|
|
1141
1138
|
stdout.write('偏好对:' + rows.length + (trainRows.length < rows.filter((r) => r.split !== 'eval').length ? DIM('(本次训练用前 ' + maxPairs + ' 条控制成本)') : '') + '(train ' + trainRows.length + ' / eval ' + evalRows.length + (evalRows.length < rows.filter((r) => r.split === 'eval').length ? DIM('(抽样 1000)') : '') + ')\n');
|
|
1142
|
-
const trainJsonl =
|
|
1143
|
-
const evalJsonl =
|
|
1139
|
+
const trainJsonl = ft.backend.dpoJsonl(trainRows);
|
|
1140
|
+
const evalJsonl = ft.backend.dpoJsonl(evalRows);
|
|
1144
1141
|
stdout.write('本地预估 token:train ~' + CF.estimateTokens(trainJsonl).toLocaleString() + ' / eval ~' + CF.estimateTokens(evalJsonl).toLocaleString() + DIM('(上传后以官方分词统计为准)') + '\n');
|
|
1145
1142
|
// upload (free) - provider token stats come back exact
|
|
1146
1143
|
const stamp = new Date().toISOString().slice(0, 10).replaceAll('-', '');
|
|
1147
1144
|
let upTrain;
|
|
1148
1145
|
let upEval = null;
|
|
1149
1146
|
try {
|
|
1150
|
-
upTrain = await CF.uploadFineTuneFile({ apiKey:
|
|
1147
|
+
upTrain = await CF.uploadFineTuneFile({ backend: ft.backend, apiKey: ft.apiKey, baseUrl: ft.baseUrl, filename: `hmh-dpo-train-${stamp}.jsonl`, jsonl: trainJsonl });
|
|
1151
1148
|
stdout.write(GREEN('✓') + ' 训练文件已上传:' + upTrain.id + '(' + upTrain.samples + ' 样本,官方统计 ' + upTrain.tokens.toLocaleString() + ' tokens)\n');
|
|
1152
1149
|
if (evalRows.length) {
|
|
1153
|
-
upEval = await CF.uploadFineTuneFile({ apiKey:
|
|
1150
|
+
upEval = await CF.uploadFineTuneFile({ backend: ft.backend, apiKey: ft.apiKey, baseUrl: ft.baseUrl, filename: `hmh-dpo-eval-${stamp}.jsonl`, jsonl: evalJsonl });
|
|
1154
1151
|
stdout.write(GREEN('✓') + ' 验证文件已上传:' + upEval.id + '(' + upEval.samples + ' 样本)\n');
|
|
1155
1152
|
}
|
|
1156
1153
|
}
|
|
@@ -1168,7 +1165,7 @@ flags:
|
|
|
1168
1165
|
// PAID step - explicit --submit only
|
|
1169
1166
|
try {
|
|
1170
1167
|
const job = await CF.createFineTuneJob({
|
|
1171
|
-
apiKey:
|
|
1168
|
+
backend: ft.backend, apiKey: ft.apiKey, baseUrl: ft.baseUrl, model,
|
|
1172
1169
|
trainingFile: upTrain.id, validationFile: upEval?.id, suffix: 'hmh',
|
|
1173
1170
|
});
|
|
1174
1171
|
await CF.recordFineTuneJob(home, job, { model, trainFile: upTrain.id, evalFile: upEval?.id, pairs: rows.length });
|
|
@@ -1625,6 +1622,39 @@ flags:
|
|
|
1625
1622
|
stdout.write('usage: hmh experiment [list|show <id>|run <id> [--cases=N]|promote <id> [--human]|rollback <target>]\n');
|
|
1626
1623
|
return;
|
|
1627
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
|
+
}
|
|
1628
1658
|
if (cmd === 'resume') {
|
|
1629
1659
|
await initHome();
|
|
1630
1660
|
const home = homeDir();
|
package/dist/tui.d.ts
CHANGED
|
@@ -243,6 +243,12 @@ export declare class TuiRuntime {
|
|
|
243
243
|
/** The user's own input, chat-style: separated by a blank line above and
|
|
244
244
|
* below, right-aligned to the terminal width so it reads as "the human
|
|
245
245
|
* side" against left-aligned model output. */
|
|
246
|
+
/** User input renders as a right-aligned chat bubble (2026-09-25 user
|
|
247
|
+
* feedback: folded long inputs "were not on the right"). The wrap width
|
|
248
|
+
* is 70% of the terminal (floor 40) - a full-width wrap made line 2+
|
|
249
|
+
* start at the left margin, which read as left-aligned text. The block
|
|
250
|
+
* always ENDS at the right edge either way; short prompts sit clearly
|
|
251
|
+
* on the right against left-aligned model output. */
|
|
246
252
|
addUser(text: string): void;
|
|
247
253
|
startStream(kind: 'think' | 'say'): ((chunk: string) => void) & {
|
|
248
254
|
drop: () => void;
|
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
|
|
@@ -2288,6 +2296,40 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2288
2296
|
rt.addText('(clipboard tool unavailable — output follows)\n' + lastAiText.slice(0, 2000), 'dim');
|
|
2289
2297
|
return;
|
|
2290
2298
|
}
|
|
2299
|
+
if (line === '/export') {
|
|
2300
|
+
// One-click export (2026-09-25): the CURRENT session (replayed or
|
|
2301
|
+
// fresh) becomes one Markdown file under ~/.hmharness/exports -
|
|
2302
|
+
// full user inputs and replies, folded tool output. Same builder as
|
|
2303
|
+
// `hmh export` and the web session view's download button.
|
|
2304
|
+
try {
|
|
2305
|
+
const { homeDir, findSessionFile, loadTranscript, exportSessionMarkdown } = await import('@hmharness/kernel');
|
|
2306
|
+
const home = homeDir();
|
|
2307
|
+
const sid = currentSessionId;
|
|
2308
|
+
const K = await import('@hmharness/kernel');
|
|
2309
|
+
const file = sid ? await findSessionFile(home, sid) : await K.latestSession(home, '');
|
|
2310
|
+
if (!file) {
|
|
2311
|
+
rt.addText('还没有可导出的会话内容。', 'dim');
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
const tr = await loadTranscript(file);
|
|
2315
|
+
if (!tr) {
|
|
2316
|
+
rt.addText('会话文件无法解析,稍后再试。', 'dim');
|
|
2317
|
+
return;
|
|
2318
|
+
}
|
|
2319
|
+
const md = exportSessionMarkdown(tr);
|
|
2320
|
+
const { mkdir, writeFile } = await import('node:fs/promises');
|
|
2321
|
+
const { join } = await import('node:path');
|
|
2322
|
+
const dir = join(home, 'exports');
|
|
2323
|
+
await mkdir(dir, { recursive: true });
|
|
2324
|
+
const out = join(dir, ((tr.id || 'session').replace(/[^a-zA-Z0-9_:.@-]/g, '')) + '.md');
|
|
2325
|
+
await writeFile(out, md, 'utf8');
|
|
2326
|
+
rt.addText(GREEN('✓') + ' 会话已导出(' + tr.messages.length + ' 条消息)→ ' + out, 'plain');
|
|
2327
|
+
}
|
|
2328
|
+
catch (err) {
|
|
2329
|
+
rt.addText('导出失败:' + String(err).slice(0, 120), 'dim');
|
|
2330
|
+
}
|
|
2331
|
+
return;
|
|
2332
|
+
}
|
|
2291
2333
|
if (line === '/mouse') {
|
|
2292
2334
|
// T23: full-time capture toggle for terminals without wheel
|
|
2293
2335
|
// 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.3",
|
|
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
|
-
"@hmharness/evolution": "0.14.
|
|
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.5",
|
|
54
54
|
"@hmharness/sandbox": "0.8.5"
|
|
55
55
|
}
|
|
56
56
|
}
|