@hncode/hncode 0.8.2 → 0.8.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/bin/hncode CHANGED
@@ -9,14 +9,60 @@
9
9
  // bootstrap() never throws (a missing Node API or a broken plugin dir degrades
10
10
  // to "no patches/plugins"), and we swallow even that here: nothing in the plugin
11
11
  // subsystem may stop hncode itself from launching.
12
- import('../src/bootstrap.js')
13
- .then((b) => b.bootstrap())
14
- .catch((err) => { console.error('[hncode] bootstrap failed, starting without plugins:', err); })
15
- .then(() => import('../src/index.js'))
16
- .then((mod) => mod.main(process.argv.slice(2)))
17
- .then((code) => process.exit(code ?? 0))
18
- .catch((err) => {
12
+ //
13
+ // THE COMPILE CACHE NEEDS A RE-EXEC, BECAUSE NODE READS IT AT STARTUP.
14
+ //
15
+ // The TUI pulls in about ninety modules, and reusing their compiled bytecode measured
16
+ // 393ms -> 298ms on a warm start. The variable is read before this file runs, so the only
17
+ // way to enable it is to start a child with it set and let the child do the work. That
18
+ // happens ONCE per launch, guarded by the variable being absent, so the child (which has
19
+ // it) never repeats it.
20
+ //
21
+ // It is skipped when the environment already names a cache (the user configured one), and
22
+ // when HNCODE_NO_COMPILE_CACHE is set (a sandbox, or a read-only home).
23
+ import path from 'node:path';
24
+ import os from 'node:os';
25
+ import cp from 'node:child_process';
26
+ import { fileURLToPath } from 'node:url';
27
+
28
+ function cacheDir() {
29
+ try { return path.join(os.homedir(), '.hncode', 'compile-cache'); } catch { return null; }
30
+ }
31
+
32
+ /** Start the real CLI with the compile cache on, and return true when that happened. */
33
+ function reexecWithCache() {
34
+ if (process.env.NODE_COMPILE_CACHE) return false;
35
+ if (process.env.HNCODE_NO_COMPILE_CACHE) return false;
36
+ const dir = cacheDir();
37
+ if (!dir) return false;
38
+ const self = fileURLToPath(import.meta.url);
39
+ const child = cp.spawn(process.execPath, [self, ...process.argv.slice(2)], {
40
+ stdio: 'inherit',
41
+ env: { ...process.env, NODE_COMPILE_CACHE: dir },
42
+ });
43
+ child.on('error', () => {
44
+ // The spawn itself failed: fall through to running in this process, uncached.
45
+ run();
46
+ });
47
+ child.on('exit', (code, signal) => {
48
+ if (signal) process.kill(process.pid, signal);
49
+ else process.exit(code ?? 0);
50
+ });
51
+ return true;
52
+ }
53
+
54
+ async function run() {
55
+ await import('../src/bootstrap.js')
56
+ .then((b) => b.bootstrap())
57
+ .catch((err) => { console.error('[hncode] bootstrap failed, starting without plugins:', err); });
58
+ const mod = await import('../src/index.js');
59
+ const code = await mod.main(process.argv.slice(2));
60
+ process.exit(code ?? 0);
61
+ }
62
+
63
+ if (!reexecWithCache()) {
64
+ run().catch((err) => {
19
65
  console.error(err);
20
66
  process.exit(1);
21
67
  });
22
-
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hncode/hncode",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "hncode — A cyan-blue TUI AI coding agent with zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/agent-task.js CHANGED
@@ -14,6 +14,8 @@
14
14
  // goes through `createTask`, so a task always has the same shape no matter which
15
15
  // tool spawned it.
16
16
 
17
+ import { uiText } from './i18n.js';
18
+
17
19
  export const TERMINAL_STATUSES = new Set(['completed', 'failed', 'timed_out', 'killed', 'lost']);
18
20
 
19
21
  export function isTerminal(status) {
@@ -302,20 +304,20 @@ export function backgroundTaskPhase(status) {
302
304
  }
303
305
 
304
306
  function bgSubject(kind) {
305
- if (kind === 'agent') return 'agent task';
306
- if (kind === 'question') return 'question task';
307
- return 'bash task';
307
+ if (kind === 'agent') return uiText('agent task');
308
+ if (kind === 'question') return uiText('question task');
309
+ return uiText('bash task');
308
310
  }
309
311
 
310
312
  function bgHeadline(status, kind) {
311
313
  const subject = bgSubject(kind);
312
314
  switch (status) {
313
- case 'running': return `${subject} started in background`;
314
- case 'completed': return `${subject} completed in background`;
315
- case 'failed': return `${subject} failed in background`;
316
- case 'timed_out': return `${subject} timed out`;
317
- case 'killed': return `${subject} stopped`;
318
- case 'lost': return `${subject} lost`;
315
+ case 'running': return `${subject} ${uiText('started in background')}`;
316
+ case 'completed': return `${subject} ${uiText('completed in background')}`;
317
+ case 'failed': return `${subject} ${uiText('failed in background')}`;
318
+ case 'timed_out': return `${subject} ${uiText('timed out')}`;
319
+ case 'killed': return `${subject} ${uiText('stopped')}`;
320
+ case 'lost': return `${subject} ${uiText('lost')}`;
319
321
  default: return `${subject} ${status}`;
320
322
  }
321
323
  }
@@ -332,14 +334,14 @@ function bgDetail(task) {
332
334
  }
333
335
  if (task.status === 'killed') {
334
336
  const reason = bgTruncate(task.stopReason);
335
- parts.push(reason !== undefined ? `stopped — ${reason}` : 'stopped');
337
+ parts.push(reason !== undefined ? `stopped — ${reason}` : uiText('stopped'));
336
338
  }
337
339
  if (task.status === 'failed') {
338
340
  const reason = bgTruncate(task.stopReason);
339
341
  if (reason !== undefined) parts.push(reason);
340
342
  }
341
- if (task.status === 'timed_out') parts.push('timed out');
342
- if (task.status === 'lost') parts.push('session restarted before completion');
343
+ if (task.status === 'timed_out') parts.push(uiText('timed out'));
344
+ if (task.status === 'lost') parts.push(uiText('session restarted before completion'));
343
345
 
344
346
  return parts.length ? parts.join(' · ') : undefined;
345
347
  }