@hmharness/cli 0.23.9 → 0.23.11
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 +264 -0
- package/dist/tui-state.d.ts +13 -0
- package/dist/tui-state.js +47 -0
- package/dist/tui.js +61 -3
- package/dist/update-check.d.ts +37 -13
- package/dist/update-check.js +56 -8
- package/package.json +14 -13
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// install-kaihongos.cjs — one-command board installer for @hmharness/cli on
|
|
3
|
+
// TWIN COPY: scripts/install-kaihongos.cjs (repo installs) and
|
|
4
|
+
// packages/cli/board/install-kaihongos.cjs (ships in the npm package - the
|
|
5
|
+
// board auto-update channel runs THIS one, settled design T28). Keep both
|
|
6
|
+
// in sync when bumping FALLBACK_PINS.
|
|
7
|
+
// KaihongOS / OpenHarmony 5.0 boards (no npm, no Python, read-only rootfs).
|
|
8
|
+
//
|
|
9
|
+
// What it does (idempotent, re-run any time):
|
|
10
|
+
// 1. locates a usable Node >= 22 (the running one, or known board paths)
|
|
11
|
+
// 2. resolves the @hmharness/* version set from registry.npmjs.org
|
|
12
|
+
// (offline fallback: known-good pins below)
|
|
13
|
+
// 3. downloads the 10 first-party tarballs and unpacks them under
|
|
14
|
+
// <BOARD_HOME>/.local/hmharness/node_modules (staged, verified, swapped)
|
|
15
|
+
// 4. writes a hardened launcher and installs it into THREE locations:
|
|
16
|
+
// <BOARD_HOME>/.local/bin/hmh (user path, always writable)
|
|
17
|
+
// /usr/local/bin/hmh (default PATH on classic shells)
|
|
18
|
+
// /system/bin/hmh (read-only rootfs, remount dance;
|
|
19
|
+
// ALSO visible inside isolated
|
|
20
|
+
// tmpfs mount-namespace terminals
|
|
21
|
+
// where /bin -> /system/bin)
|
|
22
|
+
// 5. first run: `hmh init` if config.json is missing
|
|
23
|
+
//
|
|
24
|
+
// Usage:
|
|
25
|
+
// node install-kaihongos.cjs # install/upgrade to latest
|
|
26
|
+
// node install-kaihongos.cjs --bin-only # only (re)write launchers
|
|
27
|
+
// node install-kaihongos.cjs --home=/x # non-default board home
|
|
28
|
+
//
|
|
29
|
+
// Only Node core modules are used; tar extraction uses busybox tar.
|
|
30
|
+
const fs = require('fs');
|
|
31
|
+
const path = require('path');
|
|
32
|
+
const https = require('https');
|
|
33
|
+
const { spawnSync } = require('child_process');
|
|
34
|
+
|
|
35
|
+
// ---------- board constants -------------------------------------------------
|
|
36
|
+
let BOARD_HOME = '/data/local/home'; // KaihongOS board home
|
|
37
|
+
let BIN_ONLY = false;
|
|
38
|
+
|
|
39
|
+
for (const a of process.argv.slice(2)) {
|
|
40
|
+
if (a.startsWith('--home=')) BOARD_HOME = a.slice(7);
|
|
41
|
+
else if (a === '--bin-only') BIN_ONLY = true;
|
|
42
|
+
else { console.error('unknown arg:', a); process.exit(2); }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const ROOT = path.join(BOARD_HOME, '.local', 'hmharness');
|
|
46
|
+
const NM = path.join(ROOT, 'node_modules');
|
|
47
|
+
const HMH_HOME = path.join(BOARD_HOME, '.hmharness');
|
|
48
|
+
const REG = 'https://registry.npmjs.org';
|
|
49
|
+
const PACKAGES = ['cli', 'web', 'agent', 'kernel', 'sandbox', 'evolution',
|
|
50
|
+
'domain-ops', 'evaluation', 'observability', 'domain-harmony'];
|
|
51
|
+
|
|
52
|
+
// Known-good pin set (offline fallback when the registry is unreachable).
|
|
53
|
+
const FALLBACK_PINS = {
|
|
54
|
+
cli: '0.23.10', web: '0.23.10', agent: '0.23.10', kernel: '0.23.10',
|
|
55
|
+
sandbox: '0.23.10', evolution: '0.23.10', 'domain-ops': '0.23.10',
|
|
56
|
+
evaluation: '0.23.10', observability: '0.23.10', 'domain-harmony': '0.23.10',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// ---------- helpers ---------------------------------------------------------
|
|
60
|
+
function log(msg) { console.log(msg); }
|
|
61
|
+
|
|
62
|
+
function httpsJSON(url, timeoutMs) {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const req = https.request(new URL(url), { headers: { 'User-Agent': 'hmh-kaihongos-installer' }, timeout: timeoutMs || 20000 }, (res) => {
|
|
65
|
+
if (res.statusCode !== 200) { res.resume(); reject(new Error(url + ' -> ' + res.statusCode)); return; }
|
|
66
|
+
const chunks = [];
|
|
67
|
+
res.on('data', (c) => chunks.push(c));
|
|
68
|
+
res.on('end', () => { try { resolve(JSON.parse(Buffer.concat(chunks).toString('utf8'))); } catch (e) { reject(e); } });
|
|
69
|
+
});
|
|
70
|
+
req.on('timeout', () => { req.destroy(new Error('timeout')); });
|
|
71
|
+
req.on('error', reject);
|
|
72
|
+
req.end();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function download(url, file) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
let attempt = 0;
|
|
79
|
+
function go() {
|
|
80
|
+
attempt++;
|
|
81
|
+
const req = https.request(new URL(url), { headers: { 'User-Agent': 'hmh-kaihongos-installer' }, timeout: 30000 }, (res) => {
|
|
82
|
+
if (res.statusCode !== 200) { res.resume(); reject(new Error(url + ' -> ' + res.statusCode)); return; }
|
|
83
|
+
const out = fs.createWriteStream(file);
|
|
84
|
+
res.pipe(out);
|
|
85
|
+
out.on('finish', () => out.close(resolve));
|
|
86
|
+
out.on('error', reject);
|
|
87
|
+
});
|
|
88
|
+
req.on('timeout', () => { req.destroy(); retry(); });
|
|
89
|
+
req.on('error', (e) => {
|
|
90
|
+
if (attempt < 10 && /EAI_AGAIN|ENOTFOUND|ECONNRESET|ETIMEDOUT/.test(e.code || '')) setTimeout(retry, 1500 * attempt);
|
|
91
|
+
else reject(e);
|
|
92
|
+
});
|
|
93
|
+
req.end();
|
|
94
|
+
}
|
|
95
|
+
function retry() { if (attempt < 10) go(); else reject(new Error('retries exhausted: ' + url)); }
|
|
96
|
+
go();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function extract(tgz, dest) {
|
|
101
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
102
|
+
// busybox tar is present on KaihongOS / OpenHarmony boards and understands
|
|
103
|
+
// --strip-components. (GNU/toybox tar also fine if busybox is missing.)
|
|
104
|
+
const cmds = [
|
|
105
|
+
['busybox', ['tar', '-xzf', tgz, '-C', dest, '--strip-components=1']],
|
|
106
|
+
['tar', ['-xzf', tgz, '-C', dest, '--strip-components=1']],
|
|
107
|
+
];
|
|
108
|
+
for (const [bin, args] of cmds) {
|
|
109
|
+
const r = spawnSync(bin, args, { encoding: 'utf8' });
|
|
110
|
+
if (r.status === 0) return;
|
|
111
|
+
if (r.error && r.error.code !== 'ENOENT') log(' warn: ' + bin + ' tar: ' + (r.stderr || r.error.message).slice(0, 120));
|
|
112
|
+
}
|
|
113
|
+
throw new Error('no usable tar (tried busybox tar, tar)');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function resolveVersions() {
|
|
117
|
+
log('resolving latest @hmharness/cli from registry ...');
|
|
118
|
+
const meta = await httpsJSON(REG + '/@hmharness/cli');
|
|
119
|
+
const cliLatest = meta['dist-tags'].latest;
|
|
120
|
+
const deps = (meta.versions[cliLatest].dependencies) || {};
|
|
121
|
+
const pins = { cli: cliLatest };
|
|
122
|
+
for (const n of PACKAGES.slice(1)) {
|
|
123
|
+
const want = deps['@hmharness/' + n];
|
|
124
|
+
if (want && want !== '*') { pins[n] = want.replace(/[^0-9.]/g, ''); continue; }
|
|
125
|
+
const m = await httpsJSON(REG + '/@hmharness/' + n);
|
|
126
|
+
pins[n] = m['dist-tags'].latest;
|
|
127
|
+
}
|
|
128
|
+
return pins;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---------- node discovery --------------------------------------------------
|
|
132
|
+
function findNode() {
|
|
133
|
+
const cands = [process.execPath,
|
|
134
|
+
path.join(BOARD_HOME, 'dsh-pack/node/bin/node'),
|
|
135
|
+
path.join(BOARD_HOME, '.ohos/node/bin/node'),
|
|
136
|
+
'/usr/local/bin/node', '/usr/bin/node', '/system/bin/node'];
|
|
137
|
+
for (const c of cands) {
|
|
138
|
+
try {
|
|
139
|
+
fs.accessSync(c, fs.constants.X_OK);
|
|
140
|
+
const v = spawnSync(c, ['--version'], { encoding: 'utf8' });
|
|
141
|
+
if (v.status === 0) { const maj = parseInt((v.stdout || '').replace('v', ''), 10); if (maj >= 22) return c; }
|
|
142
|
+
} catch (_) { /* next */ }
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ---------- launcher --------------------------------------------------------
|
|
148
|
+
function launcherSource(nodeBin) {
|
|
149
|
+
return [
|
|
150
|
+
'#!/system/bin/sh',
|
|
151
|
+
'# hmh launcher — KaihongOS board install (generated by install-kaihongos.cjs)',
|
|
152
|
+
'# Board layout is fixed under ' + BOARD_HOME + ', independent of caller HOME/PATH.',
|
|
153
|
+
'HROOT="' + ROOT + '"',
|
|
154
|
+
'HNODE="' + nodeBin + '"',
|
|
155
|
+
'[ -x "$HNODE" ] || for c in node ' + BOARD_HOME + '/dsh-pack/node/bin/node ' + BOARD_HOME + '/.ohos/node/bin/node; do',
|
|
156
|
+
' [ -x "$c" ] && HNODE="$c" && break',
|
|
157
|
+
'done',
|
|
158
|
+
'# optional board-wide secrets file (edit or remove — keys normally live in config.json)',
|
|
159
|
+
'[ -f ' + BOARD_HOME + '/.config/apikeys.env ] && . ' + BOARD_HOME + '/.config/apikeys.env',
|
|
160
|
+
'# board shells run with HOME=/ — force a real writable HOME and a stable state dir',
|
|
161
|
+
'[ -z "${HMH_HOME:-}" ] && export HMH_HOME="' + HMH_HOME + '"',
|
|
162
|
+
'export HOME="' + BOARD_HOME + '"',
|
|
163
|
+
'export NODE_ALLOW_JIT="${NODE_ALLOW_JIT:-1}"',
|
|
164
|
+
'# drop --jitless inherited from sandbox profiles; board root shell can JIT',
|
|
165
|
+
'NODE_OPTIONS="$(echo "${NODE_OPTIONS:-}" | sed \'s|--jitless||g; s/ */ /g\')"',
|
|
166
|
+
'NODE_OPTIONS="$(echo "$NODE_OPTIONS" | sed \'s/^ *//;s/ *$//\')"',
|
|
167
|
+
'[ -n "$NODE_OPTIONS" ] && export NODE_OPTIONS',
|
|
168
|
+
'# optional DevEco-layout toolchain shims (hvigorw / ohpm)',
|
|
169
|
+
'[ -z "${HM_DEVECO_HOME:-}" ] && [ -d ' + BOARD_HOME + '/.local/hm-devtools ] && export HM_DEVECO_HOME="' + BOARD_HOME + '/.local/hm-devtools"',
|
|
170
|
+
'exec "$HNODE" "$HROOT/node_modules/@hmharness/cli/dist/main.js" "$@"',
|
|
171
|
+
'',
|
|
172
|
+
].join('\n');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function writeLauncher(nodeBin) {
|
|
176
|
+
const src = launcherSource(nodeBin);
|
|
177
|
+
const userBin = path.join(BOARD_HOME, '.local', 'bin');
|
|
178
|
+
fs.mkdirSync(userBin, { recursive: true });
|
|
179
|
+
fs.writeFileSync(path.join(userBin, 'hmh'), src);
|
|
180
|
+
fs.chmodSync(path.join(userBin, 'hmh'), 0o755);
|
|
181
|
+
log('launcher: ' + path.join(userBin, 'hmh'));
|
|
182
|
+
|
|
183
|
+
// System locations live on the read-only rootfs — remount rw, copy, restore ro.
|
|
184
|
+
// /system/bin matters most: isolated tmpfs-namespace terminals (ttyd web
|
|
185
|
+
// terminals, containers) see no /usr at all, but /bin -> /system/bin + /data.
|
|
186
|
+
for (const sysBin of ['/usr/local/bin', '/system/bin']) {
|
|
187
|
+
try { fs.mkdirSync(sysBin, { recursive: true }); } catch (_) { /* exists */ }
|
|
188
|
+
const target = path.join(sysBin, 'hmh');
|
|
189
|
+
const rw = spawnSync('mount', ['-o', 'remount,rw', '/'], { encoding: 'utf8' });
|
|
190
|
+
try {
|
|
191
|
+
fs.writeFileSync(target, src);
|
|
192
|
+
fs.chmodSync(target, 0o755);
|
|
193
|
+
log('launcher: ' + target + (rw.status === 0 ? ' (rootfs remounted rw then ro)' : ''));
|
|
194
|
+
} catch (e) {
|
|
195
|
+
log('warn: could not write ' + target + ': ' + e.message);
|
|
196
|
+
} finally {
|
|
197
|
+
if (rw.status === 0) spawnSync('mount', ['-o', 'remount,ro', '/'], { encoding: 'utf8' });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ---------- main ------------------------------------------------------------
|
|
203
|
+
(async () => {
|
|
204
|
+
log('board home: ' + BOARD_HOME);
|
|
205
|
+
const nodeBin = findNode();
|
|
206
|
+
if (!nodeBin) { console.error('FATAL: no Node >= 22 found (looked at PATH, dsh-pack, .ohos). hmh needs Node >= 22.'); process.exit(1); }
|
|
207
|
+
log('node: ' + nodeBin + ' (' + (spawnSync(nodeBin, ['--version'], { encoding: 'utf8' }).stdout || '').trim() + ')');
|
|
208
|
+
|
|
209
|
+
if (!BIN_ONLY) {
|
|
210
|
+
let pins;
|
|
211
|
+
try { pins = await resolveVersions(); }
|
|
212
|
+
catch (e) {
|
|
213
|
+
log('warn: registry unreachable (' + e.message.slice(0, 80) + ') — falling back to known-good pins');
|
|
214
|
+
pins = Object.assign({}, FALLBACK_PINS);
|
|
215
|
+
}
|
|
216
|
+
for (const n of PACKAGES) log(' @hmharness/' + n + '@' + pins[n]);
|
|
217
|
+
|
|
218
|
+
const STAGE = NM + '.new';
|
|
219
|
+
fs.rmSync(STAGE, { recursive: true, force: true });
|
|
220
|
+
fs.mkdirSync(path.join(STAGE, '@hmharness'), { recursive: true });
|
|
221
|
+
for (const name of PACKAGES) {
|
|
222
|
+
const ver = pins[name];
|
|
223
|
+
const tgz = path.join(ROOT, '.stage.tgz');
|
|
224
|
+
process.stdout.write('download ' + name + '@' + ver + ' ... ');
|
|
225
|
+
await download(REG + '/@hmharness/' + name + '/-/' + name + '-' + ver + '.tgz', tgz);
|
|
226
|
+
const dest = path.join(STAGE, '@hmharness', name);
|
|
227
|
+
extract(tgz, dest);
|
|
228
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(dest, 'package.json'), 'utf8'));
|
|
229
|
+
if (pkg.version !== ver) throw new Error(name + ': unpacked ' + pkg.version + ' != ' + ver);
|
|
230
|
+
log('ok');
|
|
231
|
+
}
|
|
232
|
+
fs.rmSync(path.join(ROOT, '.stage.tgz'), { force: true });
|
|
233
|
+
|
|
234
|
+
// syntax-check the staged CLI entrypoint before swapping anything
|
|
235
|
+
const main = path.join(STAGE, '@hmharness', 'cli', 'dist', 'main.js');
|
|
236
|
+
const chk = spawnSync(nodeBin, ['--check', main], { encoding: 'utf8' });
|
|
237
|
+
if (chk.status !== 0) throw new Error('staged main.js failed --check: ' + (chk.stderr || '').slice(0, 200));
|
|
238
|
+
log('staged CLI entrypoint OK');
|
|
239
|
+
|
|
240
|
+
const BAK = NM + '.bak';
|
|
241
|
+
fs.rmSync(BAK, { recursive: true, force: true });
|
|
242
|
+
if (fs.existsSync(NM)) fs.renameSync(NM, BAK);
|
|
243
|
+
fs.renameSync(STAGE, NM);
|
|
244
|
+
log('installed @hmharness/cli@' + pins.cli + ' (previous tree kept at ' + BAK + ')');
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
writeLauncher(nodeBin);
|
|
248
|
+
|
|
249
|
+
// first run: create the state skeleton + blank config (never overwrite)
|
|
250
|
+
if (!fs.existsSync(path.join(HMH_HOME, 'config.json'))) {
|
|
251
|
+
log('first run: creating config skeleton at ' + HMH_HOME);
|
|
252
|
+
const r = spawnSync(nodeBin, [path.join(NM, '@hmharness', 'cli', 'dist', 'main.js'), 'init'], {
|
|
253
|
+
encoding: 'utf8', env: Object.assign({}, process.env, { HMH_HOME, HOME: BOARD_HOME }),
|
|
254
|
+
});
|
|
255
|
+
log((r.stdout || r.stderr || '').trim().split('\n').slice(-3).join('\n'));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
console.log('\nnext steps:');
|
|
259
|
+
console.log(' 1. put your provider keys in ' + path.join(HMH_HOME, 'config.json'));
|
|
260
|
+
console.log(' (presets for 38 vendors: docs/PROVIDERS.md)');
|
|
261
|
+
console.log(' 2. hmh check # verify toolchain');
|
|
262
|
+
console.log(' 3. hmh tui # or: hmh web start → http://127.0.0.1:7788');
|
|
263
|
+
console.log('pitfalls & details: docs/KAIHONGOS.md');
|
|
264
|
+
})().catch((e) => { console.error('INSTALL FAILED:', e.message); process.exit(1); });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface TuiPending {
|
|
2
|
+
/** the task that was running when the process died ('' = none) */
|
|
3
|
+
runningTask: string;
|
|
4
|
+
/** queued tasks, in order */
|
|
5
|
+
queue: string[];
|
|
6
|
+
/** the rollout the running task belonged to, when known */
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
savedAt: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function pendingPath(home: string): string;
|
|
11
|
+
export declare function savePending(home: string, p: TuiPending): Promise<void>;
|
|
12
|
+
export declare function loadPending(home: string): Promise<TuiPending | null>;
|
|
13
|
+
export declare function clearPending(home: string): Promise<void>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cli - tui-state (crash-safe pending-task memory)
|
|
3
|
+
* The TUI is where multi-hour development sessions live, and the task queue
|
|
4
|
+
* lives only in process memory: a crash, a terminal close, or a power loss
|
|
5
|
+
* took the "what was I running" state with it. This module persists exactly
|
|
6
|
+
* that - the running task plus the queued ones - to HMH_HOME/tui-pending.json
|
|
7
|
+
* on every change. A graceful quit removes the file; if the file exists at
|
|
8
|
+
* the next startup, the previous process died mid-work and the TUI shows a
|
|
9
|
+
* recall notice (the full transcript always survives in the rollout - this
|
|
10
|
+
* is the thread pointer, not the data). Best-effort IO throughout: a corrupt
|
|
11
|
+
* or unwritable file degrades to "no pending work", never a crash.
|
|
12
|
+
*/
|
|
13
|
+
import { readFile, writeFile, rm } from 'node:fs/promises';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
export function pendingPath(home) {
|
|
16
|
+
return join(home, 'tui-pending.json');
|
|
17
|
+
}
|
|
18
|
+
export async function savePending(home, p) {
|
|
19
|
+
try {
|
|
20
|
+
await writeFile(pendingPath(home), JSON.stringify(p, null, 2), 'utf8');
|
|
21
|
+
}
|
|
22
|
+
catch { /* best effort - the pending hint is a courtesy, not a contract */ }
|
|
23
|
+
}
|
|
24
|
+
export async function loadPending(home) {
|
|
25
|
+
try {
|
|
26
|
+
const j = JSON.parse(await readFile(pendingPath(home), 'utf8'));
|
|
27
|
+
if (!j || typeof j !== 'object')
|
|
28
|
+
return null;
|
|
29
|
+
if (typeof j.runningTask !== 'string' || !Array.isArray(j.queue))
|
|
30
|
+
return null;
|
|
31
|
+
return {
|
|
32
|
+
runningTask: j.runningTask,
|
|
33
|
+
queue: j.queue.filter((q) => typeof q === 'string'),
|
|
34
|
+
sessionId: typeof j.sessionId === 'string' ? j.sessionId : undefined,
|
|
35
|
+
savedAt: typeof j.savedAt === 'string' ? j.savedAt : '',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null; // missing or corrupt = no pending work
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export async function clearPending(home) {
|
|
43
|
+
try {
|
|
44
|
+
await rm(pendingPath(home), { force: true });
|
|
45
|
+
}
|
|
46
|
+
catch { /* best effort */ }
|
|
47
|
+
}
|
package/dist/tui.js
CHANGED
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
import { stdin, stdout } from 'node:process';
|
|
14
14
|
import { basename } from 'node:path';
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
|
-
import { loadConfig, homeDir, resolveProvider, listProviders, setChatRoute, setLocale, PROVIDER_PRESETS, addProviders, detectLocalProviders, latestSession, listSessions, loadTranscript, transcriptChars, compactMessages, adaptiveContextChars, getGoal, setGoal, clearGoal } from '@hmharness/kernel';
|
|
16
|
+
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
17
|
import { listDrafts, listSkills, runBench, runEvolution } from '@hmharness/evolution';
|
|
18
18
|
import { buildRegistry, runAgentTask, strings } from '@hmharness/agent';
|
|
19
19
|
import { ensureWebDaemon, DEFAULT_WEB_PORT } from "./web-daemon.js";
|
|
20
20
|
import { formatRow, initialPickerState, pickerKey, reducePicker, toolbarLine, visibleRows } from "./resume-picker.js";
|
|
21
|
+
import { savePending, loadPending, clearPending } from "./tui-state.js";
|
|
21
22
|
/** installed version, shown in the TUI header (v0.4.0) so users always
|
|
22
23
|
* know which build they are talking to - resolves in both src/ and dist/ */
|
|
23
24
|
const HMH_VERSION = (() => {
|
|
@@ -1713,6 +1714,17 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1713
1714
|
rt.setModelChoices(listProviders(cfg).map((v) => ({ name: v.name, desc: `${v.model}${v.purposes.length ? ' (' + v.purposes.join('/') + ')' : ''}` })));
|
|
1714
1715
|
rt.setModes(autoApprove); // always-visible badge, ask mode included
|
|
1715
1716
|
rt.addText(t.tuiWelcome(chatModel), 'dim');
|
|
1717
|
+
// crash recall (断点记忆): a leftover tui-pending.json means the previous
|
|
1718
|
+
// process died with work in flight. The transcript survives in the rollout;
|
|
1719
|
+
// this is the pointer so the thread is not silently lost. Shown once.
|
|
1720
|
+
{
|
|
1721
|
+
const pend = await loadPending(home);
|
|
1722
|
+
if (pend && (pend.runningTask || pend.queue.length > 0)) {
|
|
1723
|
+
const shown = pend.runningTask || pend.queue[0] || '';
|
|
1724
|
+
rt.addText(t.tuiPendingNote(shown.slice(0, 80), pend.runningTask ? pend.queue.length : Math.max(0, pend.queue.length - 1)), 'dim');
|
|
1725
|
+
}
|
|
1726
|
+
await clearPending(home);
|
|
1727
|
+
}
|
|
1716
1728
|
if (webUp)
|
|
1717
1729
|
rt.addText(t.tuiWebLinked(DEFAULT_WEB_PORT), 'dim');
|
|
1718
1730
|
// update reminder: cached (1/day) registry check, resolved async into the
|
|
@@ -1732,7 +1744,8 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1732
1744
|
void autoUpdate({
|
|
1733
1745
|
home,
|
|
1734
1746
|
current,
|
|
1735
|
-
|
|
1747
|
+
// settled design T27: success is fully silent (no popup window via
|
|
1748
|
+
// windowsHide, no transcript line) - only a failed install speaks
|
|
1736
1749
|
sayFail: (why) => rt.addText(t.tuiAutoUpdateFailed(why), 'dim'),
|
|
1737
1750
|
});
|
|
1738
1751
|
}
|
|
@@ -1774,6 +1787,27 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1774
1787
|
let planMode = false;
|
|
1775
1788
|
/** /copy source: the last completed assistant text */
|
|
1776
1789
|
let lastAiText = '';
|
|
1790
|
+
/** circuit-breaker latch: set when a task dies on a PERMANENT provider
|
|
1791
|
+
* auth/balance error (401/402/403). The queue stops draining - every
|
|
1792
|
+
* remaining task would fail identically against an unpaid bill. */
|
|
1793
|
+
let authErrorHit = false;
|
|
1794
|
+
/** Crash-safe pending-task memory (settled design T25): what the TUI was
|
|
1795
|
+
* doing at any moment, persisted so an abnormal exit (crash, terminal
|
|
1796
|
+
* close, power loss) can show a recall notice on the next start. Graceful
|
|
1797
|
+
* quit clears it. */
|
|
1798
|
+
const syncPending = (runningTask) => {
|
|
1799
|
+
if (runningTask || taskQueue.length > 0) {
|
|
1800
|
+
void savePending(home, {
|
|
1801
|
+
runningTask: runningTask ?? '',
|
|
1802
|
+
queue: [...taskQueue],
|
|
1803
|
+
sessionId: currentSessionId,
|
|
1804
|
+
savedAt: new Date().toISOString(),
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
else {
|
|
1808
|
+
void clearPending(home);
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1777
1811
|
async function runShellBang(cmd) {
|
|
1778
1812
|
// B3: `! command` runs the local shell through the SAME gate as the
|
|
1779
1813
|
// agent's run_command tool — DENY_PATTERNS hard-refuse destructive
|
|
@@ -1825,6 +1859,7 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1825
1859
|
if (taskRunning) {
|
|
1826
1860
|
taskQueue.push(line);
|
|
1827
1861
|
rt.setQueued(taskQueue.length);
|
|
1862
|
+
syncPending(null); // queue grew while a task runs - persist the new depth
|
|
1828
1863
|
rt.addText(`📋 queued: "${line.slice(0, 60)}${line.length > 60 ? '…' : ''}" (${taskQueue.length} waiting)`, 'dim');
|
|
1829
1864
|
return;
|
|
1830
1865
|
}
|
|
@@ -1930,16 +1965,29 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
1930
1965
|
let task = firstTask;
|
|
1931
1966
|
let first = true;
|
|
1932
1967
|
while (task) {
|
|
1968
|
+
syncPending(task);
|
|
1933
1969
|
await runSingleTask(task, first ? forkFrom : undefined, first ? forkResume : undefined);
|
|
1934
1970
|
first = false;
|
|
1971
|
+
// circuit breaker (settled design T24): a permanent provider
|
|
1972
|
+
// auth/balance error means every queued task would fail the same way -
|
|
1973
|
+
// hold the queue for the user instead of burning through it
|
|
1974
|
+
if (authErrorHit && taskQueue.length > 0) {
|
|
1975
|
+
rt.setQueued(taskQueue.length);
|
|
1976
|
+
rt.addText(t.tuiQueueHeld(taskQueue.length), 'dim');
|
|
1977
|
+
syncPending(null);
|
|
1978
|
+
return;
|
|
1979
|
+
}
|
|
1935
1980
|
task = taskQueue.shift();
|
|
1936
1981
|
rt.setQueued(taskQueue.length);
|
|
1982
|
+
syncPending(task ?? null);
|
|
1937
1983
|
if (task)
|
|
1938
1984
|
rt.addText(`▶ next queued: "${task.slice(0, 60)}${task.length > 60 ? '…' : ''}"`, 'dim');
|
|
1939
1985
|
}
|
|
1940
1986
|
taskRunning = false;
|
|
1987
|
+
syncPending(null);
|
|
1941
1988
|
}
|
|
1942
1989
|
async function runSingleTask(line, forkFrom, forkResume) {
|
|
1990
|
+
authErrorHit = false; // fresh latch per task attempt
|
|
1943
1991
|
rt.addUser(line);
|
|
1944
1992
|
// the folded echo hides everything past line 2 - keep the full prompt
|
|
1945
1993
|
// retrievable in the Ctrl+T replay
|
|
@@ -2057,6 +2105,7 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2057
2105
|
catch (err) {
|
|
2058
2106
|
rt.setBusy(false);
|
|
2059
2107
|
currentInject = null;
|
|
2108
|
+
authErrorHit = isProviderAuthError(String(err));
|
|
2060
2109
|
rt.addText(String(err), 'err');
|
|
2061
2110
|
// Recovery First (docx TUI 专项): every task failure names the next step
|
|
2062
2111
|
// instead of leaving a bare stack - retry is one up-arrow away
|
|
@@ -2075,7 +2124,12 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2075
2124
|
rt.addText(t.cmdResumeNotFound(tr?.id ?? file), 'err');
|
|
2076
2125
|
return;
|
|
2077
2126
|
}
|
|
2078
|
-
|
|
2127
|
+
// bounded resume (settled design T26): the rollout keeps everything
|
|
2128
|
+
// forever (audit), but the in-memory thread is compacted to the model
|
|
2129
|
+
// budget immediately - the loop would do this on the next call anyway;
|
|
2130
|
+
// doing it here keeps /usage, fork copies and memory footprint honest
|
|
2131
|
+
// from the first turn
|
|
2132
|
+
history = compactMessages(tr.messages, adaptiveContextChars(resolveProvider(cfg, 'chat')));
|
|
2079
2133
|
currentSessionId = tr.id;
|
|
2080
2134
|
rt.clearScreen();
|
|
2081
2135
|
// long sessions render from the tail so the visible window stays usable
|
|
@@ -2120,6 +2174,7 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2120
2174
|
const n = taskQueue.length;
|
|
2121
2175
|
taskQueue.length = 0;
|
|
2122
2176
|
rt.setQueued(0);
|
|
2177
|
+
syncPending(null);
|
|
2123
2178
|
rt.addText(n > 0 ? 'cleared ' + n + ' queued task(s)' : 'queue was already empty', 'dim');
|
|
2124
2179
|
return;
|
|
2125
2180
|
}
|
|
@@ -2724,6 +2779,9 @@ export async function tui(yes, noWeb = false, opts = {}) {
|
|
|
2724
2779
|
process.off('SIGINT', sigCleanup);
|
|
2725
2780
|
process.off('SIGTERM', sigCleanup);
|
|
2726
2781
|
process.off('SIGHUP', sigCleanup);
|
|
2782
|
+
// graceful exit: whatever was pending was deliberately abandoned (the
|
|
2783
|
+
// crash-recall notice must NOT fire on a clean quit)
|
|
2784
|
+
await clearPending(home);
|
|
2727
2785
|
for (const c of clients)
|
|
2728
2786
|
c.close();
|
|
2729
2787
|
stdout.write('\n');
|
package/dist/update-check.d.ts
CHANGED
|
@@ -17,31 +17,48 @@ export declare function checkForUpdate(opts: {
|
|
|
17
17
|
/** Fire-and-forget wrapper for interactive frontends: resolve-and-say, or
|
|
18
18
|
* say nothing at all. Never rejects. */
|
|
19
19
|
export declare function notifyUpdate(home: string, current: string, say: (line: string) => void): Promise<void>;
|
|
20
|
-
/** Background self-update (product direction 2026-09-21: zero-action updates
|
|
21
|
-
*
|
|
20
|
+
/** Background self-update (product direction 2026-09-21: zero-action updates;
|
|
21
|
+
* 2026-09-25 redesign: SMART update; 2026-10-02 T27/T28: fully silent +
|
|
22
|
+
* board channel).
|
|
22
23
|
*
|
|
23
24
|
* The old version hard-coded `spawn('npm', ...)` - which (a) silently fails
|
|
24
25
|
* on Windows since Node 18.20 refuses to spawn .cmd shims without a shell,
|
|
25
|
-
* while the UI still claimed "已在后台自动更新",
|
|
26
|
-
* FileHandle (DEP0137 GC-close warnings on every startup)
|
|
26
|
+
* while the UI still claimed "已在后台自动更新", (b) leaked the log
|
|
27
|
+
* FileHandle (DEP0137 GC-close warnings on every startup), and (c) opened a
|
|
28
|
+
* VISIBLE console window for every background install (the "update popup").
|
|
27
29
|
*
|
|
28
|
-
* The
|
|
30
|
+
* The design adapts instead of hard-coding, three layers deep:
|
|
31
|
+
* 0. board installs (KaihongOS/OpenHarmony, <home>/.local/hmharness
|
|
32
|
+
* layout, NO npm) update through the SHIPPED board installer script -
|
|
33
|
+
* deterministic, idempotent, registry-driven with offline pins (T28);
|
|
29
34
|
* 1. buildUpdateCommand() picks the launcher per platform (cmd.exe shell
|
|
30
|
-
* escape on win32, direct exec elsewhere) - the SAME JS runs everywhere
|
|
31
|
-
* no per-OS program;
|
|
35
|
+
* escape on win32, direct exec elsewhere) - the SAME JS runs everywhere;
|
|
32
36
|
* 2. if the standard install fails to even start, aiRepairUpdate() asks the
|
|
33
37
|
* user's configured chat model for ONE corrective install command based
|
|
34
|
-
* on the real error + environment facts
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
38
|
+
* on the real error + environment facts, validates it against an
|
|
39
|
+
* allow/deny filter and runs it detached. That is the "AI-driven" layer:
|
|
40
|
+
* the model adapts to the machine, not our code.
|
|
41
|
+
* Every spawn is detached + windowsHide (T27): updates are INVISIBLE -
|
|
42
|
+
* success says nothing (the header version changes on the next launch),
|
|
43
|
+
* only a failed install may print one dim line. A lock file keeps
|
|
44
|
+
* concurrent hmh instances from racing one install. */
|
|
39
45
|
export interface UpdateLaunch {
|
|
40
46
|
file: string;
|
|
41
47
|
args: string[];
|
|
42
48
|
/** shell:true semantics are needed when the package manager is a .cmd shim */
|
|
43
49
|
shellEscaped: boolean;
|
|
44
50
|
}
|
|
51
|
+
/** True when the CLI runs from a KaihongOS/OpenHarmony board layout
|
|
52
|
+
* (<home>/.local/hmharness/node_modules/@hmharness/cli/dist) - the layout
|
|
53
|
+
* scripts/board/install-kaihongos.cjs creates. npm does not exist there and
|
|
54
|
+
* the npm-shaped AI-repair whitelist can never produce a legal board
|
|
55
|
+
* command, so updates take the deterministic board-installer path instead
|
|
56
|
+
* (settled design T28). Pure; tested. */
|
|
57
|
+
export declare function isBoardInstall(distDir: string): boolean;
|
|
58
|
+
/** The board home for a board-layout dist dir ('' when not a board install).
|
|
59
|
+
* <home> is the segment BEFORE /.local/hmharness - exactly what the
|
|
60
|
+
* installer's --home flag wants. Pure; tested. */
|
|
61
|
+
export declare function boardHomeFromDistDir(distDir: string): string;
|
|
45
62
|
/** Platform-correct launcher for `npm install -g @hmharness/cli@<v>`.
|
|
46
63
|
* Pure; tested. */
|
|
47
64
|
export declare function buildUpdateCommand(platform: string, version: string): UpdateLaunch;
|
|
@@ -66,6 +83,7 @@ export declare function aiRepairUpdate(opts: {
|
|
|
66
83
|
detached: boolean;
|
|
67
84
|
stdio: unknown;
|
|
68
85
|
cwd: string;
|
|
86
|
+
windowsHide?: boolean;
|
|
69
87
|
}) => {
|
|
70
88
|
unref: () => void;
|
|
71
89
|
on: (ev: string, fn: () => void) => void;
|
|
@@ -80,16 +98,22 @@ export declare function spawnStarted(child: {
|
|
|
80
98
|
export declare function autoUpdate(opts: {
|
|
81
99
|
home: string;
|
|
82
100
|
current: string;
|
|
83
|
-
|
|
101
|
+
/** failure notice only - success is SILENT by design (T27): the new
|
|
102
|
+
* version announces itself in the TUI header on the next launch */
|
|
84
103
|
sayFail?: (line: string) => void;
|
|
85
104
|
spawnImpl?: (cmd: string, args: string[], o: {
|
|
86
105
|
detached: boolean;
|
|
87
106
|
stdio: unknown;
|
|
88
107
|
cwd: string;
|
|
108
|
+
windowsHide?: boolean;
|
|
89
109
|
}) => {
|
|
90
110
|
unref: () => void;
|
|
91
111
|
on: (ev: string, fn: () => void) => void;
|
|
92
112
|
};
|
|
93
113
|
now?: number;
|
|
94
114
|
aiChat?: (prompt: string) => Promise<string>;
|
|
115
|
+
/** override the running dist dir (tests inject a board layout) */
|
|
116
|
+
distDir?: string;
|
|
117
|
+
/** registry fetch injection (tests stay hermetic) */
|
|
118
|
+
fetchImpl?: typeof fetch;
|
|
95
119
|
}): Promise<void>;
|
package/dist/update-check.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* never nagging offline, results cached for a day.
|
|
7
7
|
*/
|
|
8
8
|
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
9
|
+
import { existsSync } from 'node:fs';
|
|
9
10
|
import { join } from 'node:path';
|
|
10
11
|
const REGISTRY = 'https://registry.npmjs.org/-/package/@hmharness/cli/dist-tags';
|
|
11
12
|
// 5 minutes for auto-update mode (fresh enough to catch new releases same-session);
|
|
@@ -67,6 +68,26 @@ export async function notifyUpdate(home, current, say) {
|
|
|
67
68
|
}
|
|
68
69
|
catch { /* never surface update-check failures */ }
|
|
69
70
|
}
|
|
71
|
+
/** True when the CLI runs from a KaihongOS/OpenHarmony board layout
|
|
72
|
+
* (<home>/.local/hmharness/node_modules/@hmharness/cli/dist) - the layout
|
|
73
|
+
* scripts/board/install-kaihongos.cjs creates. npm does not exist there and
|
|
74
|
+
* the npm-shaped AI-repair whitelist can never produce a legal board
|
|
75
|
+
* command, so updates take the deterministic board-installer path instead
|
|
76
|
+
* (settled design T28). Pure; tested. */
|
|
77
|
+
export function isBoardInstall(distDir) {
|
|
78
|
+
const d = distDir.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
79
|
+
return /\/\.local\/hmharness\/node_modules\/@hmharness\/cli\/dist$/.test(d);
|
|
80
|
+
}
|
|
81
|
+
/** The board home for a board-layout dist dir ('' when not a board install).
|
|
82
|
+
* <home> is the segment BEFORE /.local/hmharness - exactly what the
|
|
83
|
+
* installer's --home flag wants. Pure; tested. */
|
|
84
|
+
export function boardHomeFromDistDir(distDir) {
|
|
85
|
+
if (!isBoardInstall(distDir))
|
|
86
|
+
return '';
|
|
87
|
+
const d = distDir.replace(/\\/g, '/');
|
|
88
|
+
const at = d.indexOf('/.local/hmharness/');
|
|
89
|
+
return at > 0 ? d.slice(0, at) : '/';
|
|
90
|
+
}
|
|
70
91
|
/** Platform-correct launcher for `npm install -g @hmharness/cli@<v>`.
|
|
71
92
|
* Pure; tested. */
|
|
72
93
|
export function buildUpdateCommand(platform, version) {
|
|
@@ -124,7 +145,7 @@ export async function aiRepairUpdate(opts) {
|
|
|
124
145
|
const spawnFn = opts.spawnImpl ?? (await import('node:child_process')).spawn;
|
|
125
146
|
const plat = opts.platform;
|
|
126
147
|
const child = plat === 'win32'
|
|
127
|
-
? spawnFn('cmd.exe', ['/d', '/s', '/c', cmd], { detached: true, stdio: ['ignore', opts.logFd, opts.logFd], cwd: opts.home })
|
|
148
|
+
? spawnFn('cmd.exe', ['/d', '/s', '/c', cmd], { detached: true, stdio: ['ignore', opts.logFd, opts.logFd], cwd: opts.home, windowsHide: true })
|
|
128
149
|
: spawnFn(cmd.split(' ')[0], cmd.split(' ').slice(1), { detached: true, stdio: ['ignore', opts.logFd, opts.logFd], cwd: opts.home });
|
|
129
150
|
child.unref();
|
|
130
151
|
return cmd;
|
|
@@ -148,7 +169,7 @@ export function spawnStarted(child, ms = 3000) {
|
|
|
148
169
|
}
|
|
149
170
|
export async function autoUpdate(opts) {
|
|
150
171
|
try {
|
|
151
|
-
const info = await checkForUpdate({ home: opts.home, current: opts.current, now: opts.now });
|
|
172
|
+
const info = await checkForUpdate({ home: opts.home, current: opts.current, now: opts.now, ...(opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}) });
|
|
152
173
|
if (!info)
|
|
153
174
|
return;
|
|
154
175
|
const { open } = await import('node:fs/promises');
|
|
@@ -157,32 +178,60 @@ export async function autoUpdate(opts) {
|
|
|
157
178
|
try {
|
|
158
179
|
const prev = JSON.parse(await readFile(lockFile, 'utf8'));
|
|
159
180
|
if (now - prev.time < 10 * 60_000) {
|
|
160
|
-
|
|
161
|
-
return;
|
|
181
|
+
return; // another hmh is already updating - silent (T27)
|
|
162
182
|
}
|
|
163
183
|
}
|
|
164
184
|
catch { /* no lock */ }
|
|
165
185
|
await mkdir(opts.home, { recursive: true });
|
|
166
186
|
const log = await open(join(opts.home, 'update.log'), 'a');
|
|
167
187
|
try {
|
|
168
|
-
const launch = buildUpdateCommand(process.platform, info.latest);
|
|
169
188
|
const spawnFn = opts.spawnImpl ?? (await import('node:child_process')).spawn;
|
|
189
|
+
// Layer 0 (settled design T28): KaihongOS/OpenHarmony board installs
|
|
190
|
+
// have no npm and no package manager the AI whitelist could ever
|
|
191
|
+
// target - the SHIPPED board installer is the only correct updater.
|
|
192
|
+
// It is idempotent, resolves versions from the registry (offline
|
|
193
|
+
// fallback pins inside), stages + verifies + swaps, and rewrites the
|
|
194
|
+
// launcher. Everything runs detached and hidden; success is silent.
|
|
195
|
+
const distDir = opts.distDir ?? join(import.meta.dirname ?? '.', '');
|
|
196
|
+
if (isBoardInstall(distDir)) {
|
|
197
|
+
const script = join(distDir, '..', 'board', 'install-kaihongos.cjs');
|
|
198
|
+
const bhome = boardHomeFromDistDir(distDir);
|
|
199
|
+
if (bhome && existsSync(script)) {
|
|
200
|
+
const child = spawnFn(process.execPath, [script, '--home=' + bhome], {
|
|
201
|
+
detached: true,
|
|
202
|
+
stdio: ['ignore', log.fd, log.fd],
|
|
203
|
+
cwd: opts.home,
|
|
204
|
+
windowsHide: true, // never flash a console window (T27)
|
|
205
|
+
});
|
|
206
|
+
child.unref();
|
|
207
|
+
await writeFile(lockFile, JSON.stringify({ time: now, to: info.latest, via: 'board-installer' }), 'utf8');
|
|
208
|
+
const started = await spawnStarted(child);
|
|
209
|
+
if (!started)
|
|
210
|
+
throw new Error('board installer failed to start');
|
|
211
|
+
return; // silent success (T27)
|
|
212
|
+
}
|
|
213
|
+
opts.sayFail?.('board install: updater script missing');
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const launch = buildUpdateCommand(process.platform, info.latest);
|
|
170
217
|
const child = spawnFn(launch.file, launch.args, {
|
|
171
218
|
detached: true,
|
|
172
219
|
stdio: ['ignore', log.fd, log.fd],
|
|
173
220
|
cwd: opts.home,
|
|
221
|
+
windowsHide: true, // detached cmd.exe/npm MUST NOT open a visible window (T27)
|
|
174
222
|
});
|
|
175
223
|
child.unref();
|
|
176
224
|
await writeFile(lockFile, JSON.stringify({ time: now, to: info.latest }), 'utf8');
|
|
177
225
|
const started = await spawnStarted(child);
|
|
178
226
|
if (!started)
|
|
179
227
|
throw new Error('installer failed to start');
|
|
180
|
-
|
|
228
|
+
// silent success (T27): no notice - the header version changes on the
|
|
229
|
+
// next launch; every detail is in update.log if anyone needs it
|
|
181
230
|
}
|
|
182
231
|
catch (err) {
|
|
183
232
|
// SMART layer: let the user's own model adapt to this machine
|
|
184
233
|
const errText = String(err).slice(0, 400);
|
|
185
|
-
const distDir = join(import.meta.dirname ?? '.', '');
|
|
234
|
+
const distDir = opts.distDir ?? join(import.meta.dirname ?? '.', '');
|
|
186
235
|
const ran = await aiRepairUpdate({
|
|
187
236
|
home: opts.home,
|
|
188
237
|
platform: process.platform,
|
|
@@ -196,7 +245,6 @@ export async function autoUpdate(opts) {
|
|
|
196
245
|
});
|
|
197
246
|
if (ran) {
|
|
198
247
|
await writeFile(lockFile, JSON.stringify({ time: now, to: info.latest, via: 'ai-repair', cmd: ran }), 'utf8');
|
|
199
|
-
opts.say(info.latest + ' (AI 修复安装)');
|
|
200
248
|
}
|
|
201
249
|
else {
|
|
202
250
|
opts.sayFail?.(errText.slice(0, 80));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.11",
|
|
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",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"hmh": "dist/main.js"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"board"
|
|
19
20
|
],
|
|
20
21
|
"engines": {
|
|
21
22
|
"node": ">=22"
|
|
@@ -43,17 +44,17 @@
|
|
|
43
44
|
"build": "tsc -p tsconfig.build.json"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@hmharness/agent": "0.23.
|
|
47
|
-
"@hmharness/cognitive": "0.23.
|
|
48
|
-
"@hmharness/domain-harmony": "0.23.
|
|
49
|
-
"@hmharness/domain-ops": "0.23.
|
|
50
|
-
"@hmharness/environments": "0.23.
|
|
51
|
-
"@hmharness/evaluation": "0.23.
|
|
52
|
-
"@hmharness/evolution": "0.23.
|
|
53
|
-
"@hmharness/kernel": "0.23.
|
|
54
|
-
"@hmharness/observability": "0.23.
|
|
55
|
-
"@hmharness/sandbox": "0.23.
|
|
56
|
-
"@hmharness/web": "0.23.
|
|
47
|
+
"@hmharness/agent": "0.23.11",
|
|
48
|
+
"@hmharness/cognitive": "0.23.11",
|
|
49
|
+
"@hmharness/domain-harmony": "0.23.11",
|
|
50
|
+
"@hmharness/domain-ops": "0.23.11",
|
|
51
|
+
"@hmharness/environments": "0.23.11",
|
|
52
|
+
"@hmharness/evaluation": "0.23.11",
|
|
53
|
+
"@hmharness/evolution": "0.23.11",
|
|
54
|
+
"@hmharness/kernel": "0.23.11",
|
|
55
|
+
"@hmharness/observability": "0.23.11",
|
|
56
|
+
"@hmharness/sandbox": "0.23.11",
|
|
57
|
+
"@hmharness/web": "0.23.11",
|
|
57
58
|
"qrcode": "^1.5.4"
|
|
58
59
|
}
|
|
59
60
|
}
|