@adecore/agents-react 0.51.0 → 0.53.0

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 (59) hide show
  1. package/dist/agents/AgentIcon.js +25 -17
  2. package/dist/agents/ProviderLogo.js +26 -16
  3. package/dist/agents/agent-marks.d.ts +1 -0
  4. package/dist/agents/provider-paths.d.ts +2 -1
  5. package/dist/agents/provider-paths.js +11 -2
  6. package/dist/chat/index.d.ts +2 -1
  7. package/dist/chat/index.js +2 -1
  8. package/dist/chat/logic/command-looks.d.ts +17 -5
  9. package/dist/chat/logic/command-looks.js +35 -7
  10. package/dist/chat/logic/timeline.d.ts +6 -4
  11. package/dist/chat/logic/timeline.js +32 -25
  12. package/dist/chat/logic/tool-looks.d.ts +16 -0
  13. package/dist/chat/logic/tool-looks.js +188 -0
  14. package/dist/chat/logic/tools.d.ts +5 -0
  15. package/dist/chat/logic/tools.js +17 -2
  16. package/dist/chat/ui/ShellCommand.d.ts +2 -1
  17. package/dist/chat/ui/ShellCommand.js +73 -22
  18. package/dist/chat/ui/SubagentTimeline.js +5 -2
  19. package/dist/chat/ui/Timeline.js +2 -1
  20. package/dist/chat/ui/diff/EditorEditDiff.d.ts +3 -2
  21. package/dist/chat/ui/diff/EditorEditDiff.js +93 -79
  22. package/dist/chat/ui/diff/LegacyEditDiff.d.ts +1 -1
  23. package/dist/chat/ui/diff/LegacyEditDiff.js +64 -48
  24. package/dist/chat/ui/rows/RowContainer.js +26 -23
  25. package/dist/chat/ui/rows/WorkRows.d.ts +3 -4
  26. package/dist/chat/ui/rows/WorkRows.js +592 -519
  27. package/dist/chat/ui/rows/row-rhythm.d.ts +2 -2
  28. package/dist/chat/ui/rows/row-rhythm.js +9 -6
  29. package/dist/chat/ui/thread-references.d.ts +1 -0
  30. package/dist/chat/ui/thread-references.js +4 -3
  31. package/dist/host.d.ts +28 -0
  32. package/dist/index.d.ts +1 -1
  33. package/dist/locales/en/agent-chat.d.ts +4 -0
  34. package/dist/locales/en/agent-chat.js +4 -0
  35. package/dist/locales/nl/agent-chat.d.ts +4 -0
  36. package/dist/locales/nl/agent-chat.js +4 -0
  37. package/package.json +8 -8
  38. package/src/agents/AgentIcon.tsx +2 -1
  39. package/src/agents/ProviderLogo.tsx +2 -2
  40. package/src/agents/agent-marks.ts +2 -0
  41. package/src/agents/provider-paths.ts +15 -3
  42. package/src/chat/index.ts +2 -1
  43. package/src/chat/logic/command-looks.ts +51 -10
  44. package/src/chat/logic/timeline.ts +46 -27
  45. package/src/chat/logic/tool-looks.ts +228 -0
  46. package/src/chat/logic/tools.ts +13 -2
  47. package/src/chat/ui/ShellCommand.tsx +33 -6
  48. package/src/chat/ui/SubagentTimeline.tsx +3 -2
  49. package/src/chat/ui/Timeline.tsx +2 -1
  50. package/src/chat/ui/diff/EditorEditDiff.tsx +31 -5
  51. package/src/chat/ui/diff/LegacyEditDiff.tsx +5 -3
  52. package/src/chat/ui/rows/RowContainer.tsx +4 -2
  53. package/src/chat/ui/rows/WorkRows.tsx +46 -33
  54. package/src/chat/ui/rows/row-rhythm.ts +9 -6
  55. package/src/chat/ui/thread-references.ts +5 -1
  56. package/src/host.ts +51 -0
  57. package/src/index.ts +3 -0
  58. package/src/locales/en/agent-chat.ts +4 -0
  59. package/src/locales/nl/agent-chat.ts +4 -0
@@ -0,0 +1,228 @@
1
+ import type { ChatToolItem } from '@adecore/agent-contracts';
2
+ import type { ToolLook, ToolLookMatch } from '../../host';
3
+ import type { CommandLookWord, LookRun } from './command-looks';
4
+ import { isRecord } from './json';
5
+
6
+ // A value keeps this many characters of what it says.
7
+ const FOLD_LENGTH = 40;
8
+ // An ACP agent titles a call of an MCP tool with the server and the tool, each agent with a separator of its own.
9
+ const TITLE_SEPARATORS = ['__', '_', '-'];
10
+ const TOOL_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
11
+ // The name an ACP call of kind `other` gets, which is all a call of an MCP tool is where its agent marks none.
12
+ const ACP_TOOL_ROW = 'Tool';
13
+
14
+ /* A call of a tool on an MCP server, the same whichever CLI made it. */
15
+ export interface McpCall {
16
+ readonly server: string;
17
+ /* The tool's name on its server, without the server. */
18
+ readonly tool: string;
19
+ /* The arguments the tool got. */
20
+ readonly input: Readonly<Record<string, unknown>>;
21
+ /* What the tool answered, out of any envelope the CLI wraps it in. */
22
+ readonly output: string | null;
23
+ }
24
+
25
+ /* A call of a look's MCP server read as a tool of its own. */
26
+ export interface ToolLookRun extends LookRun {
27
+ readonly look: ToolLook;
28
+ readonly match: ToolLookMatch;
29
+ readonly call: McpCall;
30
+ }
31
+
32
+ const caches = new WeakMap<readonly ToolLook[], WeakMap<ChatToolItem, ToolLookRun | null>>();
33
+
34
+ /* The server and the tool `text` names as `<server><separator><tool>`, on the first of `servers` it starts with. */
35
+ function toolOn(text: string, servers: readonly string[], separators: readonly string[]): Pick<McpCall, 'server' | 'tool'> | null {
36
+ for (const server of servers) {
37
+ for (const separator of separators) {
38
+ const prefix = `${server}${separator}`;
39
+ const tool = text.slice(prefix.length);
40
+
41
+ if (text.startsWith(prefix) && TOOL_NAME.test(tool)) {
42
+ return { server, tool };
43
+ }
44
+ }
45
+ }
46
+
47
+ return null;
48
+ }
49
+
50
+ /*
51
+ * The call as its name says it, whatever its input holds: `mcp__<server>__<tool>`, `<server>/<tool>`, or the tool
52
+ * Grok's `use_tool` names in its input. Undefined where the name says nothing of a server, and null where it names
53
+ * one that is not in `servers`, which no title overrules.
54
+ */
55
+ function namedCall(name: string, input: Readonly<Record<string, unknown>>, servers: readonly string[]): Omit<McpCall, 'output'> | null | undefined {
56
+ if (name.startsWith('mcp__')) {
57
+ const named = toolOn(name.slice(5), servers, ['__']);
58
+
59
+ return named === null ? null : { ...named, input };
60
+ }
61
+
62
+ if (name.includes('/')) {
63
+ const named = toolOn(name, servers, ['/']);
64
+
65
+ return named === null ? null : { ...named, input };
66
+ }
67
+
68
+ if (name !== ACP_TOOL_ROW || typeof input.tool_name !== 'string') {
69
+ return undefined;
70
+ }
71
+
72
+ const used = toolOn(input.tool_name, servers, ['__']);
73
+
74
+ return used === null ? null : { ...used, input: isRecord(input.tool_input) ? input.tool_input : {} };
75
+ }
76
+
77
+ /*
78
+ * The call as an ACP agent that marks no server titles it, in the rows `toolRow` of `@adecore/agents` draws: a call
79
+ * of kind `other`, or a `Read` Copilot makes of a tool that only reads. A `Read` of a file is no MCP call.
80
+ */
81
+ function titledCall(name: string, input: Readonly<Record<string, unknown>>, servers: readonly string[]): Omit<McpCall, 'output'> | null {
82
+ const titledRow = name === ACP_TOOL_ROW || (name === 'Read' && input.file_path === undefined);
83
+ const title = typeof input.description === 'string' ? input.description : null;
84
+ const titled = !titledRow || title === null ? null : toolOn(title, servers, TITLE_SEPARATORS);
85
+
86
+ if (titled === null) {
87
+ return null;
88
+ }
89
+
90
+ // Antigravity hands the arguments over as `arguments`, Copilot beside the title.
91
+ return {
92
+ ...titled,
93
+ input: isRecord(input.arguments) ? input.arguments : Object.fromEntries(Object.entries(input).filter(([key]) => key !== 'description'))
94
+ };
95
+ }
96
+
97
+ /* A tool's answer out of the envelope Grok puts around an MCP answer, `{"type":"MCP",...,"output":{"OkayOutput":"..."}}`. */
98
+ function unwrapped(output: string | null): string | null {
99
+ if (output === null || !output.trimStart().startsWith('{')) {
100
+ return output;
101
+ }
102
+
103
+ try {
104
+ const parsed: unknown = JSON.parse(output);
105
+
106
+ if (!isRecord(parsed) || parsed.type !== 'MCP' || !isRecord(parsed.output)) {
107
+ return output;
108
+ }
109
+
110
+ const inner = Object.values(parsed.output);
111
+
112
+ return inner.length === 1 && typeof inner[0] === 'string' ? inner[0] : output;
113
+ } catch {
114
+ return output;
115
+ }
116
+ }
117
+
118
+ /*
119
+ * The call of an MCP tool on one of `servers` that `item` is: `mcp__<server>__<tool>` (Claude Code, the API and
120
+ * an ACP agent that marks its server), `<server>/<tool>` (Codex), or an ACP call titled with the server and the
121
+ * tool (Grok's `use_tool`, Copilot, and calls of agents from before they were marked). A name that says which
122
+ * server is read before any title, over every server, the longest name first. Null for any other call.
123
+ */
124
+ export function mcpCallOf(item: Pick<ChatToolItem, 'name' | 'input' | 'output'>, servers: readonly string[]): McpCall | null {
125
+ const input = isRecord(item.input) ? item.input : {};
126
+ const longestFirst = [...servers].sort((left, right) => right.length - left.length);
127
+ const named = namedCall(item.name, input, longestFirst);
128
+ const call = named === undefined ? titledCall(item.name, input, longestFirst) : named;
129
+
130
+ return call === null || call === undefined ? null : { ...call, output: unwrapped(item.output) };
131
+ }
132
+
133
+ function folded(text: string): string {
134
+ const line = text.replace(/\s+/g, ' ');
135
+
136
+ return line.length > FOLD_LENGTH ? `${line.slice(0, FOLD_LENGTH)}…` : line;
137
+ }
138
+
139
+ function scalarText(value: unknown): string | null {
140
+ return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' ? String(value) : null;
141
+ }
142
+
143
+ /* The lead and the fields of a call as `field=value`, each value a word a host may name; a value that is no text reads as `{…}` or `[…]`. */
144
+ function detailOf(match: ToolLookMatch, input: Readonly<Record<string, unknown>>): Pick<LookRun, 'detail' | 'words'> {
145
+ let detail = match.lead ?? '';
146
+ const words: CommandLookWord[] = [];
147
+
148
+ for (const field of match.fields ?? Object.keys(input)) {
149
+ const value = input[field];
150
+
151
+ if (value === undefined || value === null) {
152
+ continue;
153
+ }
154
+
155
+ detail += `${detail === '' ? '' : ' '}${field}=`;
156
+ const values: unknown[] = Array.isArray(value) ? value : [value];
157
+ const texts = values.map(scalarText).filter((text) => text !== null);
158
+
159
+ if (texts.length < values.length) {
160
+ detail += Array.isArray(value) ? '[…]' : '{…}';
161
+
162
+ continue;
163
+ }
164
+
165
+ texts.forEach((text, index) => {
166
+ const quoted = text === '' || /[\s",]/.test(text);
167
+ detail += `${index === 0 ? '' : ','}${quoted ? '"' : ''}`;
168
+ const start = detail.length;
169
+ detail += folded(text);
170
+ words.push({ start, end: detail.length, text, option: field });
171
+ detail += quoted ? '"' : '';
172
+ });
173
+ }
174
+
175
+ return { detail, words };
176
+ }
177
+
178
+ function read(item: ChatToolItem, looks: readonly ToolLook[]): ToolLookRun | null {
179
+ const call = mcpCallOf(
180
+ item,
181
+ looks.map(({ server }) => server)
182
+ );
183
+ const look = call === null ? undefined : looks.find(({ server }) => server === call.server);
184
+ const match = call === null || look === undefined ? null : look.describe(call.tool, call.input);
185
+
186
+ if (call === null || look === undefined || match === null) {
187
+ return null;
188
+ }
189
+
190
+ return {
191
+ look,
192
+ match,
193
+ call,
194
+ label: match.label,
195
+ group: match.group,
196
+ ...detailOf(match, call.input),
197
+ code: [],
198
+ others: [],
199
+ more: 0,
200
+ heredoc: false,
201
+ shell: false
202
+ };
203
+ }
204
+
205
+ /* The call of a look's MCP server that `item` is, read as that look's tool; null for any other call and one the look does not describe. */
206
+ export function matchToolLook(item: ChatToolItem, looks: readonly ToolLook[] | undefined): ToolLookRun | null {
207
+ if (looks === undefined || looks.length === 0) {
208
+ return null;
209
+ }
210
+
211
+ let cache = caches.get(looks);
212
+
213
+ if (cache === undefined) {
214
+ cache = new WeakMap();
215
+ caches.set(looks, cache);
216
+ }
217
+
218
+ const known = cache.get(item);
219
+
220
+ if (known !== undefined) {
221
+ return known;
222
+ }
223
+
224
+ const run = read(item, looks);
225
+ cache.set(item, run);
226
+
227
+ return run;
228
+ }
@@ -6,6 +6,17 @@ export interface FileChange {
6
6
  path: string;
7
7
  before: string;
8
8
  after: string;
9
+ // A piece of the file (an Edit's `old_string` and `new_string`), whose line numbers and last line say nothing about the file.
10
+ fragment?: boolean;
11
+ }
12
+
13
+ /* The texts a diff draws: a fragment ends where its edit does, not where its file ends, so it gets no "no final newline" mark. */
14
+ export function diffTexts(change: FileChange): { before: string; after: string } {
15
+ if (change.fragment !== true || change.before.endsWith('\n') || change.after.endsWith('\n')) {
16
+ return { before: change.before, after: change.after };
17
+ }
18
+
19
+ return { before: `${change.before}\n`, after: `${change.after}\n` };
9
20
  }
10
21
 
11
22
  function str(value: unknown): string | null {
@@ -156,7 +167,7 @@ export function fileChanges(name: string, input: unknown): FileChange[] {
156
167
  const path = str(input.file_path) ?? '';
157
168
 
158
169
  if (name === 'Edit') {
159
- return [{ path, before: str(input.old_string) ?? '', after: str(input.new_string) ?? '' }];
170
+ return [{ path, before: str(input.old_string) ?? '', after: str(input.new_string) ?? '', fragment: true }];
160
171
  }
161
172
 
162
173
  if (name === 'Write') {
@@ -164,7 +175,7 @@ export function fileChanges(name: string, input: unknown): FileChange[] {
164
175
  }
165
176
 
166
177
  if (name === 'MultiEdit' && Array.isArray(input.edits)) {
167
- return input.edits.filter(isRecord).map((edit) => ({ path, before: str(edit.old_string) ?? '', after: str(edit.new_string) ?? '' }));
178
+ return input.edits.filter(isRecord).map((edit) => ({ path, before: str(edit.old_string) ?? '', after: str(edit.new_string) ?? '', fragment: true }));
168
179
  }
169
180
 
170
181
  return [];
@@ -6,6 +6,7 @@ import type { CodeToken } from './code-lines';
6
6
  import { useChatHost, type CommandName } from '../../host';
7
7
  import { useCodeTheme } from './code-theme';
8
8
  import { tokenStyle, useCodeHighlighter, type CodeHighlighter, type Highlighter } from './highlighter';
9
+ import { ReferenceChip } from './ReferenceChip';
9
10
 
10
11
  /* One colored run of a command, as offsets into it. */
11
12
  interface Run extends CodeToken {
@@ -156,8 +157,23 @@ function draw(command: string, runs: readonly Run[] | null, from: number, to: nu
156
157
  return parts;
157
158
  }
158
159
 
159
- /* A word as its name, in a frame so it reads as a reference; the word itself stays in the text, for a find. */
160
+ /*
161
+ * A word as its name: the `#` chip of the reference it is, else in a frame so it reads as one. The word itself
162
+ * stays in the text, for a find.
163
+ */
160
164
  function Name({ named }: { named: NamedWord }) {
165
+ const { reference } = named.name;
166
+
167
+ if (reference !== undefined) {
168
+ // A click opens what the chip points at and leaves the line it stands on as it was.
169
+ return (
170
+ <span className="font-sans" onClick={(e) => e.stopPropagation()}>
171
+ <ReferenceChip id={reference} lastName={named.name.name} />
172
+ <span className="sr-only">{named.word}</span>
173
+ </span>
174
+ );
175
+ }
176
+
161
177
  return (
162
178
  <Tooltip label={named.word}>
163
179
  <span className="inline-flex items-center gap-1 rounded bg-surface-hover px-1 font-sans text-text ring-1 ring-border ring-inset">
@@ -192,8 +208,19 @@ function drawNamed(command: string, runs: readonly Run[] | null, names: readonly
192
208
  * `python3 -c` argument, a heredoc) in its own language. Plain text until the grammars are in, which
193
209
  * changes no size; a command past the limit stays plain. `code` adds stretches whose language the
194
210
  * caller knows, and `names` draws words as the names a host gave them, both as offsets into `command`.
211
+ * `plain` draws text that is no shell source uncolored, with its names.
195
212
  */
196
- export function ShellCommand({ command, code = NO_CODE, names = NO_NAMES }: { command: string; code?: readonly EmbeddedCode[]; names?: readonly NamedWord[] }) {
213
+ export function ShellCommand({
214
+ command,
215
+ code = NO_CODE,
216
+ names = NO_NAMES,
217
+ plain = false
218
+ }: {
219
+ command: string;
220
+ code?: readonly EmbeddedCode[];
221
+ names?: readonly NamedWord[];
222
+ plain?: boolean;
223
+ }) {
197
224
  // The highlighter's cache fills in place; compiled, the runs it gave before its grammars loaded would stay.
198
225
  'use no memo';
199
226
  const theme = useCodeTheme();
@@ -201,11 +228,11 @@ export function ShellCommand({ command, code = NO_CODE, names = NO_NAMES }: { co
201
228
  const highlighter = useCodeHighlighter();
202
229
  // Bumped when a load settles, so the cache is asked again.
203
230
  const [, setLoads] = useState(0);
204
- const tooLong = command.length > EMBEDDED_CODE_LIMIT;
205
- const runs = tooLong ? null : highlight(command, code, theme, highlighter);
231
+ const uncolored = plain || command.length > EMBEDDED_CODE_LIMIT;
232
+ const runs = uncolored ? null : highlight(command, code, theme, highlighter);
206
233
 
207
234
  useEffect(() => {
208
- if (runs !== null || tooLong) {
235
+ if (runs !== null || uncolored) {
209
236
  return;
210
237
  }
211
238
 
@@ -218,7 +245,7 @@ export function ShellCommand({ command, code = NO_CODE, names = NO_NAMES }: { co
218
245
  return () => {
219
246
  cancelled = true;
220
247
  };
221
- }, [highlighter, command, code, theme, custom, runs, tooLong]);
248
+ }, [highlighter, command, code, theme, custom, runs, uncolored]);
222
249
 
223
250
  if (names.length > 0) {
224
251
  return <>{drawNamed(command, runs, names)}</>;
@@ -44,7 +44,7 @@ export function SubagentTimeline({
44
44
  }) {
45
45
  const { t } = useTranslation('agent-chat');
46
46
  const scope = useChatScope();
47
- const { commandLooks } = useChatHost();
47
+ const { commandLooks, toolLooks, saidBy } = useChatHost();
48
48
  const { trail, show } = useSubagentTrail(chatId);
49
49
  const [state, setState] = useState<SubagentConversationState>(INITIAL_CONVERSATION);
50
50
  const controller = useRef<SubagentConversation | null>(null);
@@ -89,6 +89,7 @@ export function SubagentTimeline({
89
89
  expandedSubagents: subagents.ids,
90
90
  activeTurnId: null,
91
91
  commandLooks,
92
+ toolLooks,
92
93
  hideTools
93
94
  });
94
95
 
@@ -185,7 +186,7 @@ export function SubagentTimeline({
185
186
  const previous = index > 0 ? rows[index - 1]! : null;
186
187
 
187
188
  return (
188
- <div key={row.id} data-item-id={row.id} className={rowRhythm(row, previous)}>
189
+ <div key={row.id} data-item-id={row.id} className={rowRhythm(row, previous, saidBy !== undefined)}>
189
190
  <Row
190
191
  row={row}
191
192
  chatId={chatId}
@@ -291,10 +291,11 @@ export function Timeline({
291
291
  activeTurnId,
292
292
  forkedTurns,
293
293
  commandLooks: host.commandLooks,
294
+ toolLooks: host.toolLooks,
294
295
  hideTools
295
296
  }
296
297
  );
297
- }, [order, items, groups.ids, turns.ids, subagents.ids, activeTurnId, forkedTurns, host.commandLooks, hideTools]);
298
+ }, [order, items, groups.ids, turns.ids, subagents.ids, activeTurnId, forkedTurns, host.commandLooks, host.toolLooks, hideTools]);
298
299
 
299
300
  const cards = useHostThreadCards(scopeId, chatId);
300
301
  const drawsVisuals = host.visuals !== null;
@@ -5,7 +5,7 @@ import { getFiletypeFromFileName } from '@pierre/diffs';
5
5
  import type { EditorEngine } from '@adecore/editor';
6
6
  import { DiffView, type DiffSource } from '@adecore/editor-react';
7
7
  import { diffDocument, patchOf, type DiffDocument } from '@adecore/merge';
8
- import type { FileChange } from '../../logic/tools';
8
+ import { diffTexts, type FileChange } from '../../logic/tools';
9
9
  import { useDiffSourceTokens } from '../use-diff-source-tokens';
10
10
  import { diffSourceBudget } from './diff-source-budget';
11
11
  import { DiffOmitted } from './DiffOmitted';
@@ -25,6 +25,7 @@ function ReadyDiff({
25
25
  fill,
26
26
  layout,
27
27
  maxHeight,
28
+ numbered,
28
29
  onSource
29
30
  }: {
30
31
  document: DiffDocument;
@@ -34,6 +35,7 @@ function ReadyDiff({
34
35
  fill: boolean;
35
36
  layout: 'unified' | 'split';
36
37
  maxHeight: number;
38
+ numbered: boolean;
37
39
  onSource?(source: DiffSource): void | (() => void);
38
40
  }) {
39
41
  useReviewSettled();
@@ -55,6 +57,7 @@ function ReadyDiff({
55
57
  layout={layout}
56
58
  wrap={wrap}
57
59
  fill={fill}
60
+ numbered={numbered}
58
61
  className="chat-diff select-text"
59
62
  onSource={onSource}
60
63
  />
@@ -70,6 +73,7 @@ export function EditorDocumentDiff({
70
73
  fill = false,
71
74
  layout = 'unified',
72
75
  maxHeight = 480,
76
+ numbered = true,
73
77
  onSource
74
78
  }: {
75
79
  document: DiffDocument;
@@ -80,6 +84,7 @@ export function EditorDocumentDiff({
80
84
  fill?: boolean;
81
85
  layout?: 'unified' | 'split';
82
86
  maxHeight?: number;
87
+ numbered?: boolean;
83
88
  onSource?(source: DiffSource): void | (() => void);
84
89
  }) {
85
90
  const { t } = useTranslation('agent-chat');
@@ -130,7 +135,17 @@ export function EditorDocumentDiff({
130
135
  return engine === null ? (
131
136
  fallback
132
137
  ) : (
133
- <ReadyDiff document={document} path={path} engine={engine} wrap={wrap} fill={fill} layout={layout} maxHeight={maxHeight} onSource={onSource} />
138
+ <ReadyDiff
139
+ document={document}
140
+ path={path}
141
+ engine={engine}
142
+ wrap={wrap}
143
+ fill={fill}
144
+ layout={layout}
145
+ maxHeight={maxHeight}
146
+ numbered={numbered}
147
+ onSource={onSource}
148
+ />
134
149
  );
135
150
  }
136
151
 
@@ -147,14 +162,25 @@ export default function EditorEditDiff({
147
162
  fallback: ReactNode;
148
163
  maxHeight?: number;
149
164
  }) {
165
+ const { before, after } = diffTexts(change);
166
+
150
167
  const document =
151
- sourceChecked || diffSourceBudget(change.before, change.after)
152
- ? diffDocument(patchOf(change.before, change.after, 3, { maxWork: EDITOR_DIFF_WORK }), { old: change.before, new: change.after })
168
+ sourceChecked || diffSourceBudget(before, after)
169
+ ? diffDocument(patchOf(before, after, 3, { maxWork: EDITOR_DIFF_WORK }), { old: before, new: after })
153
170
  : undefined;
154
171
 
155
172
  if (document === undefined) {
156
173
  return <DiffOmitted path={change.path} />;
157
174
  }
158
175
 
159
- return <EditorDocumentDiff document={document} path={change.path} loadEngine={loadEngine} fallback={fallback} maxHeight={maxHeight} />;
176
+ return (
177
+ <EditorDocumentDiff
178
+ document={document}
179
+ path={change.path}
180
+ loadEngine={loadEngine}
181
+ fallback={fallback}
182
+ maxHeight={maxHeight}
183
+ numbered={change.fragment !== true}
184
+ />
185
+ );
160
186
  }
@@ -2,21 +2,23 @@ import { LegacyDiffPool } from './LegacyDiffPool';
2
2
  import { useReviewSettled } from './review-settle';
3
3
  import { MultiFileDiff } from '@pierre/diffs/react';
4
4
  import { useDiffTheme } from '../diff-theme';
5
- import type { FileChange } from '../../logic/tools';
5
+ import { diffTexts, type FileChange } from '../../logic/tools';
6
6
  import { useHostCodeMode } from '../../../host-hooks';
7
7
 
8
8
  export default function LegacyEditDiff({ change, maxHeight }: { change: FileChange; maxHeight?: number }) {
9
9
  useReviewSettled();
10
10
  const resolved = useHostCodeMode();
11
11
  const theme = useDiffTheme();
12
- const oldFile = { name: change.path, contents: change.before };
13
- const newFile = { name: change.path, contents: change.after };
12
+ const { before, after } = diffTexts(change);
13
+ const oldFile = { name: change.path, contents: before };
14
+ const newFile = { name: change.path, contents: after };
14
15
 
15
16
  const options = {
16
17
  diffStyle: 'unified' as const,
17
18
  theme,
18
19
  themeType: resolved,
19
20
  disableFileHeader: true,
21
+ disableLineNumbers: change.fragment === true,
20
22
  overflow: 'wrap' as const,
21
23
  hunkSeparators: 'simple' as const
22
24
  };
@@ -1,5 +1,6 @@
1
1
  import type { ReactNode, Ref } from 'react';
2
2
  import clsx from 'clsx';
3
+ import { useChatHost } from '../../../host';
3
4
  import type { TimelineRow } from '../../logic/timeline';
4
5
  import { rowPosition, rowRhythm, saidToChat } from './row-rhythm';
5
6
 
@@ -14,6 +15,7 @@ export interface RowContainerProps {
14
15
 
15
16
  export function RowContainer({ row, previous, index, top, ref, children }: RowContainerProps) {
16
17
  const wide = row.kind === 'visual' && row.visual.layout === 'wide';
18
+ const hostSpeaks = useChatHost().saidBy !== undefined;
17
19
 
18
20
  return (
19
21
  <div
@@ -23,9 +25,9 @@ export function RowContainer({ row, previous, index, top, ref, children }: RowCo
23
25
  className={clsx(
24
26
  'absolute inset-x-0 top-0 mx-auto w-full',
25
27
  wide ? 'chat-wide-content' : 'chat-column-content',
26
- rowRhythm(row, previous),
28
+ rowRhythm(row, previous, hostSpeaks),
27
29
  // Turn gaps belong inside the measurement used by the virtualizer.
28
- saidToChat(row) && index > 0 && 'pt-(--chat-turn-gap)'
30
+ saidToChat(row, hostSpeaks) && index > 0 && 'pt-(--chat-turn-gap)'
29
31
  )}
30
32
  style={rowPosition(row.kind, top)}
31
33
  >