@hncode/hncode 0.8.1 → 0.8.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.
Files changed (52) hide show
  1. package/README.md +18 -0
  2. package/README_CN.md +14 -0
  3. package/bin/hncode +54 -8
  4. package/package.json +1 -1
  5. package/src/agent-task.js +356 -337
  6. package/src/agent.js +1465 -1405
  7. package/src/animate.js +56 -0
  8. package/src/colors.js +615 -593
  9. package/src/config.js +50 -7
  10. package/src/context-bar.js +280 -278
  11. package/src/doctor.js +4 -3
  12. package/src/file-tree.js +4 -3
  13. package/src/highlight.js +20 -6
  14. package/src/i18n.js +1432 -389
  15. package/src/image-row.js +11 -2
  16. package/src/index.js +218 -6
  17. package/src/keybindings.js +2 -1
  18. package/src/llm.js +146 -21
  19. package/src/log-file.js +112 -0
  20. package/src/markdown.js +646 -567
  21. package/src/mcp-server.js +409 -0
  22. package/src/mcp.js +279 -29
  23. package/src/memory-profile.js +19 -16
  24. package/src/migrate-index.js +175 -0
  25. package/src/migrate.js +392 -0
  26. package/src/panels.js +9 -7
  27. package/src/plan.js +7 -5
  28. package/src/plugin.js +37 -21
  29. package/src/registry-browser.js +17 -15
  30. package/src/rows-plan-bg.js +3 -2
  31. package/src/rows-status.js +20 -6
  32. package/src/rows-tool-result.js +242 -208
  33. package/src/screen-paint.js +153 -128
  34. package/src/session-recover.js +317 -0
  35. package/src/session.js +203 -13
  36. package/src/settings-schema.js +9 -0
  37. package/src/swarm-progress.js +6 -2
  38. package/src/tasks-browser.js +37 -36
  39. package/src/team-panel.js +12 -11
  40. package/src/term.js +57 -21
  41. package/src/text.js +254 -149
  42. package/src/tool-line.js +7 -2
  43. package/src/tool-result.js +400 -327
  44. package/src/tools/agent.js +7 -2
  45. package/src/tools/ask-user-question.js +1 -2
  46. package/src/tools/bash.js +446 -434
  47. package/src/tools/edit.js +653 -665
  48. package/src/tools/goal.js +130 -93
  49. package/src/tools/read.js +141 -133
  50. package/src/tools/tasks.js +214 -214
  51. package/src/tools/utils.js +143 -104
  52. package/src/tui.js +20887 -19942
package/src/config.js CHANGED
@@ -313,6 +313,27 @@ export function clampRatio(value, fallback) {
313
313
  return (v > 0 && v < 1) ? v : fallback;
314
314
  }
315
315
 
316
+ // ---- the runtime's own language -------------------------------------------
317
+
318
+ /**
319
+ * The language the SYSTEM is set to, as `zh` or `en`.
320
+ *
321
+ * Region, not timezone: a machine can sit in any timezone and still be an English
322
+ * install. `Intl` reports what the user picked in their OS settings, which is the same
323
+ * value their other applications follow. Anything outside Chinese falls back to English,
324
+ * which is what the UI is authored in.
325
+ *
326
+ * The locale is a parameter so a test can drive both branches without touching the host.
327
+ */
328
+ export function systemLanguage(locale) {
329
+ let tag = locale;
330
+ if (tag === undefined) {
331
+ try { tag = new Intl.DateTimeFormat().resolvedOptions().locale; } catch { tag = ''; }
332
+ }
333
+ const norm = String(tag || '').trim().toLowerCase().replace('_', '-');
334
+ return (norm === 'zh' || norm.startsWith('zh-')) ? 'zh' : 'en';
335
+ }
336
+
316
337
  export function resolveConfig() {
317
338
  const root = loadBaseToml() || {};
318
339
  // Merge plugin-provided defaults UNDER the user's config: an explicitly set
@@ -484,6 +505,22 @@ const b = baseUrl.replace(/\/+$/, '');
484
505
  // Backwards-compat: read legacy cool_mode key if calm_mode is not set.
485
506
  : (root.calm_mode === true || root.calm_mode === 'true'
486
507
  || root.cool_mode === true || root.cool_mode === 'true'),
508
+ lang: (() => {
509
+ const explicit = String(process.env.HNCODE_LANG || root.lang || '').trim().toLowerCase().replace('_', '-');
510
+ if (explicit === 'zh' || explicit.startsWith('zh-')) return 'zh';
511
+ if (explicit === 'en' || explicit.startsWith('en-')) return 'en';
512
+ return systemLanguage();
513
+ })(),
514
+ // THINKING TAGS: whether the model is told to wrap its reasoning in
515
+ // `<|thinking|>…<|/thinking|>`. THREE states: `auto` follows the model (a model with
516
+ // a native reasoning channel does not need the tag, one without it does), and `on`
517
+ // / `off` decide by hand.
518
+ thinkingTags: (() => {
519
+ const raw = String(process.env.HNCODE_THINKING_TAGS || root.thinking_tags || 'auto').trim().toLowerCase();
520
+ if (raw === 'on' || raw === 'true' || raw === 'yes' || raw === '1') return 'on';
521
+ if (raw === 'off' || raw === 'false' || raw === 'no' || raw === '0') return 'off';
522
+ return 'auto';
523
+ })(),
487
524
  subagentModel: process.env.HNCODE_SUBAGENT_MODEL || root.subagent_model || '',
488
525
  // SECONDARY MODEL (/secondary-model): the cheap model for side work — /btw,
489
526
  // /recap and the compaction summary run on it, so a long main-context model is
@@ -1243,9 +1280,14 @@ export function effortOptions(cfg, modelKeyName) {
1243
1280
  // Token budget for a NAMED grade, on a protocol that wants a number rather than a word.
1244
1281
  //
1245
1282
  // The grades the catalog declares are low/medium/high, and a user may also write their own
1246
- // in config.toml (`efforts = ["xhigh"]`). A grade with no entry here has no honest budget to
1247
- // send, so the field is omitted — the previous code fell back to 8000, which silently gave
1248
- // every unknown grade the same strength as `on` and `medium`.
1283
+ // in config.toml (`efforts = ["xhigh"]`). A grade with no entry here has no budget of its
1284
+ // own to send, and the old code fell back to 8000 — which silently gave an unknown grade the
1285
+ // same strength as `medium`.
1286
+ //
1287
+ // These numbers are the grade's INTENT, not the wire value. llm.js fits the figure to the
1288
+ // request's own `max_tokens` (see anthropicThinking), because this API requires a budget
1289
+ // that leaves the reply room to be written: 32000 against a 10000 cap is a guaranteed 400,
1290
+ // which is exactly what the old mapping sent for `high` and `max`.
1249
1291
  const EFFORT_BUDGETS = { low: 2000, medium: 8000, high: 16000, max: 32000 };
1250
1292
 
1251
1293
  // Map a chosen effort to the wire value for the active protocol.
@@ -1259,12 +1301,13 @@ export function effortWire(cfg, effort) {
1259
1301
  const named = Object.prototype.hasOwnProperty.call(EFFORT_BUDGETS, effort);
1260
1302
 
1261
1303
  if (cfg.protocol === 'anthropic') {
1262
- // `thinking: { type: 'enabled' }` IS the plain toggle; `budget_tokens` is optional and
1263
- // only meaningful for a named grade. Omitting it lets the provider pick its own budget,
1264
- // which is what "on" asked for.
1304
+ // A BUDGET IS REQUIRED whenever thinking is enabled on this protocol, the plain "on"
1305
+ // toggle included: `{type:'enabled'}` on its own is a 400, not a default. `on` therefore
1306
+ // asks for the neutral grade's figure and llm.js fits it to the request's output cap
1307
+ // (see anthropicThinking), so the intent survives but the number is always legal.
1265
1308
  return named
1266
1309
  ? { thinking: { type: 'enabled', budget_tokens: EFFORT_BUDGETS[effort] } }
1267
- : { thinking: { type: 'enabled' } };
1310
+ : { thinking: { type: 'enabled', budget_tokens: EFFORT_BUDGETS.medium } };
1268
1311
  }
1269
1312
 
1270
1313
  // Responses API and the OpenAI-compatible shape both take a GRADE word, and neither has