@hncode/hncode 0.8.1 → 0.8.2

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/src/agent.js CHANGED
@@ -689,6 +689,11 @@ const filtered = (Array.isArray(cfg.toolFilter) && cfg.toolFilter.length
689
689
  let toolCalls = [];
690
690
  let emittedEnd = false;
691
691
  let thought = '';
692
+ // Anthropic thinking blocks, WITH their signatures. They belong to the assistant
693
+ // message: the next request in the turn must replay them or the provider rejects the
694
+ // tool result that follows (see toAnthropic in llm.js). Reset per step because each
695
+ // step is a separate reply.
696
+ let thoughtBlocks = [];
692
697
  // decide whether running out of steps actually left the turn unfinished.
693
698
  let hadToolCallsOnFinalStep = false;
694
699
  // How many times this turn has continued an answer the output cap cut in half.
@@ -708,6 +713,11 @@ const filtered = (Array.isArray(cfg.toolFilter) && cfg.toolFilter.length
708
713
  thought += e.text;
709
714
  this.onEvent({ type: 'think', text: e.text });
710
715
  break;
716
+ case 'thought_block':
717
+ // A signed thinking block from the provider. Opaque to us; kept whole so it can
718
+ // be sent back verbatim, which is the only way it is accepted.
719
+ if (e.block) thoughtBlocks.push(e.block);
720
+ break;
711
721
  case 'truncated':
712
722
  // The reply hit max_tokens and was cut off mid-answer. Remember it: the
713
723
  // loop below continues the turn instead of ending it (see the `truncated`
@@ -793,7 +803,7 @@ const filtered = (Array.isArray(cfg.toolFilter) && cfg.toolFilter.length
793
803
  }
794
804
  }
795
805
  if (this.stopRequested) { this.onEvent({ type: 'stopped' }); break; }
796
- text = ''; toolCalls = []; emittedEnd = false; thought = '';
806
+ text = ''; toolCalls = []; emittedEnd = false; thought = ''; thoughtBlocks = [];
797
807
  this._truncated = false;
798
808
  // Report the start of each model round so the TUI can count steps/rounds.
799
809
  this.onEvent({ type: 'step_start', step, round: step + 1 });
@@ -1061,14 +1071,20 @@ const filtered = (Array.isArray(cfg.toolFilter) && cfg.toolFilter.length
1061
1071
 
1062
1072
  // Append the assistant message. NEVER push one that carries neither text
1063
1073
  // nor tool_calls: upstream rejects it with "content or tool_calls must be
1064
- // set".
1074
+ // set". A signed thinking block counts as content for this protocol — a reply
1075
+ // that only thought and called a tool carries nothing else, and dropping it
1076
+ // breaks the pairing its tool result depends on.
1065
1077
  const hasText = !!(text && text.trim());
1066
1078
  const hasCalls = toolCalls.length > 0;
1067
- if (hasText || hasCalls) {
1079
+ const hasThoughtBlocks = thoughtBlocks.length > 0;
1080
+ if (hasText || hasCalls || hasThoughtBlocks) {
1068
1081
  const assistantMsg = {
1069
1082
  role: 'assistant',
1070
1083
  content: hasText ? text : null,
1071
1084
  toolCalls: hasCalls ? toolCalls : undefined,
1085
+ // Not part of the answer, never rendered from here: it is the provider's own
1086
+ // accounting of its reasoning, replayed verbatim on the next request.
1087
+ thoughtBlocks: hasThoughtBlocks ? thoughtBlocks : undefined,
1072
1088
  };
1073
1089
  // Mixin seam: llmResponse - plugins may rewrite the assistant text before it is saved.
1074
1090
  try { const out = await runPatch('llmResponse', { content: assistantMsg.content, toolCalls: assistantMsg.toolCalls }, (c) => c); if (out) { if (out.content !== undefined) assistantMsg.content = out.content; if (out.toolCalls !== undefined) assistantMsg.toolCalls = out.toolCalls; } } catch (e) { console.error('[hncode-plugin] llmResponse error:', e.message); }
package/src/animate.js CHANGED
@@ -369,3 +369,38 @@ export function framesPerChar(n, ticks = SWEEP_TICKS) {
369
369
  const BAND = bandCharsFor(n) / n;
370
370
  return (BAND * ticks) / (1 + BAND * SWEEP_TRAVEL_PAD);
371
371
  }
372
+
373
+
374
+ /**
375
+ * A slow, even breath between two colours, for a surface that is WAITING on the user.
376
+ *
377
+ * The screen has exactly one state where the user is the bottleneck: a prompt that blocks the agent until they answer
378
+ * (a tool approval, a plan review, a question). Those boxes are currently drawn in a flat border colour, which reads as
379
+ * ordinary chrome — and a reader busy in another window has no cue that the program has stopped for them.
380
+ *
381
+ * NOT the travelling light. A sweep says "work is happening", which is the opposite of the truth here: nothing is
382
+ * happening until someone presses a key. A breath is the shape for waiting.
383
+ *
384
+ * `t` is a 0..1 triangle over the cycle, so the two ends meet exactly and there is no visible seam when it repeats.
385
+ * Reduced motion collapses this to the resting colour: a surface that fades in and out is motion, and the point of
386
+ * the setting is that there is none.
387
+ *
388
+ * @param {string} rest the colour the surface rests at (an SGR foreground or background run)
389
+ * @param {string} peak the colour it breathes toward
390
+ * @param {number} phaseMs milliseconds into the cycle
391
+ * @param {number} cycleMs length of one full breath
392
+ * @param {boolean} [reduced] true to return `rest` unchanged
393
+ */
394
+ export function breatheColour(rest, peak, phaseMs, cycleMs = 2400, reduced = false) {
395
+ if (reduced || !peak) return rest;
396
+ // A triangle, not a sine: the two are indistinguishable at this speed and the triangle needs no trig per frame.
397
+ const half = cycleMs / 2;
398
+ const at = ((phaseMs % cycleMs) + cycleMs) % cycleMs;
399
+ const t = at < half ? at / half : 1 - (at - half) / half;
400
+ // The colours arrive as SGR runs, so the blend happens on the NUMBERS inside them rather than on the strings.
401
+ const a = /38;2;(\d+);(\d+);(\d+)/.exec(rest);
402
+ const b = /38;2;(\d+);(\d+);(\d+)/.exec(peak);
403
+ if (!a || !b) return rest; // a named colour, not truecolor: nothing to interpolate, so leave it alone
404
+ const mix = (i) => Math.round(Number(a[i]) + (Number(b[i]) - Number(a[i])) * t);
405
+ return `\x1b[38;2;${mix(1)};${mix(2)};${mix(3)}m`;
406
+ }
package/src/config.js CHANGED
@@ -484,6 +484,18 @@ const b = baseUrl.replace(/\/+$/, '');
484
484
  // Backwards-compat: read legacy cool_mode key if calm_mode is not set.
485
485
  : (root.calm_mode === true || root.calm_mode === 'true'
486
486
  || root.cool_mode === true || root.cool_mode === 'true'),
487
+ // UI LANGUAGE (/lang): which language the TERMINAL UI speaks. Only the strings a
488
+ // person reads are translated — command descriptions, the help panel, menu hints
489
+ // and turn states. The system prompt and everything the model reads stay English,
490
+ // because those are instructions to the model rather than text for a reader, and a
491
+ // half-translated instruction set is worse than an English one.
492
+ //
493
+ // Anything unrecognised falls back to English rather than failing the launch.
494
+ lang: (() => {
495
+ const raw = String(process.env.HNCODE_LANG || root.lang || '').trim().toLowerCase().replace('_', '-');
496
+ if (raw === 'zh' || raw.startsWith('zh-')) return 'zh';
497
+ return 'en';
498
+ })(),
487
499
  subagentModel: process.env.HNCODE_SUBAGENT_MODEL || root.subagent_model || '',
488
500
  // SECONDARY MODEL (/secondary-model): the cheap model for side work — /btw,
489
501
  // /recap and the compaction summary run on it, so a long main-context model is
@@ -1243,9 +1255,14 @@ export function effortOptions(cfg, modelKeyName) {
1243
1255
  // Token budget for a NAMED grade, on a protocol that wants a number rather than a word.
1244
1256
  //
1245
1257
  // 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`.
1258
+ // in config.toml (`efforts = ["xhigh"]`). A grade with no entry here has no budget of its
1259
+ // own to send, and the old code fell back to 8000 — which silently gave an unknown grade the
1260
+ // same strength as `medium`.
1261
+ //
1262
+ // These numbers are the grade's INTENT, not the wire value. llm.js fits the figure to the
1263
+ // request's own `max_tokens` (see anthropicThinking), because this API requires a budget
1264
+ // that leaves the reply room to be written: 32000 against a 10000 cap is a guaranteed 400,
1265
+ // which is exactly what the old mapping sent for `high` and `max`.
1249
1266
  const EFFORT_BUDGETS = { low: 2000, medium: 8000, high: 16000, max: 32000 };
1250
1267
 
1251
1268
  // Map a chosen effort to the wire value for the active protocol.
@@ -1259,12 +1276,13 @@ export function effortWire(cfg, effort) {
1259
1276
  const named = Object.prototype.hasOwnProperty.call(EFFORT_BUDGETS, effort);
1260
1277
 
1261
1278
  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.
1279
+ // A BUDGET IS REQUIRED whenever thinking is enabled on this protocol, the plain "on"
1280
+ // toggle included: `{type:'enabled'}` on its own is a 400, not a default. `on` therefore
1281
+ // asks for the neutral grade's figure and llm.js fits it to the request's output cap
1282
+ // (see anthropicThinking), so the intent survives but the number is always legal.
1265
1283
  return named
1266
1284
  ? { thinking: { type: 'enabled', budget_tokens: EFFORT_BUDGETS[effort] } }
1267
- : { thinking: { type: 'enabled' } };
1285
+ : { thinking: { type: 'enabled', budget_tokens: EFFORT_BUDGETS.medium } };
1268
1286
  }
1269
1287
 
1270
1288
  // Responses API and the OpenAI-compatible shape both take a GRADE word, and neither has
package/src/file-tree.js CHANGED
@@ -23,6 +23,7 @@
23
23
  import path from 'node:path';
24
24
  import { C } from './colors.js';
25
25
  import { visualWidth } from './term.js';
26
+ import { uiText } from './i18n.js';
26
27
 
27
28
  const ELLIPSIS = '\u2026';
28
29
  const ESC = '\x1b';
@@ -153,11 +154,11 @@ export function renderTree(input) {
153
154
 
154
155
  const total = root.children.length ? countFiles(root) : 0;
155
156
  const title = filter
156
- ? `Files matching "${filter}" — ${total} file(s)`
157
- : `Files — ${total} file(s)`;
157
+ ? uiText(`Files matching "${filter}" — ${total} file(s)`)
158
+ : uiText(`Files — ${total} file(s)`);
158
159
  // Deliberately terse: the full phrasing ("↑↓ move · →/← open/close · Enter insert path ·
159
160
  // Ctrl+O expand all · Esc close") is 71 columns and got clipped mid-word at 70.
160
- const hint = '↑↓ move · →/← open · Enter insert · Ctrl+O all · Esc close';
161
+ const hint = uiText('↑↓ move · →/← open · Enter insert · Ctrl+O all · Esc close');
161
162
 
162
163
  const lines = [];
163
164
  // The header and the hint are clamped to the panel like every other row. Unclamped, a
package/src/highlight.js CHANGED
@@ -938,17 +938,31 @@ export function langForPath(p) {
938
938
  function colorFor(kind) {
939
939
  switch (kind) {
940
940
  case 'keyword': return C.cyan;
941
+ // NUMBERS ARE NOT LITERALS, and they are not comments either.
942
+ //
943
+ // This used to return `C.heading`, the same colour `literal` gets — so `42` and `true` were one family when one is
944
+ // a value you scan for and the other is a word. Worse, on the dark theme `heading` (200,210,220) sits within about
945
+ // 30 of `comment` (184,189,191) in every channel, so a number read as dim as a comment.
946
+ //
947
+ // Orange is already the theme's "attention without alarm" accent, and it is far enough from cyan, green and the
948
+ // comment grey to be picked out at a glance.
949
+ case 'number': return C.orange;
941
950
  case 'literal': return C.heading;
942
951
  case 'string': return C.diffAddFg;
943
952
  // COMMENTS ARE DERIVED FROM THE FOREGROUND, not from the theme's grey.
944
953
  //
945
- // `C.gray` is tuned to sit quiet against the PAGE background, and in several themes it lands almost exactly on
946
- // the diff wash — dracula and tokyo came out at a brightness difference of 3 to 5, which is invisible. A comment
947
- // is the one token that has to stay readable ON the wash, so it comes from `C.comment`, which `setTheme` mixes
948
- // from the palette's foreground: quiet, but always far enough from whatever is behind it.
954
+ // `C.gray` is tuned to sit quiet against the PAGE background, and in several themes it lands almost exactly on the
955
+ // diff wash — dracula and tokyo came out at a brightness difference of 3 to 5, which is invisible. A comment is the
956
+ // one token that has to stay readable ON the wash, so it comes from `C.comment`: quiet, but always far enough from
957
+ // whatever is behind it.
949
958
  case 'comment': return C.comment;
950
- case 'number': return C.heading;
951
- case 'func': return C.cyan;
959
+ // A FUNCTION NAME IS NOT A KEYWORD.
960
+ //
961
+ // Both were `C.cyan`, which made `function` and the name after it one undifferentiated run: the reader could not
962
+ // tell the syntax from the thing being called, and a call site (`foo(x)`) read as if `foo` were built in.
963
+ // `C.spring` is the palette's second cool accent — same family as the keyword colour, so the line still reads as
964
+ // code, and far enough from it to separate the two roles.
965
+ case 'func': return C.spring;
952
966
  case 'attr': return C.orange;
953
967
  default: return '';
954
968
  }