@hncode/hncode 0.7.3 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hncode/hncode",
3
- "version": "0.7.3",
3
+ "version": "0.7.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.js CHANGED
@@ -1312,10 +1312,10 @@ const filtered = (Array.isArray(cfg.toolFilter) && cfg.toolFilter.length
1312
1312
  });
1313
1313
  return;
1314
1314
  }
1315
- // The transcript keeps the full text; the MODEL may get a bounded version
1316
- // (a spill or a preview) so one huge read cannot inflate every subsequent
1317
- // request. See tool-result.js.
1318
- const rawForModel = out.editDiff ? out.result + formatEditDiffForModel(out.editDiff) : out.result;
1315
+ // THE MODEL GETS THE TOOL'S OWN RESULT. It used to have the rendered DIFF appended as well, because an Edit
1316
+ // reported only "replaced lines 5-7" and the model could not see what it had written. The Edit now quotes
1317
+ // the file around the change itself, so appending the diff would show the same lines twice.
1318
+ const rawForModel = out.result;
1319
1319
  const shaped = toolResultLimitsEnabled()
1320
1320
  ? shapeToolResult(rawForModel, { sessionId: this.cfg.sessionId, toolCallId: tc.id })
1321
1321
  : { content: rawForModel, spilled: false };
@@ -1327,7 +1327,12 @@ const filtered = (Array.isArray(cfg.toolFilter) && cfg.toolFilter.length
1327
1327
  // output the model was handed in the step it is about to reason about.
1328
1328
  this._lastToolResultIndex = this.messages.length - 1;
1329
1329
  this.onEvent({
1330
- type: 'tool_result', id: tc.id, name: tc.name, content: out.result,
1330
+ type: 'tool_result', id: tc.id, name: tc.name,
1331
+ // THE UI GETS THE SUMMARY, NOT THE QUOTED FILE. The context lines after an Edit exist for the MODEL, so
1332
+ // it does not have to read the same region twice — the user reads the DIFF (`editDiff`) instead, which
1333
+ // already shows what changed in place. Passing the whole result drew the same lines twice, once as a
1334
+ // diff and once as a block of text.
1335
+ content: out.editDiff ? String(out.result).split('\n\n')[0] : out.result,
1331
1336
  editDiff: out.editDiff, spilled: shaped.spilled,
1332
1337
  });
1333
1338
  };
package/src/banner.js ADDED
@@ -0,0 +1,222 @@
1
+ // The startup mark: an HNCODE wordmark, drawn once when a session has nothing in it yet.
2
+ //
3
+ // WHY ALL CAPITALS. A lowercase letter needs a smaller x-height, and at bitmap sizes that means its top rows are
4
+ // blank — which shifts it against the capitals and makes the word look broken rather than typeset. One height for
5
+ // every letter is the only thing that lines up.
6
+ //
7
+ // THE ALPHABET IS BUILT FROM HALF BLOCKS. `▀` (U+2580) fills the upper half of a cell and `▄` (U+2584) the lower,
8
+ // so one terminal row carries TWO rows of the drawing and every joint is a straight edge. Full blocks and
9
+ // quadrants were tried: `█` rows read as solid slabs, and the quadrant characters carry padding on all sides so a
10
+ // row of them came out as scattered dots.
11
+ //
12
+ // AUTHORING. Each glyph is a picture, five rows of five cells, and the mark is scaled up from that. Writing it at
13
+ // 1x and multiplying is the only way to keep it correct: a hand-written bitmap at the larger size has hundreds of
14
+ // characters per letter, and one wrong one produces a letter that is malformed on screen but looks fine in source.
15
+ //
16
+ // THE SCALE IS CHOSEN PER CALL from the space available — the largest of 1, 2 and 3 that fits. A fixed 3 is 105
17
+ // columns and disappears on a terminal narrower than that, which is most of them; a fixed 1 is cramped on a wide
18
+ // one. Every cell of the 5x5 picture becomes `scale` cells.
19
+ //
20
+ // THE DROP SHADOW is the same picture offset by one cell down and one across, drawn dim. It is what makes the
21
+ // wordmark sit ON the page rather than float in it, and at this size a shadow costs one extra column and one
22
+ // extra terminal row.
23
+ const BASE = {
24
+ H: [
25
+ '#...#',
26
+ '#...#',
27
+ '#####',
28
+ '#...#',
29
+ '#...#',
30
+ ],
31
+ N: [
32
+ '#...#',
33
+ '##..#',
34
+ '#.#.#',
35
+ '#..##',
36
+ '#...#',
37
+ ],
38
+ C: [
39
+ '#####',
40
+ '#....',
41
+ '#....',
42
+ '#....',
43
+ '#####',
44
+ ],
45
+ O: [
46
+ '#####',
47
+ '#...#',
48
+ '#...#',
49
+ '#...#',
50
+ '#####',
51
+ ],
52
+ D: [
53
+ '####.',
54
+ '#...#',
55
+ '#...#',
56
+ '#...#',
57
+ '####.',
58
+ ],
59
+ E: [
60
+ '#####',
61
+ '#....',
62
+ '####.',
63
+ '#....',
64
+ '#####',
65
+ ],
66
+ };
67
+
68
+ const WORD = ['H', 'N', 'C', 'O', 'D', 'E'];
69
+ const UP = '\u2580'; // upper half
70
+ const DOWN = '\u2584'; // lower half
71
+ const BOTH = '\u2588'; // both halves
72
+ const NONE = ' ';
73
+
74
+ /** The size the mark is drawn at. Fixed: one size, chosen once, rather than four variants to keep correct. */
75
+ export const SCALE = 2;
76
+
77
+ /** How many columns the mark occupies, counting the shadow's offset on the right. */
78
+ export function bannerWidthAt(scale = SCALE) {
79
+ const s = Math.max(1, Math.round(scale) || 1);
80
+ // Five cells of ink per letter, one cell between letters, and two half-cells on the right for the shadow.
81
+ return WORD.length * 5 * s + (WORD.length - 1) * 2 + 2;
82
+ }
83
+
84
+ /** 0 when the mark does not fit at its one size, so a caller can skip it entirely. */
85
+ export function bannerScaleFor(width) {
86
+ return Number(width) >= bannerWidthAt() ? SCALE : 0;
87
+ }
88
+
89
+ /** Blow the glyphs up to `scale` and lay them side by side, as one picture of `#` and `.`. */
90
+ function buildPicture(scale) {
91
+ const s = Math.max(1, Math.round(scale) || 1);
92
+ const glyphs = WORD.map((ch) => {
93
+ const rows = [];
94
+ for (const row of BASE[ch]) {
95
+ let line = '';
96
+ for (const c of row) line += (c === '#' ? '#' : '.').repeat(s);
97
+ for (let i = 0; i < s; i++) rows.push(line);
98
+ }
99
+ return rows;
100
+ });
101
+ // ONE CHARACTER CELL BETWEEN LETTERS. The gap is in half-cells, so one cell is two of them — and it has to be
102
+ // at least that, or each letter's shadow lands on the next letter's ink.
103
+ const gap = '.'.repeat(2);
104
+ const height = glyphs[0].length;
105
+ const rows = [];
106
+ for (let r = 0; r < height; r++) {
107
+ rows.push(glyphs.map((g, i) => g[r] + (i === glyphs.length - 1 ? '' : gap)).join(''));
108
+ }
109
+ // Room on the right and at the bottom for the shadow, which is two half-cells in each direction.
110
+ const width = Math.max(...rows.map((l) => l.length)) + 2;
111
+ for (let i = 0; i < rows.length; i++) rows[i] = rows[i].padEnd(width, '.');
112
+ return rows;
113
+ }
114
+
115
+ /** The mark's picture at `scale`, plus its shadow, as one grid of `#` (ink), `s` (shadow) and `.`. */
116
+ function withShadow(picture, shadowRows, shadowCols) {
117
+ const height = picture.length + shadowRows;
118
+ const width = Math.max(...picture.map((l) => l.length)) + shadowCols;
119
+ const grid = [];
120
+ for (let r = 0; r < height; r++) {
121
+ const line = [];
122
+ for (let c = 0; c < width; c++) {
123
+ const ink = picture[r] && picture[r][c] === '#';
124
+ const sh = picture[r - shadowRows] && picture[r - shadowRows][c - shadowCols] === '#';
125
+ // Ink wins where they overlap, so the shadow reads as being BEHIND the letter.
126
+ line.push(ink ? '#' : sh ? 's' : '.');
127
+ }
128
+ grid.push(line);
129
+ }
130
+ return grid;
131
+ }
132
+
133
+ /** Fold two grid rows into one terminal row, where the character says which colour runs. */
134
+ function foldRow(upper, lower) {
135
+ let out = '';
136
+ for (let c = 0; c < upper.length; c++) {
137
+ const u = upper[c];
138
+ const d = lower ? lower[c] : '.';
139
+ // A cell is described by the pair (upper, lower). `#` means ink, `s` shadow, `.` empty.
140
+ out += u + d;
141
+ }
142
+ return out;
143
+ }
144
+
145
+ /**
146
+ * The mark as terminal rows, each a string of cells.
147
+ *
148
+ * A cell is returned as a two-character token naming its halves so the painter can colour the ink and the shadow
149
+ * differently: `##` both ink, `#.` ink above only, `.#` ink below only, `ss`/`s.`/`.s` the same for shadow, and
150
+ * `..` empty. `bannerLines` turns these into the actual block characters.
151
+ */
152
+ export function bannerCells(scale = SCALE) {
153
+ const picture = buildPicture(scale);
154
+ const s = Math.max(1, Math.round(scale) || 1);
155
+ // THE SHADOW IS ALWAYS ONE CHARACTER DOWN AND ONE ACROSS — two half-cells, whatever the scale.
156
+ //
157
+ // A character cell is two half-cells by definition, so this offset is the same at 1x, 2x and 3x. What changes is
158
+ // the STROKE: at 1x one character wide, at 3x three. The ratio is what makes the shadow read as an edge — at
159
+ // 1x the shadow is as wide as the stroke, which is why that size looked right, and at 2x it is half as wide.
160
+ //
161
+ // Halving the offset per scale would restore the ratio but put the shadow inside the stroke, where the ink covers
162
+ // it. Keeping one full character keeps it BESIDE the stroke, which is the only thing that stays legible.
163
+ const grid = withShadow(picture, 2, 2);
164
+ const out = [];
165
+ for (let r = 0; r < grid.length; r += 2) out.push(foldRow(grid[r], grid[r + 1]));
166
+ return out;
167
+ }
168
+
169
+ /** The mark as plain rows at a given scale — no colour, for tests and callers that only want the shape. */
170
+ export function bannerShape(scale = SCALE) {
171
+ return bannerCells(scale).map((row) => {
172
+ let line = '';
173
+ for (let i = 0; i < row.length; i += 2) {
174
+ const u = row[i];
175
+ const d = row[i + 1];
176
+ const ink = u === '#' || d === '#';
177
+ if (!ink) { line += NONE; continue; }
178
+ line += u === '#' && d === '#' ? BOTH : u === '#' ? UP : DOWN;
179
+ }
180
+ return line;
181
+ });
182
+ }
183
+
184
+ /** The width the mark needs at the largest scale, for callers that only want to know whether it fits at all. */
185
+ export const BANNER_WIDTH = bannerWidthAt(SCALE);
186
+
187
+ /**
188
+ * The lines to draw, with the ink painted in `paint` and the shadow in `shadow`.
189
+ *
190
+ * @param {number} width The space available, in columns. The scale is reduced to fit; when even 1x does not fit
191
+ * the mark is DROPPED rather than truncated — half a wordmark reads as a rendering bug, and the session works
192
+ * fine without it.
193
+ * @param {(s: string) => string} paint Applies the accent colour to the letters.
194
+ * @param {(s: string) => string} [shadow] Applies the shadow colour. Without it the shadow is drawn as ink.
195
+ * @returns {string[]} rows, or `[]` when they do not fit.
196
+ */
197
+ export function bannerLines(width, paint, shadow) {
198
+ const scale = bannerScaleFor(width);
199
+ if (!scale) return [];
200
+ const dim = typeof shadow === 'function' ? shadow : paint;
201
+ return bannerCells(scale).map((row) => {
202
+ let line = '';
203
+ for (let i = 0; i < row.length; i += 2) {
204
+ const u = row[i];
205
+ const d = row[i + 1];
206
+ const isInk = u === '#' || d === '#';
207
+ const isShadow = !isInk && (u === 's' || d === 's');
208
+ let ch;
209
+ if (isInk) ch = u === '#' && d === '#' ? BOTH : u === '#' ? UP : DOWN;
210
+ else if (isShadow) ch = u === 's' && d === 's' ? BOTH : u === 's' ? UP : DOWN;
211
+ else { line += NONE; continue; }
212
+ line += isInk ? paint(ch) : dim(ch);
213
+ }
214
+ return line;
215
+ });
216
+ }
217
+
218
+ /** How tall the mark is at the largest scale that fits, for layout maths that runs before the text exists. */
219
+ export function bannerHeight(width) {
220
+ const scale = bannerScaleFor(width);
221
+ return scale ? bannerCells(scale).length : 0;
222
+ }
package/src/colors.js CHANGED
@@ -214,7 +214,28 @@ export const C = {
214
214
  muted: '\x1b[90m',
215
215
  teal: TEAL,
216
216
  cyan: CYAN,
217
- blue: BLUE,
217
+ // The mark's shadow: the same cyan at 40% brightness. `dim` (SGR 2) is applied by the TERMINAL and most render
218
+ // it barely darker; `teal` is only ~15% off `cyan`. Neither reads as a shadow behind the letters.
219
+ cyanDeep: rgb(0, 86, 102),
220
+ // The startup heading: the grey the annotations use, lifted towards white. The wordmark above it owns the cyan,
221
+ // so the name under it is a lighter neutral rather than a second colour competing with the mark.
222
+ heading: rgb(200, 210, 220),
223
+ // DIFF COLOURS ARE DERIVED FROM THE THEME, not fixed.
224
+ //
225
+ // A diff paints two layers: the whole changed LINE gets a wash, and the words that actually differ get a
226
+ // stronger one. Those have to sit on THIS theme's background — the Islands Dark tints read as a warm grey on
227
+ // gruvbox and as nothing at all on `light`. `setTheme` recomputes all four from the theme's own `green`, `red`
228
+ // and `bg`, so switching themes recolours the diff with everything else. The values here are the dark defaults,
229
+ // used before any theme is applied.
230
+ diffAddBg: brgb(34, 58, 38),
231
+ diffAddWordBg: brgb(52, 96, 58),
232
+ diffDelBg: brgb(74, 32, 34),
233
+ diffDelWordBg: brgb(112, 44, 48),
234
+ diffAddFg: rgb(133, 208, 143),
235
+ diffDelFg: rgb(255, 176, 168),
236
+ // A code comment. `setTheme` mixes it from the palette's foreground towards its background, so it is quiet without
237
+ // disappearing — `C.gray` is tuned for the page and vanishes on a diff wash in several themes.
238
+ comment: '\x1b[90m',
218
239
  fg: FG,
219
240
  bg: BG,
220
241
  bgTeal: brgb(0, 184, 219),
@@ -426,6 +447,34 @@ export function setTheme(name) {
426
447
  } else {
427
448
  C.branch = TRUECOLOR ? rgb(255, 219, 110) : '\x1b[38;5;222m';
428
449
  }
450
+ // DIFF TINTS, mixed from this theme's own green/red towards its background.
451
+ //
452
+ // A line wash is a WEAK mix and a word wash a STRONGER one of the same pair: weak enough that ordinary text on it
453
+ // still reads as text, strong enough that the block is visible without reading it. Mixing towards `t.bg` rather
454
+ // than towards black is what makes a light theme work — a dark red wash on white is a black bar with letters in
455
+ // it, while a pale red is a highlighter mark.
456
+ const mix = (a, b, k) => a.map((v, i) => Math.round(v * k + b[i] * (1 - k)));
457
+ const green = t.green || [120, 200, 120];
458
+ const red = t.red || [230, 80, 80];
459
+ // ABOUT HALF. Lower mixes disappear into a dark page — the wash has to be obvious without being read, and at
460
+ // 16% an added block looked like ordinary text with a faint tint. Light backgrounds need slightly more still,
461
+ // because the same distance in RGB is a smaller difference next to white.
462
+ const isLight = t.bg && t.bg[0] > 128;
463
+ const line = isLight ? 0.52 : 0.46;
464
+ const word = isLight ? 0.68 : 0.62;
465
+ C.diffAddBg = brgb(...mix(green, t.bg, line));
466
+ C.diffAddWordBg = brgb(...mix(green, t.bg, word));
467
+ C.diffDelBg = brgb(...mix(red, t.bg, line));
468
+ C.diffDelWordBg = brgb(...mix(red, t.bg, word));
469
+ // The sign and the text of a changed line are the same hue as its wash, pulled towards the theme's own foreground
470
+ // so they read ON that wash — not the theme's plain green/red, which is tuned for the page background.
471
+ C.diffAddFg = rgb(...mix(green, t.fg, 0.55));
472
+ C.diffDelFg = rgb(...mix(red, t.fg, 0.55));
473
+
474
+ // A comment: the palette's foreground, pulled most of the way towards its background so it reads as quiet. A dark
475
+ // page can afford a looser mix; a light one cannot — solar's foreground is already a muted blue-grey, and at the
476
+ // dark theme's ratio its comments came within 8 of the removal wash.
477
+ C.comment = rgb(...mix(t.fg, t.bg, isLight ? 0.86 : 0.72));
429
478
 
430
479
  return true;
431
480
  }
package/src/config.js CHANGED
@@ -122,6 +122,32 @@ export function writeMemoryRaw(scope, workspace, text) {
122
122
  return file;
123
123
  }
124
124
 
125
+ /**
126
+ * Drop every note whose text contains `needle`, case-insensitively.
127
+ *
128
+ * A NOTE IS ONE LINE starting with `- `, so removal is line-based: the whole line goes, not a substring of it. A
129
+ * rule that is no longer true is worse than no rule — it keeps steering later sessions — so this has to be able to
130
+ * delete, not only append.
131
+ *
132
+ * Returns `{ removed, kept }` so the caller can report what happened, and 0 when nothing matched: a note that was
133
+ * never there must not read as one that was deleted.
134
+ */
135
+ export function removeMemory(scope, workspace, needle) {
136
+ const text = String(needle == null ? '' : needle).trim().toLowerCase();
137
+ if (!text) return { removed: 0, kept: 0 };
138
+ const lines = readMemoryRaw(scope, workspace).split('\n');
139
+ const keptLines = [];
140
+ let removed = 0;
141
+ for (const line of lines) {
142
+ if (line.startsWith('- ') && line.toLowerCase().includes(text)) { removed++; continue; }
143
+ keptLines.push(line);
144
+ }
145
+ if (!removed) return { removed: 0, kept: 0 };
146
+ const kept = keptLines.filter((l) => l.trim()).length;
147
+ writeMemoryRaw(scope, workspace, keptLines.join('\n'));
148
+ return { removed, kept };
149
+ }
150
+
125
151
  // Append one note to a scope's memory, creating the file if needed. Appending
126
152
  // (rather than replacing) is what a memory tool needs: the agent records a single
127
153
  // learning and must not have to re-emit everything it knew before.
@@ -391,13 +417,25 @@ const b = baseUrl.replace(/\/+$/, '');
391
417
  const presencePenalty = samplingOn
392
418
  ? numOrNull(process.env.HNCODE_PRESENCE_PENALTY ?? root.presence_penalty, -2, 2)
393
419
  : null;
394
- const reasoning = process.env.HNCODE_REASONING ? /^(1|true|yes)$/i.test(process.env.HNCODE_REASONING) : !!root.reasoning;
420
+ // THE THINKING GRADE, read back from config.toml.
421
+ //
422
+ // `/effort` wrote this key and nothing read it: `resolveConfig` had no `effort` field at all, so a grade chosen
423
+ // in one session was gone by the next launch — the setting persisted in the file and was simply never loaded.
424
+ // `effort = "off"` means "reasoning on, no grade", which is what the empty string means to the callers.
425
+ const effortRaw = process.env.HNCODE_EFFORT != null ? String(process.env.HNCODE_EFFORT) : root.effort;
426
+ const effort = effortRaw == null || String(effortRaw).toLowerCase() === 'off' ? '' : String(effortRaw);
427
+ // A GRADE IS A REASONING SETTING. `effort = "high"` in the file says the model should think, whether or not
428
+ // `reasoning` was also written — that is what `/effort high` means, and reading the two keys independently left a
429
+ // session with a grade but `reasoning` false, so nothing was ever requested.
430
+ const reasoning = process.env.HNCODE_REASONING
431
+ ? /^(1|true|yes)$/i.test(process.env.HNCODE_REASONING)
432
+ : (!!root.reasoning || !!effort);
395
433
  const allowExternal = process.env.HNCODE_ALLOW_EXTERNAL === '1' || !!root.tool_allow_external_paths;
396
434
 
397
435
  return {
398
436
  model, provider: providerName, innerModel,
399
437
  baseUrl: b, endpoint, apiKey, protocol,
400
- maxContextTokens: maxContext, maxOutputTokens: maxOutput, reasoning,
438
+ maxContextTokens: maxContext, maxOutputTokens: maxOutput, reasoning, effort,
401
439
  // Sampling. `undefined`/null means "do not send it", which is what lets a provider apply its own
402
440
  // default — and what keeps a rejection from becoming a hard failure.
403
441
  temperature: temperature == null ? undefined : temperature,
@@ -535,6 +573,12 @@ const b = baseUrl.replace(/\/+$/, '');
535
573
  // because the two are a matter of taste and the cost is one branch.
536
574
  shimmerEdge: String(root.shimmer_edge || process.env.HNCODE_SHIMMER_EDGE || 'cosine').toLowerCase() === 'linear'
537
575
  ? 'linear' : 'cosine',
576
+ // TITLE DISPLAY (`title_display`): the band at the top of the screen. On by default — a session's name is
577
+ // how it is recognised in a list and on the window — so this is an opt-out for a terminal with very few rows.
578
+ titleDisplay: !(root.title_display === false || root.title_display === 'false'),
579
+ // AUTO TITLE (`auto_title`): whether the model names the session from its first message. Off means the name
580
+ // is only ever what `/title` (or the title band) sets.
581
+ autoTitle: !(root.auto_title === false || root.auto_title === 'false'),
538
582
  // WEB SEARCH KEYS (`web_search_api_key`).
539
583
  //
540
584
  // Keyless mode is rate-limited BY IP, so a shared or busy address gets refusals that look like "search is