@hncode/hncode 0.7.4 → 0.7.6
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/README.md +24 -2
- package/README_CN.md +24 -2
- package/package.json +1 -1
- package/src/colors.js +29 -0
- package/src/hooks.js +44 -7
- package/src/tui.js +198 -94
package/README.md
CHANGED
|
@@ -6,9 +6,31 @@
|
|
|
6
6
|
|
|
7
7
|
English | [简体中文](https://github.com/NiceHello666/HNCode/blob/main/README_CN.md) | [Wiki](https://github.com/NiceHello666/HNCode/blob/main/README_WIKI.md)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
A coding agent that lives in your terminal. Point it at a repo, describe the change, and it reads the files, edits them and runs the tests — inside a raw-TTY renderer that stays correct on Windows Terminal, where most terminal UIs garble.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Why this one
|
|
12
|
+
|
|
13
|
+
**Raw terminal, done properly.** No UI library sits between the agent and the terminal. The renderer writes the escape sequences itself and keeps its own cell buffer, so Windows Terminal — where blessed-style libraries garble on a non-TTY stream — gets the same layout as everything else. Capabilities are probed live: synchronized output, the Kitty keyboard protocol, image protocols, and a theme that follows the detected background.
|
|
14
|
+
|
|
15
|
+
**Fast enough to type against.** Markdown is rendered block-by-block with a cache, so a streaming reply does not re-parse the whole transcript on every frame. Only changed cells are repainted. Message token counts are memoized per message and kept as a rolling total; the context gauge no longer re-walks a long history several times per turn. It makes a visible difference once a session has read a few hundred files.
|
|
16
|
+
|
|
17
|
+
**Built to be looked at.** Syntax-highlighted diffs and file reads, line-level red/green washes that survive a mouse selection, block comments that stay grey, wide CJK glyphs, a scrollbar with sub-cell resolution, LaTeX typeset as a bitmap with Unicode and source fallbacks, Mermaid fences drawn as diagrams. `/raw` shows the model's reply verbatim when you need to tell a bad answer from a bad render.
|
|
18
|
+
|
|
19
|
+
**Everything is in this repository.** No runtime dependencies. The token estimator, the RFC6455 WebSocket behind `/web`, the image encoder, the syntax highlighter and the plugin/skill managers are all here, readable and patchable. `npm install -g @hncode/hncode` installs exactly this code.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## A session
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
$ npm install -g @hncode/hncode
|
|
27
|
+
$ cd my-project
|
|
28
|
+
$ hncode
|
|
29
|
+
|
|
30
|
+
> the tests fail after the config change — find out why and fix it
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The agent reads the config and the failing test, runs the suite, edits the file, and runs it again. Every tool call appears with its own syntax-highlighted diff, so the change is on screen before it happens.
|
|
12
34
|
|
|
13
35
|
---
|
|
14
36
|
|
package/README_CN.md
CHANGED
|
@@ -6,9 +6,31 @@
|
|
|
6
6
|
|
|
7
7
|
[English](https://github.com/NiceHello666/HNCode/blob/main/README.md) | 简体中文 | [Wiki](https://github.com/NiceHello666/HNCode/blob/main/README_WIKI_CN.md)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
一个住在终端里的编程 agent。指到某个仓库、说清楚要改什么,它会读文件、改文件、跑测试,全过程都在一个原始终端渲染器里完成,包括 Windows Terminal 上那些会让多数终端界面花屏的场景。
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## 为什么用它
|
|
12
|
+
|
|
13
|
+
**原始终端,做对了。** agent 和终端之间没有 UI 库。渲染器自己写终端序列、自己维护单元格缓冲,所以 blessed 一类库会在非 TTY 流上花屏的 Windows Terminal,也能拿到和别处一致的排版。能力是实时探测的:同步输出、Kitty 键盘协议、图片协议,以及跟着背景色走的主题。
|
|
14
|
+
|
|
15
|
+
**打字时跟得上。** Markdown 按块渲染并带缓存,流式回复不用每一帧都重新解析整份记录;重绘只写变化的单元格。消息的 token 数按对象记忆化,并维护滚动总量,context 计量不再在每一轮里反复遍历长历史。读过几百个文件之后,这个差别肉眼可见。
|
|
16
|
+
|
|
17
|
+
**为「看代码」而做。** diff 和文件读取带语法高亮,行级红绿底色在鼠标选区下仍然保留,块注释整段灰色,CJK 宽字符对齐,滚动条有亚单元格精度,LaTeX 排版成位图并带 Unicode 与源码回退,Mermaid 画成图。`/raw` 可以逐字看模型的原始回复,用来分辨是回答本身不对还是渲染不对。
|
|
18
|
+
|
|
19
|
+
**全部就在这个仓库里。** 零运行时依赖:token 估算器、`/web` 背后的 RFC6455 WebSocket、图片编码器、语法高亮器、插件与 skill 管理器都在这里,能读也能改。`npm install -g @hncode/hncode` 装的就是这份代码。
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 一次会话
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
$ npm install -g @hncode/hncode
|
|
27
|
+
$ cd my-project
|
|
28
|
+
$ hncode
|
|
29
|
+
|
|
30
|
+
> 改完配置之后测试挂了,查清楚原因并修好
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
它会读配置和失败的测试,跑一遍测试,改文件,再跑一遍。每次工具调用都带着自己的语法高亮 diff,改动发生之前就已经在屏幕上。
|
|
12
34
|
|
|
13
35
|
---
|
|
14
36
|
|
package/package.json
CHANGED
package/src/colors.js
CHANGED
|
@@ -267,6 +267,13 @@ export const C = {
|
|
|
267
267
|
// is rgb(48,48,48) = #303030 — clearly lifted off a near-black terminal without
|
|
268
268
|
// washing the text out. Truecolor gets `#2e2e2e`, the same shade written exactly.
|
|
269
269
|
bgPanel: TRUECOLOR ? '\x1b[48;2;46;46;46m' : '\x1b[48;5;236m',
|
|
270
|
+
// The code-surface background, set by setTheme from the theme's own page colour. A placeholder until then, so
|
|
271
|
+
// code drawn before the first setTheme still has a surface.
|
|
272
|
+
codeBg: TRUECOLOR ? '\x1b[48;2;12;20;26m' : '\x1b[48;5;233m',
|
|
273
|
+
// The terminal-surface background, set by setTheme from the theme's page colour. Placeholder until then.
|
|
274
|
+
termBg: TRUECOLOR ? '\x1b[48;2;0;14;21m' : '\x1b[48;5;234m',
|
|
275
|
+
// The composer's neutral-grey surface. Placeholder until setTheme runs.
|
|
276
|
+
composerBg: TRUECOLOR ? '\x1b[48;2;44;44;46m' : '\x1b[48;5;237m',
|
|
270
277
|
border: BORDER,
|
|
271
278
|
red: '\x1b[91m',
|
|
272
279
|
green: '\x1b[92m',
|
|
@@ -471,6 +478,28 @@ export function setTheme(name) {
|
|
|
471
478
|
C.diffAddFg = rgb(...mix(green, t.fg, 0.55));
|
|
472
479
|
C.diffDelFg = rgb(...mix(red, t.fg, 0.55));
|
|
473
480
|
|
|
481
|
+
// THE CODE-SURFACE BACKGROUND, one step off the page. Read rows, Write previews and diff CONTEXT lines sit on
|
|
482
|
+
// it; diff `+`/`-` rows keep their green/red wash on top. Mixed from this theme's own page colour rather than
|
|
483
|
+
// a fixed grey, so a light theme gets a light code surface and a dark one a dark one.
|
|
484
|
+
//
|
|
485
|
+
// The step depends on WHICH SIDE the page is. On a dark page the surface is one step LIGHTER (mix very little
|
|
486
|
+
// foreground in); on a light page it is one step DARKER (mix a little foreground in). Same small distance either
|
|
487
|
+
// way, because a code region must read as "same screen, slightly recessed", not as a panel.
|
|
488
|
+
C.codeBg = brgb(...mix(t.bg, t.fg, isLight ? 0.93 : 0.94));
|
|
489
|
+
// THE TERMINAL-SURFACE BACKGROUND: the same small step on the OTHER side of the page, so the ordering holds on
|
|
490
|
+
// both kinds of theme — page < terminal < code on a dark one, terminal < code < page on a light one. Bash output
|
|
491
|
+
// and the shell-mode echo sit on it: a command reads as "a terminal ran this" without becoming a black band,
|
|
492
|
+
// which is what a deeper well looked like — a hole in the screen rather than a region of it.
|
|
493
|
+
//
|
|
494
|
+
// Towards BLACK on a dark theme and towards the foreground on a light one: mixing a dark page further towards its
|
|
495
|
+
// own foreground would make it lighter, which is `codeBg`'s job, not this one.
|
|
496
|
+
C.termBg = brgb(...mix(t.bg, isLight ? t.fg : [0, 0, 0], isLight ? 0.88 : 0.94));
|
|
497
|
+
// THE COMPOSER SURFACE: a NEUTRAL GREY, not a tint of the page. The input area is the one region that should not
|
|
498
|
+
// follow the theme's hue — a cyan-tinted box on a dark-teal page reads as "more page", while a grey one reads as
|
|
499
|
+
// an input field. Neutral means equal RGB, so it is written as a grey and adjusted only for light vs dark. A
|
|
500
|
+
// theme may override it with its own `composer` triple.
|
|
501
|
+
C.composerBg = brgb(...(t.composer || (isLight ? [232, 232, 232] : [44, 44, 46])));
|
|
502
|
+
|
|
474
503
|
// A comment: the palette's foreground, pulled most of the way towards its background so it reads as quiet. A dark
|
|
475
504
|
// page can afford a looser mix; a light one cannot — solar's foreground is already a muted blue-grey, and at the
|
|
476
505
|
// dark theme's ratio its comments came within 8 of the removal wash.
|
package/src/hooks.js
CHANGED
|
@@ -47,15 +47,41 @@ export const HOOK_EVENTS = [
|
|
|
47
47
|
'SessionEnd',
|
|
48
48
|
'UserPromptSubmit',
|
|
49
49
|
'PreToolUse',
|
|
50
|
+
'PermissionRequest',
|
|
50
51
|
'PostToolUse',
|
|
51
52
|
'PostToolUseFailure',
|
|
53
|
+
'FileChanged',
|
|
52
54
|
'Stop',
|
|
55
|
+
'SubagentStart',
|
|
53
56
|
'SubagentStop',
|
|
54
57
|
'PreCompact',
|
|
55
58
|
'PostCompact',
|
|
56
59
|
'Notification',
|
|
60
|
+
'ConfigChange',
|
|
61
|
+
'CwdChanged',
|
|
57
62
|
];
|
|
58
63
|
|
|
64
|
+
/** What each event means, shown by /hooks so the panel is a reference rather than a bare list of names. */
|
|
65
|
+
export const HOOK_EVENT_HINTS = {
|
|
66
|
+
SessionStart: 'a session opens or resumes',
|
|
67
|
+
SessionEnd: 'a session is closing',
|
|
68
|
+
UserPromptSubmit: 'before your prompt is sent',
|
|
69
|
+
PreToolUse: 'before a tool runs; can block it',
|
|
70
|
+
PermissionRequest: 'a tool needs your approval',
|
|
71
|
+
PostToolUse: 'after a tool succeeds',
|
|
72
|
+
PostToolUseFailure: 'after a tool fails',
|
|
73
|
+
FileChanged: 'after a file is written or edited',
|
|
74
|
+
Stop: 'the model finishes a turn',
|
|
75
|
+
SubagentStart: 'a subagent is spawned',
|
|
76
|
+
SubagentStop: 'a subagent finishes',
|
|
77
|
+
PreCompact: 'before history is summarized',
|
|
78
|
+
PostCompact: 'after history is summarized',
|
|
79
|
+
Notification: 'the app needs your attention',
|
|
80
|
+
ConfigChange: 'a setting or config file changes',
|
|
81
|
+
CwdChanged: 'the working directory changes',
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
|
|
59
85
|
// A hook that hangs must not hang the agent. 60s is generous for a formatter or
|
|
60
86
|
// a lint pass and still bounded.
|
|
61
87
|
export const HOOK_TIMEOUT_MS = 60 * 1000;
|
|
@@ -221,7 +247,12 @@ export async function runShellHooks(config, event, payload, cwd) {
|
|
|
221
247
|
// ran after reads and searches too.
|
|
222
248
|
const isToolEvent = event === 'PreToolUse' || event === 'PostToolUse' || event === 'PostToolUseFailure';
|
|
223
249
|
const results = [];
|
|
224
|
-
for (const
|
|
250
|
+
for (const raw of list) {
|
|
251
|
+
// A hook entry can arrive from a CONFIG FILE (which fills in the defaults) or from a caller that built it by
|
|
252
|
+
// hand — a test, a plugin, or one of the TUI-side notifications. The timeout must exist in both cases: an
|
|
253
|
+
// undefined one made setTimeout fire at once and reported "timed out after NaNs" without ever running the
|
|
254
|
+
// command.
|
|
255
|
+
const entry = { ...raw, timeoutMs: Number.isFinite(raw.timeoutMs) ? raw.timeoutMs : HOOK_TIMEOUT_MS };
|
|
225
256
|
if (isToolEvent && !matcherApplies(entry.matcher, payload && payload.toolName)) continue;
|
|
226
257
|
const r = await runHookCommand(entry, event, payload, cwd);
|
|
227
258
|
results.push({ entry, ...r });
|
|
@@ -239,19 +270,25 @@ export async function runShellHooks(config, event, payload, cwd) {
|
|
|
239
270
|
}
|
|
240
271
|
|
|
241
272
|
// Human-readable summary for /hooks.
|
|
242
|
-
|
|
273
|
+
//
|
|
274
|
+
// EVERY EVENT IS LISTED, including the ones with nothing configured. The old version printed a single
|
|
275
|
+
// "No hooks configured." line when the config was empty, which told the user nothing about what COULD be hooked
|
|
276
|
+
// and left the panel almost blank. Listing the full set is what makes the screen a reference: a reader sees the
|
|
277
|
+
// eleven events, which of them are active, and where the files live, without having to read the docs first.
|
|
278
|
+
export function describeHooks(config, workspace) {
|
|
243
279
|
const hooks = (config && config.hooks) || {};
|
|
244
280
|
const lines = [];
|
|
245
|
-
const total =
|
|
246
|
-
|
|
281
|
+
const total = HOOK_EVENTS.reduce((a, ev) => a + ((hooks[ev] || []).length), 0);
|
|
282
|
+
lines.push(`${total} hook${total === 1 ? '' : 's'} configured across ${HOOK_EVENTS.length} events.`, '');
|
|
247
283
|
for (const ev of HOOK_EVENTS) {
|
|
248
|
-
const list = hooks[ev];
|
|
249
|
-
|
|
250
|
-
lines.push(`${ev}
|
|
284
|
+
const list = hooks[ev] || [];
|
|
285
|
+
const hint = HOOK_EVENT_HINTS[ev] || '';
|
|
286
|
+
lines.push(`${ev}${hint ? ` — ${hint}` : ''}: ${list.length ? `${list.length} configured` : '(none)'}`);
|
|
251
287
|
for (const e of list) {
|
|
252
288
|
lines.push(` ${e.matcher ? `[${e.matcher}] ` : ''}${e.command}`);
|
|
253
289
|
lines.push(` (${e.source})`);
|
|
254
290
|
}
|
|
255
291
|
}
|
|
292
|
+
lines.push('', `Global file: ${globalHooksFile()}`, `Project file: ${projectHooksFile(workspace || process.cwd())}`);
|
|
256
293
|
return lines;
|
|
257
294
|
}
|
package/src/tui.js
CHANGED
|
@@ -1543,7 +1543,9 @@ function paintCode(text, lang, bg, inComment = false) {
|
|
|
1543
1543
|
// whole body inside one token, so it drew with no wash at all while the code below it was washed, and the block
|
|
1544
1544
|
// looked striped. Seeding the background at the front covers that first run; the replacement covers every run
|
|
1545
1545
|
// after it, because each token closes with a reset that would otherwise drop back to the page background.
|
|
1546
|
-
|
|
1546
|
+
// ESC[39m, NOT ESC[0m: a bare reset clears the background too, and the row's wash must survive past the last
|
|
1547
|
+
// token. The final glyph is still inside the coloured run, so nothing is left over to clear.
|
|
1548
|
+
return { text: bg + raw.replace(/\x1b\[0m/g, `\x1b[0m${bg}`) + '\x1b[39m', inComment: result.inComment };
|
|
1547
1549
|
}
|
|
1548
1550
|
|
|
1549
1551
|
/**
|
|
@@ -2756,11 +2758,17 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2756
2758
|
const MAX_RUN_LINES = expanded ? Infinity : 8;
|
|
2757
2759
|
const shown = rawLines.slice(-MAX_RUN_LINES); // running: show the newest output
|
|
2758
2760
|
if (rawLines.length > MAX_RUN_LINES) {
|
|
2759
|
-
|
|
2761
|
+
const more = col(`… ${rawLines.length - MAX_RUN_LINES} earlier line(s)`, C.gray);
|
|
2762
|
+
out.push({ text: C.termBg + fitAnsi(more.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}`), bodyW) + C.bgReset, ind: indent, raw: true });
|
|
2760
2763
|
}
|
|
2764
|
+
// THE TERMINAL SURFACE APPLIES WHILE IT RUNS TOO, not only once the result lands. The row is the same thing
|
|
2765
|
+
// before and after — a command's output — so switching its background on completion made the block jump as
|
|
2766
|
+
// the call finished.
|
|
2761
2767
|
for (const ln of shown) {
|
|
2762
2768
|
for (const t of (ln === '' ? [''] : wrapWords(ln, bodyW))) {
|
|
2763
|
-
|
|
2769
|
+
const painted = col(t, C.gray);
|
|
2770
|
+
const surfaced = painted.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}`);
|
|
2771
|
+
out.push({ text: C.termBg + fitAnsi(surfaced, bodyW) + C.bgReset, ind: indent, raw: true });
|
|
2764
2772
|
}
|
|
2765
2773
|
}
|
|
2766
2774
|
}
|
|
@@ -2822,13 +2830,15 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2822
2830
|
// and letting it through at full width made the terminal wrap it itself — which pushes every later row down
|
|
2823
2831
|
// by one and desynchronises the frame, so the screen scrolled while the file was still arriving.
|
|
2824
2832
|
const room = Math.max(1, width - visualCol(indent) - num.length - 1);
|
|
2833
|
+
// The whole preview sits on the CODE SURFACE, number included, so the block reads as one recessed field.
|
|
2825
2834
|
if (!writeLang) {
|
|
2826
|
-
out.push({ text: col(`${num} ${fitAnsi(ln, room)}
|
|
2835
|
+
out.push({ text: C.codeBg + col(`${num} ${fitAnsi(ln, room)}`.replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`), C.gray) + C.bgReset, ind: i === 0 ? '↳ ' : indent, raw: true });
|
|
2827
2836
|
return;
|
|
2828
2837
|
}
|
|
2829
2838
|
const painted = paintCode(ln, writeLang, '', writeInComment);
|
|
2830
2839
|
writeInComment = painted.inComment;
|
|
2831
|
-
|
|
2840
|
+
const writeRow = (col(num + ' ', C.gray) + fitAnsi(painted.text, room)).replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`);
|
|
2841
|
+
out.push({ text: C.codeBg + writeRow + C.bgReset, ind: i === 0 ? '↳ ' : indent, raw: true });
|
|
2832
2842
|
});
|
|
2833
2843
|
const shown = Math.min(lines.length, MAX);
|
|
2834
2844
|
if (totalLines > shown) out.push({ text: col(`… ${totalLines - shown} more lines, ctrl+o to expand`, C.gray), ind: indent, raw: true });
|
|
@@ -2931,6 +2941,11 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2931
2941
|
// recolouring the transcript, resetting styles mid-row, moving the cursor or
|
|
2932
2942
|
// clearing the screen over the composer.
|
|
2933
2943
|
const rawLines = sanitizeText(msg.text).replace(/\r\n/g, '\n').split('\n');
|
|
2944
|
+
// A TAB counts as ZERO columns in our width maths but advances to the next tab stop in a real terminal.
|
|
2945
|
+
// A row containing one was therefore padded short and the terminal kept the old frame's glyphs in the gap —
|
|
2946
|
+
// the "residue" under tool output. Read rows are the exception: their first tab is the line-number separator
|
|
2947
|
+
// and is handled in the Read branch below, where the CONTENT half is expanded too.
|
|
2948
|
+
if (!msg.readPath) for (let k = 0; k < rawLines.length; k++) rawLines[k] = expandTabs(rawLines[k]);
|
|
2934
2949
|
// Trim blank lines at BOTH ends: commands typically emit a trailing
|
|
2935
2950
|
// newline, and some tools emit a leading one. A stray blank line would
|
|
2936
2951
|
// render as a lone "↳ " with no content.
|
|
@@ -2993,10 +3008,12 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2993
3008
|
|
|
2994
3009
|
if (!lineBg) {
|
|
2995
3010
|
// CONTEXT LINES ARE CODE TOO. They are the most of a diff and the part a reader scans to place the
|
|
2996
|
-
// change, so they get the same highlighter
|
|
3011
|
+
// the change, so they get the same highlighter, on the CODE SURFACE rather than the raw page — a changed
|
|
3012
|
+
// block sits on one recessed field. The +/- rows around it keep their green/red wash.
|
|
2997
3013
|
const ctxPainted = paintCode(text, d.lang, '', inComment);
|
|
2998
3014
|
inComment = ctxPainted.inComment;
|
|
2999
|
-
|
|
3015
|
+
const ctxRow = (lead + ctxPainted.text).replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`);
|
|
3016
|
+
diffRows.push({ text: C.codeBg + fitAnsi(ctxRow, bodyW) + C.bgReset, ind: cont, raw: true });
|
|
3000
3017
|
emitted++;
|
|
3001
3018
|
continue;
|
|
3002
3019
|
}
|
|
@@ -3007,7 +3024,9 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
3007
3024
|
inComment = painted.inComment;
|
|
3008
3025
|
const used = visualCol(`${no} ${mark} `) + visualCol(painted.text);
|
|
3009
3026
|
const pad = ' '.repeat(Math.max(0, bodyW - used));
|
|
3010
|
-
|
|
3027
|
+
// The padding is INSIDE the wash, so it must not end with a bare reset: `col()` closes with ESC[0m, which
|
|
3028
|
+
// would drop the background on the last column and leave a strip of page colour at the right edge.
|
|
3029
|
+
diffRows.push({ text: lead + painted.text + lineBg + pad + '\x1b[39m', ind: cont, raw: true });
|
|
3011
3030
|
emitted++;
|
|
3012
3031
|
}
|
|
3013
3032
|
if (total > emitted) {
|
|
@@ -3043,22 +3062,46 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
3043
3062
|
const numbered = readLang && !isErr ? /^(\d+)\t([\s\S]*)$/.exec(ln) : null;
|
|
3044
3063
|
if (numbered) {
|
|
3045
3064
|
// `wrapAnsiWords` measures VISIBLE columns, so the colour codes do not count towards the wrap.
|
|
3046
|
-
|
|
3065
|
+
// THE FILE'S OWN INDENTATION IS OFTEN TABS. Left as tabs, `visualCol` counted them as zero columns
|
|
3066
|
+
// while the terminal advanced to the next stop: the row was padded short and the previous frame's
|
|
3067
|
+
// glyphs stayed visible behind it. Expand before measuring, but keep the first tab as the separator
|
|
3068
|
+
// — the regex above already split on it.
|
|
3069
|
+
const painted = paintCode(expandTabs(numbered[2]), readLang, '', inComment);
|
|
3047
3070
|
inComment = painted.inComment;
|
|
3048
3071
|
// THE SEPARATOR IS A TAB, AND `visualCol` COUNTS A TAB AS ZERO COLUMNS. A terminal advances it to the
|
|
3049
3072
|
// next stop, so the row was measured several columns short, the terminal wrapped it itself, and the tail
|
|
3050
3073
|
// landed on the next row as a fragment — `921d` under a `920`-numbered row is exactly that. A fixed
|
|
3051
3074
|
// two-space gap is what the width maths needs and what reads better.
|
|
3052
3075
|
const text = `${numbered[1]} ${painted.text}`;
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3076
|
+
// A Read row is TRUNCATED, not wrapped. `wrapAnsiWords` used to fold an overlong line onto a second
|
|
3077
|
+
// row, and that second row — padded to full width by the frame, without a line number — was exactly
|
|
3078
|
+
// what a differential painter could not reconcile with the previous frame: the leftover glyphs stayed
|
|
3079
|
+
// under it as residue. One source line is one display row.
|
|
3080
|
+
//
|
|
3081
|
+
// THE CODE SURFACE: the whole row sits on `codeBg`, one step off the page. The number keeps its grey,
|
|
3082
|
+
// the content keeps its syntax colours, and the wash reaches the right edge. Diff `+`/`-` rows are
|
|
3083
|
+
// NOT affected — they keep their green/red.
|
|
3084
|
+
//
|
|
3085
|
+
// The background has to survive the row's own resets: every syntax token closes with `ESC[0m`, and the
|
|
3086
|
+
// padding `fitAnsi` adds sits AFTER the last one. Re-asserting after each reset — the same trick
|
|
3087
|
+
// `paintCode` uses for a diff wash — keeps the surface on the padding too, so the block reads solid.
|
|
3088
|
+
const surfaced = text.replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`);
|
|
3089
|
+
diffRows.push({ text: C.codeBg + fitAnsi(surfaced, bodyW) + C.bgReset, ind: idx === 0 ? pre : cont, raw: true });
|
|
3057
3090
|
return;
|
|
3058
3091
|
}
|
|
3059
3092
|
const wrapped = ln === '' ? [''] : wrapWords(ln, bodyW);
|
|
3093
|
+
// BASH OUTPUT SITS ON THE TERMINAL SURFACE, like text inside a real terminal emulator: the darkest recess
|
|
3094
|
+
// on screen. Other tools keep the plain page background, so a command's output reads as "a terminal ran
|
|
3095
|
+
// this" rather than as an ordinary result. The row keeps its grey text and the surface survives its own
|
|
3096
|
+
// resets the same way the code surface does.
|
|
3097
|
+
const termSurface = msg.toolName === 'Bash' || msg.toolName === 'Shell';
|
|
3060
3098
|
wrapped.forEach((t, i) => {
|
|
3061
|
-
|
|
3099
|
+
if (termSurface) {
|
|
3100
|
+
const surfaced = t.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}`);
|
|
3101
|
+
diffRows.push({ text: C.termBg + fitAnsi(surfaced, bodyW) + C.bgReset, ind: idx === 0 && i === 0 ? pre : cont, raw: true });
|
|
3102
|
+
} else {
|
|
3103
|
+
diffRows.push({ text: t, ind: idx === 0 && i === 0 ? pre : cont, color });
|
|
3104
|
+
}
|
|
3062
3105
|
});
|
|
3063
3106
|
});
|
|
3064
3107
|
if (visible.length > MAX_RESULT_LINES) {
|
|
@@ -4285,16 +4328,22 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4285
4328
|
msgLen.set(mem.msgLen.subarray(0, reuse), 0);
|
|
4286
4329
|
sigs.set(prevSigs.subarray(0, reuse), 0);
|
|
4287
4330
|
cursor = rowStart[reuse - 1] + msgLen[reuse - 1];
|
|
4288
|
-
prevBordered = chat[reuse - 1].role === '
|
|
4289
|
-
|| chat[reuse - 1].role === 'bash';
|
|
4331
|
+
prevBordered = chat[reuse - 1].role === 'queued';
|
|
4290
4332
|
}
|
|
4291
4333
|
for (let mi = reuse; mi < n; mi++) {
|
|
4292
4334
|
const m = chat[mi];
|
|
4293
|
-
|
|
4335
|
+
// ONLY `queued` IS DRAWN INSIDE A FRAME. A user message and a shell echo are a filled surface with no walls, so
|
|
4336
|
+
// their text uses the full inner width — leaving them in `border` narrowed it by two columns and this pass's row
|
|
4337
|
+
// count drifted from what the layout actually paints.
|
|
4338
|
+
const border = m.role === 'queued';
|
|
4294
4339
|
const ww = border ? Math.max(1, Math.min(1, innerW - 4)) : innerW; // placeholder
|
|
4295
4340
|
void ww;
|
|
4296
4341
|
rowStart[mi] = cursor;
|
|
4297
|
-
|
|
4342
|
+
// THE RULES BELONG TO THE FRAME, and only `queued` still draws one: a user message and a shell echo are a
|
|
4343
|
+
// filled surface now. Counting two rules for them made this pass's row count disagree with what the layout
|
|
4344
|
+
// actually paints, which is what `chatRowTotal` compares against.
|
|
4345
|
+
const drawsFrame = m.role === 'queued';
|
|
4346
|
+
const rules = drawsFrame ? (prevBordered ? 1 : 2) : 0;
|
|
4298
4347
|
sigs[mi] = messageSignature(m);
|
|
4299
4348
|
// Reuse/minimal layout for the row count: same width/border arithmetic as
|
|
4300
4349
|
// the layout path below. We need boxText for bordered messages.
|
|
@@ -4368,7 +4417,7 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4368
4417
|
if (!hasFence && !valid && !cached && !animating && m._count && m._count.key === countKey && m._count.textLen === countLen) {
|
|
4369
4418
|
msgLen[mi] = m._count.len + rules;
|
|
4370
4419
|
cursor += msgLen[mi];
|
|
4371
|
-
|
|
4420
|
+
prevBordered = drawsFrame;
|
|
4372
4421
|
continue;
|
|
4373
4422
|
}
|
|
4374
4423
|
if (valid) {
|
|
@@ -4437,7 +4486,7 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4437
4486
|
m._cache = null;
|
|
4438
4487
|
}
|
|
4439
4488
|
cursor += msgLen[mi];
|
|
4440
|
-
prevBordered =
|
|
4489
|
+
prevBordered = drawsFrame;
|
|
4441
4490
|
}
|
|
4442
4491
|
}
|
|
4443
4492
|
const total = cursor;
|
|
@@ -4534,11 +4583,14 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4534
4583
|
boxText = Math.max(1, boxInner - boxPad * 2);
|
|
4535
4584
|
}
|
|
4536
4585
|
// Shared wall with the previous bordered message (its bottom rule is ours).
|
|
4586
|
+
//
|
|
4587
|
+
// A USER MESSAGE AND A SHELL ECHO NO LONGER DRAW A FRAME, so they have no wall to share. Leaving them in made the
|
|
4588
|
+
// second of two adjacent rows skip its filled surface and fall through to the frame branch — the shell echo
|
|
4589
|
+
// came out with walls and no background. Only `queued` still draws a box.
|
|
4537
4590
|
let shared = false;
|
|
4538
4591
|
if (bordered && mi > 0) {
|
|
4539
4592
|
const prev = chat[mi - 1];
|
|
4540
|
-
shared =
|
|
4541
|
-
&& rowStart[mi - 1] + msgLen[mi - 1] === cursor;
|
|
4593
|
+
shared = prev.role === 'queued' && rowStart[mi - 1] + msgLen[mi - 1] === cursor;
|
|
4542
4594
|
}
|
|
4543
4595
|
const len = msgLen[mi];
|
|
4544
4596
|
// A message that may contain a bitmap is always built, visible or not: a row COUNT cannot represent a
|
|
@@ -4568,8 +4620,20 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4568
4620
|
}
|
|
4569
4621
|
const spinRows = ccc.spinRows;
|
|
4570
4622
|
const liveAt = (r, i) => (spinRows && spinRows.has(i) ? r.split(SPIN_PLACEHOLDER).join(spinFrame) : r);
|
|
4571
|
-
|
|
4572
|
-
if (bordered)
|
|
4623
|
+
const asSurface = msg.role === 'user' || msg.role === 'bash';
|
|
4624
|
+
if (bordered && !shared && !asSurface) out.push(rule(true, boxColor));
|
|
4625
|
+
// A USER MESSAGE IS DRAWN AS A FILLED SURFACE, the same one the composer uses: what was typed and what is
|
|
4626
|
+
// being typed read as one kind of thing. The frame is gone for the same reason it left the composer — a box
|
|
4627
|
+
// competes with the transcript and spends rows on chrome. A shell echo keeps its terminal surface instead.
|
|
4628
|
+
const surfaceFor = msg.role === 'bash' ? C.termBg : (msg.role === 'user' ? C.composerBg : '');
|
|
4629
|
+
if (bordered && surfaceFor && !shared) {
|
|
4630
|
+
for (let i = 0; i < ccc.rows.length; i++) {
|
|
4631
|
+
const rowText = liveAt(ccc.rows[i], i);
|
|
4632
|
+
if (isImageRow(rowText)) { out.push(rowText); continue; }
|
|
4633
|
+
const surfaced = rowText.replace(/\x1b\[0m/g, `\x1b[0m${surfaceFor}`);
|
|
4634
|
+
out.push(PAD + surfaceFor + fitAnsi(surfaced, innerW) + C.bgReset);
|
|
4635
|
+
}
|
|
4636
|
+
} else if (bordered) {
|
|
4573
4637
|
const pad = ' '.repeat(boxPad);
|
|
4574
4638
|
const wall = col('│', boxColor);
|
|
4575
4639
|
for (let i = 0; i < ccc.rows.length; i++) {
|
|
@@ -4588,7 +4652,7 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4588
4652
|
out.push(isImageRow(rowText) ? rowText : PAD + rowText);
|
|
4589
4653
|
}
|
|
4590
4654
|
}
|
|
4591
|
-
if (bordered) out.push(rule(false, boxColor));
|
|
4655
|
+
if (bordered && !asSurface) out.push(rule(false, boxColor));
|
|
4592
4656
|
} else {
|
|
4593
4657
|
for (let i = 0; i < len; i++) out.push('');
|
|
4594
4658
|
}
|
|
@@ -5045,7 +5109,7 @@ function justify(left, right, w) {
|
|
|
5045
5109
|
// Height of the composer box (top border + content rows + bottom border).
|
|
5046
5110
|
export function composerHeight(state, cols) {
|
|
5047
5111
|
const insideW = Math.max(0, (cols | 0) - 2);
|
|
5048
|
-
return composerLayout(state, insideW
|
|
5112
|
+
return composerLayout(state, insideW).rows.length;
|
|
5049
5113
|
}
|
|
5050
5114
|
|
|
5051
5115
|
// UNCLAMPED height of the AskUserQuestion box. `composeFrame` caps the real
|
|
@@ -5308,25 +5372,45 @@ function applySelectionToRow(lines, idx, sel, w) {
|
|
|
5308
5372
|
*/
|
|
5309
5373
|
function highlightAnsiRange(row, c0, c1, w) {
|
|
5310
5374
|
const s = String(row);
|
|
5375
|
+
const cells = parseCells(s);
|
|
5376
|
+
// The SGR for the background each column was drawn with, or '' when the row has none there.
|
|
5377
|
+
const ownBg = cells.map((_, c) => {
|
|
5378
|
+
const rgb = cellBg(cells, c);
|
|
5379
|
+
return rgb ? `\x1b[48;2;${rgb[0]};${rgb[1]};${rgb[2]}m` : '';
|
|
5380
|
+
});
|
|
5381
|
+
// The theme's selection colour, read from the SGR rather than hardcoded: a light theme has a pale one.
|
|
5382
|
+
const m = /48;2;(\d+);(\d+);(\d+)/.exec(C.selBg);
|
|
5383
|
+
const selRgb = m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
5384
|
+
// The SELECTION WINS. A hint of the row's own wash stays in the mix so a selected deletion still reads as a
|
|
5385
|
+
// deletion, but nine parts selection to one part row — an earlier three-parts-row blend left the diff colour
|
|
5386
|
+
// dominating and the selected range looked like an unselected diff with a tint.
|
|
5387
|
+
const selectedBg = (col) => {
|
|
5388
|
+
const rgb = cellBg(cells, col);
|
|
5389
|
+
if (!rgb || !selRgb) return C.selBg;
|
|
5390
|
+
const mix = (a, b) => Math.round(a * 0.9 + b * 0.1);
|
|
5391
|
+
return `\x1b[48;2;${mix(selRgb[0], rgb[0])};${mix(selRgb[1], rgb[1])};${mix(selRgb[2], rgb[2])}m`;
|
|
5392
|
+
};
|
|
5393
|
+
const lo = Math.max(c0, 1);
|
|
5311
5394
|
let out = '';
|
|
5312
5395
|
let col = 0;
|
|
5313
5396
|
let i = 0;
|
|
5314
5397
|
let inSel = false;
|
|
5315
|
-
// A range that begins at the margin starts one column later.
|
|
5316
|
-
const lo = Math.max(c0, 1);
|
|
5317
5398
|
|
|
5318
5399
|
while (i < s.length) {
|
|
5319
5400
|
if (s[i] === '\x1b') {
|
|
5320
|
-
// Emit the escape, then RE-ASSERT the
|
|
5321
|
-
//
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5401
|
+
// Emit the escape, then RE-ASSERT the background for the column it was emitted at: the row embeds its own
|
|
5402
|
+
// resets (a markdown span ends in ESC[0m), and a bare reset clears the background too.
|
|
5403
|
+
const esc = /^\x1b\[[0-9;?]*[a-zA-Z]/.exec(s.slice(i)) || /^\x1b\[[0-9;?]* [a-zA-Z]/.exec(s.slice(i));
|
|
5404
|
+
if (esc) {
|
|
5405
|
+
out += esc[0];
|
|
5406
|
+
// The row writes its OWN background back after every syntax token — `paintCode` re-asserts the diff wash
|
|
5407
|
+
// after each `ESC[0m`. Those SGRs arrive here as ordinary escapes, not resets, so leaving them untouched
|
|
5408
|
+
// let the diff colour overwrite the selection mid-run. Inside the selection, ANY background escape that
|
|
5409
|
+
// follows is replaced by the selected one; outside it, only a reset needs the row's own wash restored.
|
|
5410
|
+
const isBg = /^\x1b\[48;/.test(esc[0]);
|
|
5411
|
+
if (inSel && (isBg || esc[0] === '\x1b[0m' || esc[0] === '\x1b[m')) out += selectedBg(col);
|
|
5412
|
+
else if (!inSel && (esc[0] === '\x1b[0m' || esc[0] === '\x1b[m')) out += ownBg[col] || '';
|
|
5413
|
+
i += esc[0].length;
|
|
5330
5414
|
continue;
|
|
5331
5415
|
}
|
|
5332
5416
|
}
|
|
@@ -5336,28 +5420,21 @@ function highlightAnsiRange(row, c0, c1, w) {
|
|
|
5336
5420
|
const cw = visualWidth(ch);
|
|
5337
5421
|
const want = col >= lo && col < c1;
|
|
5338
5422
|
|
|
5339
|
-
if (want && !inSel) {
|
|
5340
|
-
|
|
5341
|
-
//
|
|
5342
|
-
//
|
|
5343
|
-
out += C.
|
|
5344
|
-
inSel = true;
|
|
5345
|
-
} else if (!want && inSel) {
|
|
5346
|
-
// Leave the selection: reset just the background (ESC[49m), keeping the
|
|
5347
|
-
// row's foreground. A bare reset would also clear the foreground.
|
|
5348
|
-
out += C.bgReset;
|
|
5423
|
+
if (want && !inSel) { out += selectedBg(col); inSel = true; }
|
|
5424
|
+
else if (!want && inSel) {
|
|
5425
|
+
// RESTORE the row's own background, not ESC[49m: a diff row is red or green all the way to the right edge,
|
|
5426
|
+
// and clearing the background there left a strip of page colour in the middle of the wash.
|
|
5427
|
+
out += ownBg[col] || C.bgReset;
|
|
5349
5428
|
inSel = false;
|
|
5350
5429
|
}
|
|
5351
5430
|
|
|
5352
5431
|
out += ch;
|
|
5353
5432
|
col += cw;
|
|
5354
5433
|
i += cp > 0xffff ? 2 : 1;
|
|
5355
|
-
|
|
5356
5434
|
if (col >= w) break;
|
|
5357
5435
|
}
|
|
5358
5436
|
|
|
5359
5437
|
if (inSel) out += C.reset;
|
|
5360
|
-
|
|
5361
5438
|
return out;
|
|
5362
5439
|
}
|
|
5363
5440
|
|
|
@@ -6019,7 +6096,11 @@ export function composeFrame(state, cols, rows) {
|
|
|
6019
6096
|
const takeover = state.editor || state.panel || null;
|
|
6020
6097
|
|
|
6021
6098
|
// ---- geometry ----
|
|
6022
|
-
const composer = composerLayout(state, insideW
|
|
6099
|
+
const composer = composerLayout(state, insideW);
|
|
6100
|
+
// ONE ROW PER INPUT ROW. It used to be `rows.length + 2` for the top and bottom rules; the composer is now a
|
|
6101
|
+
// filled surface with no frame, so reserving those two rows would leave a gap above and below it.
|
|
6102
|
+
// One row per input row, PLUS the separator rule above the composer.
|
|
6103
|
+
// One row per input row, PLUS a rule above and below the composer.
|
|
6023
6104
|
const composerBoxH = takeover ? 0 : composer.rows.length + 2;
|
|
6024
6105
|
const menuItems = (state.menuOpen && state.menuList.length && !takeover)
|
|
6025
6106
|
? Math.min(state.menuList.length, MAX_MENU) + 1
|
|
@@ -7347,33 +7428,30 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7347
7428
|
|
|
7348
7429
|
let composerFirstRow = -1;
|
|
7349
7430
|
if (!takeover) {
|
|
7350
|
-
|
|
7351
|
-
//
|
|
7352
|
-
//
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
//
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
//
|
|
7361
|
-
|
|
7362
|
-
|
|
7431
|
+
// A SEPARATOR BETWEEN THE TRANSCRIPT AND THE INPUT. With the border gone, the last line of the conversation sat
|
|
7432
|
+
// directly on top of the composer, and a paragraph against a grey block reads as one crowded mass. One faint
|
|
7433
|
+
// rule says "the conversation ends here" without drawing a frame.
|
|
7434
|
+
lines.push(col('─'.repeat(w), C.border));
|
|
7435
|
+
composerFirstRow = lines.length;
|
|
7436
|
+
// THE COMPOSER SPANS THE FULL WIDTH. It used to keep the transcript's 1-column left margin so its walls
|
|
7437
|
+
// lined up with a sent user message's box; with no walls there is nothing to line up, and a filled surface
|
|
7438
|
+
// that stops one column short of an edge reads as a damaged block rather than as an input field.
|
|
7439
|
+
const CPAD = '';
|
|
7440
|
+
const cInner = Math.max(1, insideW + 2); // the full terminal width: insideW is w - 2
|
|
7441
|
+
// NO BORDER: the composer is a BLOCK OF BACKGROUND, one row per input row. A box drawn in characters competes
|
|
7442
|
+
// with the transcript's own boxes (a sent user message is boxed too) and spends rows on chrome; a filled
|
|
7443
|
+
// surface says the same thing — "this is the input, and it is this wide" — without drawing a frame.
|
|
7363
7444
|
for (let ri = 0; ri < composer.rows.length; ri++) {
|
|
7364
|
-
addHit(lines.length,
|
|
7365
|
-
// Colour the prompt glyph like the transcript's user marker
|
|
7366
|
-
//
|
|
7367
|
-
// continuation rows are padded with spaces instead).
|
|
7445
|
+
addHit(lines.length, 0, cInner, { kind: 'composerRow', rowIdx: ri });
|
|
7446
|
+
// Colour the prompt glyph like the transcript's user marker and keep the typed TEXT white. The prefix is the
|
|
7447
|
+
// first `> ` of the row (the continuation rows are padded with spaces instead).
|
|
7368
7448
|
const rawRow = composer.rows[ri];
|
|
7369
|
-
// Which chip the pointer is over, if any. `state.pasteHover` is the paste NUMBER, set by the
|
|
7370
|
-
//
|
|
7371
|
-
//
|
|
7449
|
+
// Which chip the pointer is over, if any. `state.pasteHover` is the paste NUMBER, set by the mousehover
|
|
7450
|
+
// handler from the same index maths the expand gesture uses, so the highlight and the click can never
|
|
7451
|
+
// disagree about which chip they mean.
|
|
7372
7452
|
const styledRow = highlightPasteMarkers(rawRow, state.pasteHover);
|
|
7373
|
-
// One space of padding after the left wall (and before the right wall), the
|
|
7374
|
-
// same as the transcript's user/queue boxes, so the geometry is identical.
|
|
7375
7453
|
const pre = composerInput(state).prefix;
|
|
7376
|
-
const textW = Math.max(1, cInner - 2);
|
|
7454
|
+
const textW = Math.max(1, cInner - 2);
|
|
7377
7455
|
// Apply composer text selection highlight if a selection is active.
|
|
7378
7456
|
const sel = state.composerSel;
|
|
7379
7457
|
const rowMeta = composer.meta[ri] || {};
|
|
@@ -7384,18 +7462,16 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7384
7462
|
const highlighted = (sel && sel.anchor !== sel.head)
|
|
7385
7463
|
? highlightSelection(textPart, textStart, sel.anchor, sel.head)
|
|
7386
7464
|
: textPart;
|
|
7387
|
-
// The `!` (shell mode) prefix is BOLD: it is a mode marker, not punctuation,
|
|
7388
|
-
//
|
|
7465
|
+
// The `!` (shell mode) prefix is BOLD: it is a mode marker, not punctuation, and it should out-weigh
|
|
7466
|
+
// the `>` prompt glyph at a glance.
|
|
7389
7467
|
const preCol = state.inputMode === 'bash' ? (C.shellMode + C.bold) : C.cyan;
|
|
7390
|
-
rowAnsi = ' ' + col(pre, preCol) + C.white
|
|
7391
|
-
fitAnsi(highlighted, Math.max(1, textW - visualCol(pre))) + ' ';
|
|
7468
|
+
rowAnsi = ' ' + col(pre, preCol) + C.white
|
|
7469
|
+
+ fitAnsi(highlighted, Math.max(1, textW - visualCol(pre))) + ' ';
|
|
7392
7470
|
} else {
|
|
7393
7471
|
// THE INDENT IS NOT TEXT. A continuation row arrives as `cont + text` — two spaces standing in for
|
|
7394
7472
|
// `> ` — and `rowMeta.start` is the offset of the TEXT, not of the row. Handing the whole row to
|
|
7395
7473
|
// `highlightSelection` therefore shifted the selection by the prefix's width: the two blank columns lit
|
|
7396
7474
|
// up and the highlight ran two characters early, which is the offset seen on every wrapped line.
|
|
7397
|
-
//
|
|
7398
|
-
// The first-row branch above already strips its prefix; this one has to strip the continuation's.
|
|
7399
7475
|
const contWidth = rowMeta.preWidth != null ? rowMeta.preWidth : visualCol(pre);
|
|
7400
7476
|
const indent = styledRow.slice(0, contWidth);
|
|
7401
7477
|
const textPart = styledRow.slice(contWidth);
|
|
@@ -7405,13 +7481,15 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7405
7481
|
: textPart;
|
|
7406
7482
|
rowAnsi = ' ' + indent + C.white + fitAnsi(highlighted, Math.max(1, textW - contWidth)) + ' ';
|
|
7407
7483
|
}
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
);
|
|
7484
|
+
// THE SURFACE SURVIVES THE ROW'S OWN RESETS: every colour span closes with \x1b[0m, so the background is
|
|
7485
|
+
// re-asserted after each one — the same trick the code and terminal surfaces use.
|
|
7486
|
+
const surfaced = rowAnsi.replace(/\x1b\[0m/g, `\x1b[0m${C.composerBg}`);
|
|
7487
|
+
lines.push(C.composerBg + fitAnsi(surfaced, insideW + 2) + C.bgReset);
|
|
7411
7488
|
}
|
|
7412
|
-
|
|
7489
|
+
// AND THE RULE UNDER IT, mirroring the one above: the input is bounded by two faint rules, so it reads as a
|
|
7490
|
+
// field between the conversation and the status line rather than as a block touching both.
|
|
7491
|
+
lines.push(col('─'.repeat(w), C.border));
|
|
7413
7492
|
}
|
|
7414
|
-
|
|
7415
7493
|
|
|
7416
7494
|
const MPAD = ' ';
|
|
7417
7495
|
const mInner = Math.max(1, insideW - 3);
|
|
@@ -7742,10 +7820,12 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7742
7820
|
// The confirm prompt is NOT a term here: it shares the tip row, which is already inside
|
|
7743
7821
|
// STATUS_H, so counting it made the caret jump up a line every time Ctrl+C was pressed.
|
|
7744
7822
|
const bottomChrome = STATUS_H + CTX_H + menuH + mentionH;
|
|
7823
|
+
// `- 2`: the two rules that bound the composer. The input's last row sits above the lower rule, which sits above
|
|
7824
|
+
// the status line.
|
|
7745
7825
|
const caretScreenRow = h - bottomChrome - 2 - (composer.rows.length - 1 - composer.caretRow);
|
|
7746
7826
|
cursor = {
|
|
7747
7827
|
row: Math.max(0, Math.min(caretScreenRow, h - 1)),
|
|
7748
|
-
col: Math.min(composer.caretCol
|
|
7828
|
+
col: Math.min(Math.max(0, composer.caretCol), w - 1),
|
|
7749
7829
|
};
|
|
7750
7830
|
cursorVisible = true;
|
|
7751
7831
|
}
|
|
@@ -8943,6 +9023,23 @@ function ensureMenuVisible(state) {
|
|
|
8943
9023
|
}
|
|
8944
9024
|
|
|
8945
9025
|
// ---- command dispatch ----
|
|
9026
|
+
/**
|
|
9027
|
+
* Fire a TUI-side hook and FORGET it. These are notifications, not decisions: a slow or failing hook must not
|
|
9028
|
+
* hold up a permission prompt, a directory move or a settings save. The config is loaded fresh so an edit made
|
|
9029
|
+
* while the session was running is picked up without a restart.
|
|
9030
|
+
*
|
|
9031
|
+
* MODULE-LEVEL ON PURPOSE. `runTurn` and `dispatch` are both module-level functions, and the onEvent callbacks
|
|
9032
|
+
* in runTurn reach this helper too. A version scoped inside either one is invisible to the other, and the bare
|
|
9033
|
+
* name then throws a ReferenceError right after a tool result has arrived — which used to kill the process.
|
|
9034
|
+
*/
|
|
9035
|
+
function fireHook(event, payload, ws) {
|
|
9036
|
+
try {
|
|
9037
|
+
const { hooks } = loadHooks(ws);
|
|
9038
|
+
if (!(hooks[event] || []).length) return;
|
|
9039
|
+
void runShellHooks({ hooks }, event, payload, ws).catch(() => {});
|
|
9040
|
+
} catch { /* a broken hook config is a reason to carry on, not to fail the command */ }
|
|
9041
|
+
}
|
|
9042
|
+
|
|
8946
9043
|
export async function dispatch(cmdRaw, arg, state, cfg, session, h, submit, stdout, renderFrameArg) {
|
|
8947
9044
|
const { addChat, openPicker, openForm, notice, sendPrompt, quit, saveSession, openEditor } = h;
|
|
8948
9045
|
|
|
@@ -9087,6 +9184,7 @@ export async function dispatch(cmdRaw, arg, state, cfg, session, h, submit, stdo
|
|
|
9087
9184
|
if (key === 'plan_instructions') cfg.planInstructions = raw;
|
|
9088
9185
|
if (key === 'focus_instructions') cfg.focusInstructions = raw;
|
|
9089
9186
|
if (key === 'swarm_instructions') cfg.swarmInstructions = raw;
|
|
9187
|
+
fireHook('ConfigChange', { key, value: coerced.value, source: 'settings' }, state.workspace || cfg.workspace);
|
|
9090
9188
|
if (typeof renderFrameArg === 'function') renderFrameArg();
|
|
9091
9189
|
return true;
|
|
9092
9190
|
}
|
|
@@ -12853,6 +12951,7 @@ export async function dispatch(cmdRaw, arg, state, cfg, session, h, submit, stdo
|
|
|
12853
12951
|
// paths against `ctx.cwd || ctx.workspace`, which the agent copies from `cfg`
|
|
12854
12952
|
// each turn. Moving only the status line left Edit/Read/Bash pointed at the
|
|
12855
12953
|
// directory being left behind.
|
|
12954
|
+
const prevCwd = state.cwd || cfg.workspace;
|
|
12856
12955
|
state.cwd = target;
|
|
12857
12956
|
state.workspace = target;
|
|
12858
12957
|
cfg.workspace = target;
|
|
@@ -12869,6 +12968,7 @@ export async function dispatch(cmdRaw, arg, state, cfg, session, h, submit, stdo
|
|
|
12869
12968
|
state.steps = session.steps || 0;
|
|
12870
12969
|
saveSession(session);
|
|
12871
12970
|
app(`Session moved to: ${target} (${newSession.id})`);
|
|
12971
|
+
fireHook('CwdChanged', { cwd: target, previous: prevCwd }, target);
|
|
12872
12972
|
return;
|
|
12873
12973
|
}
|
|
12874
12974
|
|
|
@@ -13076,7 +13176,7 @@ export async function dispatch(cmdRaw, arg, state, cfg, session, h, submit, stdo
|
|
|
13076
13176
|
return;
|
|
13077
13177
|
}
|
|
13078
13178
|
const { hooks, errors } = loadHooks(workspace);
|
|
13079
|
-
const lines = describeHooks({ hooks });
|
|
13179
|
+
const lines = describeHooks({ hooks }, workspace);
|
|
13080
13180
|
if (errors.length) lines.push('', 'Config problems:', ...errors.map((e) => ` ! ${e}`));
|
|
13081
13181
|
h.openPanel('hncode — hooks', lines);
|
|
13082
13182
|
return;
|
|
@@ -14774,6 +14874,8 @@ const agents = readAgentsMd(state.cwd || state.workspace || cfg.workspace, state
|
|
|
14774
14874
|
// The prompt must NOT touch the composer: the user may already be typing,
|
|
14775
14875
|
// and only Enter/Esc belong to the prompt.
|
|
14776
14876
|
state.approvalPending = { toolName, args, desc, resolve, detail };
|
|
14877
|
+
fireHook('PermissionRequest', { toolName, toolArgs: args, prompt: desc }, state.workspace || cfg.workspace);
|
|
14878
|
+
fireHook('Notification', { type: 'permission_prompt', toolName, prompt: desc }, state.workspace || cfg.workspace);
|
|
14777
14879
|
viewCur.render();
|
|
14778
14880
|
});
|
|
14779
14881
|
};
|
|
@@ -15235,6 +15337,7 @@ const agents = readAgentsMd(state.cwd || state.workspace || cfg.workspace, state
|
|
|
15235
15337
|
// block renders from the moment the swarm is announced. Every item
|
|
15236
15338
|
// starts "queued" and flips as the tool reports progress.
|
|
15237
15339
|
if (e.name === 'AgentSwarm') {
|
|
15340
|
+
fireHook('SubagentStart', { description: (e.args && e.args.description) || '', items: (e.args && e.args.items) || [] }, state.workspace || cfg.workspace);
|
|
15238
15341
|
const a = entry.toolArgs || {};
|
|
15239
15342
|
entry.swarmDescription = a.description || '';
|
|
15240
15343
|
entry.swarmModel = a.subagent_type || '';
|
|
@@ -15283,6 +15386,7 @@ const agents = readAgentsMd(state.cwd || state.workspace || cfg.workspace, state
|
|
|
15283
15386
|
// straight from that payload — no LCS inference, which mis-paired the context rows
|
|
15284
15387
|
// into `-`/`+` pairs because the two sides had different shapes.
|
|
15285
15388
|
entry.diff = editDiffRows(e.editDiff);
|
|
15389
|
+
fireHook('FileChanged', { path: e.editDiff.path || (entry.toolArgs && entry.toolArgs.path), change: 'edit' }, state.workspace || cfg.workspace);
|
|
15286
15390
|
}
|
|
15287
15391
|
// Hand the counts to the TOOL row (which keeps `+N -N` next to its
|
|
15288
15392
|
// name) and the diff to the RESULT row (rendered beneath the `↳`).
|
|
@@ -18266,7 +18370,7 @@ export async function startTUI(opts) {
|
|
|
18266
18370
|
case 'composerRow': {
|
|
18267
18371
|
const { cols } = dims();
|
|
18268
18372
|
const insideW = Math.max(0, cols - 2);
|
|
18269
|
-
const layout = composerLayout(state, insideW
|
|
18373
|
+
const layout = composerLayout(state, insideW);
|
|
18270
18374
|
const t = state._lastMouse;
|
|
18271
18375
|
const clickCol = t ? (t.col || 1) - 1 : 1;
|
|
18272
18376
|
// The column is measured from the row's PREFIX, because `composerTextIndexAt`
|
|
@@ -18636,7 +18740,7 @@ export async function startTUI(opts) {
|
|
|
18636
18740
|
if (hb && hb.kind === 'composerRow') {
|
|
18637
18741
|
const { cols } = dims();
|
|
18638
18742
|
const insideW = Math.max(0, cols - 2);
|
|
18639
|
-
const layout = composerLayout(state, insideW
|
|
18743
|
+
const layout = composerLayout(state, insideW);
|
|
18640
18744
|
const clickCol = Math.max(0, (t.col || 1) - 1 - 3);
|
|
18641
18745
|
pasteHover = pasteMarkerIdAt(state.input || '', composerTextIndexAt(layout, hb.rowIdx, clickCol));
|
|
18642
18746
|
}
|
|
@@ -18708,7 +18812,7 @@ export async function startTUI(opts) {
|
|
|
18708
18812
|
if (hb && hb.kind === 'composerRow') {
|
|
18709
18813
|
const { cols } = dims();
|
|
18710
18814
|
const insideW = Math.max(0, cols - 2);
|
|
18711
|
-
const layout = composerLayout(state, insideW
|
|
18815
|
+
const layout = composerLayout(state, insideW);
|
|
18712
18816
|
const clickCol = (t.col || 1) - 1;
|
|
18713
18817
|
const colInContent = Math.max(0, clickCol - 1);
|
|
18714
18818
|
const idx = composerTextIndexAt(layout, hb.rowIdx, colInContent);
|
|
@@ -19893,7 +19997,7 @@ export async function startTUI(opts) {
|
|
|
19893
19997
|
}
|
|
19894
19998
|
}
|
|
19895
19999
|
const insideW = Math.max(0, dims().cols - 2);
|
|
19896
|
-
const layout = composerLayout(state, insideW
|
|
20000
|
+
const layout = composerLayout(state, insideW);
|
|
19897
20001
|
const dir = t.key === 'down' ? 1 : -1;
|
|
19898
20002
|
const targetRow = layout.caretRow + dir;
|
|
19899
20003
|
if (targetRow >= 0 && targetRow < layout.rows.length) {
|
|
@@ -19921,7 +20025,7 @@ export async function startTUI(opts) {
|
|
|
19921
20025
|
if (!overlay) {
|
|
19922
20026
|
const cur = state.input || '';
|
|
19923
20027
|
const insideW = Math.max(0, dims().cols - 2);
|
|
19924
|
-
const layout = composerLayout(state, insideW
|
|
20028
|
+
const layout = composerLayout(state, insideW);
|
|
19925
20029
|
const dir = t.key === 'down' ? 1 : -1;
|
|
19926
20030
|
const targetRow = layout.caretRow + dir;
|
|
19927
20031
|
// The composer is MULTI-LINE: ↑/↓ move the caret between its rows
|
|
@@ -20349,7 +20453,7 @@ export async function startTUI(opts) {
|
|
|
20349
20453
|
return;
|
|
20350
20454
|
}
|
|
20351
20455
|
const insideW = Math.max(0, dims().cols - 2);
|
|
20352
|
-
const layout = composerLayout(state, insideW
|
|
20456
|
+
const layout = composerLayout(state, insideW);
|
|
20353
20457
|
const dir = t.key === 'down' ? 1 : -1;
|
|
20354
20458
|
const targetRow = layout.caretRow + dir;
|
|
20355
20459
|
if (targetRow >= 0 && targetRow < layout.rows.length) {
|
|
@@ -20477,7 +20581,7 @@ export async function startTUI(opts) {
|
|
|
20477
20581
|
// a multi-line prompt can be selected across lines. Same sticky column as
|
|
20478
20582
|
// the plain ↑/↓ (see verticalCaretIndex).
|
|
20479
20583
|
const insideW = Math.max(0, dims().cols - 2);
|
|
20480
|
-
const layout = composerLayout(state, insideW
|
|
20584
|
+
const layout = composerLayout(state, insideW);
|
|
20481
20585
|
const targetRow = layout.caretRow + (dirName === 'down' ? 1 : -1);
|
|
20482
20586
|
if (targetRow < 0 || targetRow >= layout.rows.length) { renderFrame(); return; }
|
|
20483
20587
|
next = verticalCaretIndex(state, cur, layout, targetRow);
|