@hmharness/cli 0.23.10 → 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.
@@ -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); });
package/dist/tui.js CHANGED
@@ -1744,7 +1744,8 @@ export async function tui(yes, noWeb = false, opts = {}) {
1744
1744
  void autoUpdate({
1745
1745
  home,
1746
1746
  current,
1747
- say: (latest) => rt.addText(t.tuiAutoUpdating(latest), 'dim'),
1747
+ // settled design T27: success is fully silent (no popup window via
1748
+ // windowsHide, no transcript line) - only a failed install speaks
1748
1749
  sayFail: (why) => rt.addText(t.tuiAutoUpdateFailed(why), 'dim'),
1749
1750
  });
1750
1751
  }
@@ -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
- * notify only; 2026-09-25 redesign: SMART update).
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 "已在后台自动更新", and (b) leaked the log
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 smart design adapts instead of hard-coding:
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 (nvm/fnm/pnpm global dirs,
35
- * permission quirks - the long tail no static table covers), validates
36
- * it against an allow/deny filter and runs it detached. That is the
37
- * "AI-driven" layer: the model adapts to the machine, not our code.
38
- * A lock file keeps concurrent hmh instances from racing one install. */
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
- say: (line: string) => void;
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>;
@@ -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
- opts.say?.(info.latest + ' (another hmh is already updating)');
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
- opts.say(info.latest);
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.10",
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.10",
47
- "@hmharness/cognitive": "0.23.10",
48
- "@hmharness/domain-harmony": "0.23.10",
49
- "@hmharness/domain-ops": "0.23.10",
50
- "@hmharness/environments": "0.23.10",
51
- "@hmharness/evaluation": "0.23.10",
52
- "@hmharness/evolution": "0.23.10",
53
- "@hmharness/kernel": "0.23.10",
54
- "@hmharness/observability": "0.23.10",
55
- "@hmharness/sandbox": "0.23.10",
56
- "@hmharness/web": "0.23.10",
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
  }