@mistriwork/agent-ui 1.4.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /**
3
3
  * `@mistriwork/agent-ui/pierre`: Optional adapter connecting `@pierre/diffs`
4
- * (Shiki code/diff viewer, virtualized split/unified diffs, inline annotations,
5
- * `renderSelectionAction` -> "Add to chat", and lazy `@pierre/diffs/edit`) and
4
+ * (`@pierre/diffs@1.7.2` Shiki code/diff viewer, virtualized split/unified
5
+ * diffs, inline annotations, `enableGutterUtility` / `onGutterUtilityClick`,
6
+ * and top-level `edit` + `EditProvider` / `@pierre/diffs/edit`) and
6
7
  * `@pierre/trees` (virtualized file tree) into `@mistriwork/agent-ui`'s
7
8
  * `<AgentUiProvider>` surface seam.
8
9
  *
@@ -11,32 +12,94 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
12
  * imported Pierre modules so Vite/Rolldown tree-shakes cleanly, and surfaces
12
13
  * fall back gracefully to built-in zero-dep primitives if omitted.
13
14
  */
14
- import { useMemo } from 'react';
15
- import { Button } from '@mistriwork/mistri/ui';
16
- import { DefaultFileTree } from './fileTree.js';
15
+ import { useCallback, useMemo, useRef, useState } from 'react';
16
+ import { Badge } from '@mistriwork/mistri/ui';
17
+ import { DefaultFileTree, resolveFileTreeRoots } from './fileTree.js';
17
18
  import { DefaultCodeSurface, DefaultDiffSurface, } from './surfaces.js';
18
19
  const DEFAULT_THEME = { dark: 'pierre-dark', light: 'pierre-light' };
19
- function renderChatSelectionButton(path, content, selection, onAddToChat) {
20
- const startLine = Math.min(selection.start, selection.end);
21
- const endLine = Math.max(selection.start, selection.end);
22
- const text = selection.text ??
23
- content
24
- .split('\n')
25
- .slice(Math.max(0, startLine - 1), endLine)
26
- .join('\n');
27
- return (_jsx(Button, { size: "sm", variant: "primary", onClick: () => onAddToChat({ path, startLine, endLine, text }), children: "Add to chat" }));
20
+ function extractLineRange(content, startLine, endLine) {
21
+ return content
22
+ .split('\n')
23
+ .slice(Math.max(0, startLine - 1), endLine)
24
+ .join('\n');
28
25
  }
29
- export function PierreCodeSurface({ diffs, theme = DEFAULT_THEME, themeMode = 'system', unsafeCSS, createEditor, ...props }) {
30
- if (!diffs?.File)
31
- return _jsx(DefaultCodeSurface, { ...props });
32
- const PierreFile = diffs.File;
33
- const EditProvider = diffs.EditProvider;
34
- const file = {
35
- name: props.path,
36
- contents: props.content,
37
- ...(props.language ? { lang: props.language } : {}),
26
+ function buildSelectionSnippet(path, content, range) {
27
+ const startLine = Math.min(range.start, range.end);
28
+ const endLine = Math.max(range.start, range.end);
29
+ const text = range.text ?? extractLineRange(content, startLine, endLine);
30
+ return { path, startLine, endLine, text };
31
+ }
32
+ /**
33
+ * Keep a memoized `PierreFileContents` reference stable while live editing is
34
+ * active: per `@pierre/diffs@1.7.2`'s `onEditChange` contract, `file.contents`
35
+ * must not be mutated on every keystroke while `edit` is enabled, otherwise
36
+ * Pierre resets the active editor state. If a parent mirrors `onChange` into
37
+ * state and passes the echoed text back as `contents`, this hook shields the
38
+ * `file` object reference until `name`/`lang` changes, editing ends, or an
39
+ * external update provides different contents.
40
+ */
41
+ function useStableEditableFile(name, contents, lang, editable, lastEmittedRef) {
42
+ const fileRef = useRef(null);
43
+ return useMemo(() => {
44
+ const prev = fileRef.current;
45
+ if (prev && prev.name === name && prev.lang === lang) {
46
+ if (prev.contents === contents)
47
+ return prev;
48
+ if (editable && lastEmittedRef.current?.key === name && lastEmittedRef.current.contents === contents) {
49
+ return prev;
50
+ }
51
+ }
52
+ const next = { name, contents, ...(lang ? { lang } : {}) };
53
+ fileRef.current = next;
54
+ return next;
55
+ }, [name, contents, lang, editable, lastEmittedRef]);
56
+ }
57
+ function PierreCodeSurfaceMounted({ diffs, theme = DEFAULT_THEME, themeMode = 'system', unsafeCSS, createEditor, ...props }) {
58
+ const editable = Boolean(props.editable);
59
+ const lastEmittedRef = useRef(null);
60
+ const latestRef = useRef({
61
+ path: props.path,
62
+ content: props.content,
63
+ onChange: props.onChange,
64
+ onAddToChat: props.onAddToChat,
65
+ });
66
+ latestRef.current = {
67
+ path: props.path,
68
+ content: props.content,
69
+ onChange: props.onChange,
70
+ onAddToChat: props.onAddToChat,
38
71
  };
39
- const lineAnnotations = [
72
+ const file = useStableEditableFile(props.path, props.content, props.language, editable, lastEmittedRef);
73
+ const handleEditChange = useCallback((ev) => {
74
+ lastEmittedRef.current = { key: latestRef.current.path, contents: ev.file.contents };
75
+ latestRef.current.onChange?.(ev.file.contents);
76
+ }, []);
77
+ const handleEditComplete = useCallback((ev) => {
78
+ lastEmittedRef.current = { key: latestRef.current.path, contents: ev.file.contents };
79
+ latestRef.current.onChange?.(ev.file.contents);
80
+ return 'accept';
81
+ }, []);
82
+ const hasGutterAction = Boolean(props.onAddToChat);
83
+ const handleGutterUtilityClick = useCallback((range) => {
84
+ const { path, content, onAddToChat } = latestRef.current;
85
+ if (!onAddToChat)
86
+ return;
87
+ const activeContent = lastEmittedRef.current?.key === path ? lastEmittedRef.current.contents : content;
88
+ onAddToChat(buildSelectionSnippet(path, activeContent, range));
89
+ }, []);
90
+ const options = useMemo(() => ({
91
+ theme,
92
+ themeType: themeMode,
93
+ ...(unsafeCSS ? { unsafeCSS } : {}),
94
+ ...(hasGutterAction
95
+ ? {
96
+ enableLineSelection: true,
97
+ enableGutterUtility: true,
98
+ onGutterUtilityClick: handleGutterUtilityClick,
99
+ }
100
+ : {}),
101
+ }), [theme, themeMode, unsafeCSS, hasGutterAction, handleGutterUtilityClick]);
102
+ const lineAnnotations = useMemo(() => [
40
103
  ...(props.markers ?? []).map((m) => ({
41
104
  lineNumber: m.line,
42
105
  metadata: `${m.severity.toUpperCase()}: ${m.message}`,
@@ -45,64 +108,203 @@ export function PierreCodeSurface({ diffs, theme = DEFAULT_THEME, themeMode = 's
45
108
  lineNumber: a.line,
46
109
  metadata: a.body,
47
110
  })),
48
- ];
49
- const options = {
50
- theme,
51
- themeType: themeMode,
52
- ...(unsafeCSS ? { unsafeCSS } : {}),
53
- ...(props.editable ? { edit: true, onChange: props.onChange } : {}),
111
+ ], [props.markers, props.annotations]);
112
+ const renderAnnotation = useCallback((ann) => ann.metadata, []);
113
+ const PierreFile = diffs.File;
114
+ const EditProvider = diffs.EditProvider;
115
+ const fileProps = {
116
+ file,
117
+ options,
118
+ edit: editable,
119
+ editStateKey: editable ? props.path : undefined,
120
+ onEditChange: editable ? handleEditChange : undefined,
121
+ onEditComplete: editable ? handleEditComplete : undefined,
122
+ lineAnnotations: lineAnnotations.length > 0 ? lineAnnotations : undefined,
123
+ renderAnnotation: lineAnnotations.length > 0 ? renderAnnotation : undefined,
124
+ className: props.className,
54
125
  };
55
- const rendered = (_jsx(PierreFile, { file: file, options: options, lineAnnotations: lineAnnotations.length > 0 ? lineAnnotations : undefined, renderAnnotation: lineAnnotations.length > 0 ? (ann) => ann.metadata : undefined, renderSelectionAction: props.onAddToChat ? (sel) => renderChatSelectionButton(props.path, props.content, sel, props.onAddToChat) : undefined, className: props.className }));
56
- if (props.editable && EditProvider) {
57
- return _jsx(EditProvider, { createEditor: createEditor, children: rendered });
126
+ const rendered = _jsx(PierreFile, { ...fileProps });
127
+ if (editable && EditProvider) {
128
+ const providerProps = { createEditor };
129
+ return _jsx(EditProvider, { ...providerProps, children: rendered });
58
130
  }
59
131
  return rendered;
60
132
  }
61
- export function PierreDiffSurface({ diffs, theme = DEFAULT_THEME, themeMode = 'system', unsafeCSS, createEditor, ...props }) {
62
- if (!diffs)
63
- return _jsx(DefaultDiffSurface, { ...props });
64
- const EditProvider = diffs.EditProvider;
65
- const lineAnnotations = props.annotations?.map((ann) => ({
66
- side: ann.side,
67
- lineNumber: ann.line,
68
- metadata: ann.body,
69
- }));
70
- const options = {
133
+ /**
134
+ * `@pierre/diffs/react` `<File>` surface wrapper with automatic zero-dep fallback.
135
+ *
136
+ * Note: While `editable` is true, avoid replacing `content` from parent state on
137
+ * every keystroke unless needed — `PierreCodeSurface` shields echoed `onChange`
138
+ * values so `@pierre/diffs`'s active editor stays stable.
139
+ */
140
+ export function PierreCodeSurface(props) {
141
+ if (!props.diffs?.File) {
142
+ const { diffs: _d, theme: _t, themeMode: _tm, unsafeCSS: _u, createEditor: _c, ...rest } = props;
143
+ return _jsx(DefaultCodeSurface, { ...rest });
144
+ }
145
+ return _jsx(PierreCodeSurfaceMounted, { ...props, diffs: props.diffs });
146
+ }
147
+ function PierreDiffSurfaceMounted({ diffs, theme = DEFAULT_THEME, themeMode = 'system', unsafeCSS, createEditor, ...props }) {
148
+ const editable = Boolean(props.editable);
149
+ const editKey = props.newFile?.name ?? props.selectedFile;
150
+ const lastEmittedRef = useRef(null);
151
+ const latestRef = useRef({
152
+ editKey,
153
+ oldFile: props.oldFile,
154
+ newFile: props.newFile,
155
+ patch: props.patch,
156
+ selectedFile: props.selectedFile,
157
+ onChange: props.onChange,
158
+ onLineComment: props.onLineComment,
159
+ onAddToChat: props.onAddToChat,
160
+ });
161
+ latestRef.current = {
162
+ editKey,
163
+ oldFile: props.oldFile,
164
+ newFile: props.newFile,
165
+ patch: props.patch,
166
+ selectedFile: props.selectedFile,
167
+ onChange: props.onChange,
168
+ onLineComment: props.onLineComment,
169
+ onAddToChat: props.onAddToChat,
170
+ };
171
+ const oldFile = useMemo(() => props.oldFile
172
+ ? { name: props.oldFile.name, contents: props.oldFile.contents, ...(props.oldFile.lang ? { lang: props.oldFile.lang } : {}) }
173
+ : undefined, [props.oldFile?.name, props.oldFile?.contents, props.oldFile?.lang]);
174
+ const stableNewFile = useStableEditableFile(props.newFile?.name ?? '', props.newFile?.contents ?? '', props.newFile?.lang, editable, lastEmittedRef);
175
+ const newFile = props.newFile ? stableNewFile : undefined;
176
+ const handleEditChange = useCallback((ev) => {
177
+ const key = latestRef.current.editKey ?? ev.file.name;
178
+ lastEmittedRef.current = { key, contents: ev.file.contents };
179
+ latestRef.current.onChange?.(ev.file.contents);
180
+ }, []);
181
+ const handleEditComplete = useCallback((ev) => {
182
+ const key = latestRef.current.editKey ?? ev.file.name;
183
+ lastEmittedRef.current = { key, contents: ev.file.contents };
184
+ latestRef.current.onChange?.(ev.file.contents);
185
+ return 'accept';
186
+ }, []);
187
+ const hasGutterAction = Boolean(props.onLineComment || props.onAddToChat);
188
+ const handleGutterUtilityClick = useCallback((range) => {
189
+ const { oldFile: oldF, newFile: newF, patch, selectedFile, onLineComment, onAddToChat } = latestRef.current;
190
+ const isDeletion = range.side === 'deletions';
191
+ const targetPath = newF ? (isDeletion && oldF ? oldF.name : newF.name) : (selectedFile ?? 'diff');
192
+ const sourceContent = newF
193
+ ? isDeletion && oldF
194
+ ? oldF.contents
195
+ : lastEmittedRef.current?.key === newF.name
196
+ ? lastEmittedRef.current.contents
197
+ : newF.contents
198
+ : (patch ?? '');
199
+ const snippet = buildSelectionSnippet(targetPath, sourceContent, range);
200
+ onLineComment?.(snippet.path, snippet.startLine, snippet.text);
201
+ onAddToChat?.(snippet);
202
+ }, []);
203
+ const diffStyle = props.diffStyle ?? 'split';
204
+ const options = useMemo(() => ({
71
205
  theme,
72
206
  themeType: themeMode,
73
- diffStyle: props.diffStyle ?? 'split',
207
+ diffStyle,
74
208
  ...(unsafeCSS ? { unsafeCSS } : {}),
75
- ...(props.editable ? { edit: true, onChange: props.onChange } : {}),
76
- };
209
+ ...(hasGutterAction
210
+ ? {
211
+ enableLineSelection: true,
212
+ enableGutterUtility: true,
213
+ onGutterUtilityClick: handleGutterUtilityClick,
214
+ }
215
+ : {}),
216
+ }), [theme, themeMode, diffStyle, unsafeCSS, hasGutterAction, handleGutterUtilityClick]);
217
+ const lineAnnotations = useMemo(() => props.annotations?.map((ann) => ({
218
+ side: ann.side,
219
+ lineNumber: ann.line,
220
+ metadata: ann.body,
221
+ })), [props.annotations]);
222
+ const renderAnnotation = useCallback((ann) => ann.metadata, []);
223
+ const EditProvider = diffs.EditProvider;
77
224
  let rendered = null;
78
- if (props.oldFile && props.newFile && diffs.MultiFileDiff) {
225
+ if (oldFile && newFile && diffs.MultiFileDiff) {
79
226
  const MultiFileDiff = diffs.MultiFileDiff;
80
- rendered = (_jsx(MultiFileDiff, { oldFile: props.oldFile, newFile: props.newFile, options: options, lineAnnotations: lineAnnotations, renderAnnotation: lineAnnotations ? (ann) => ann.metadata : undefined, renderSelectionAction: props.onAddToChat
81
- ? (sel) => renderChatSelectionButton(props.newFile.name, props.newFile.contents, sel, props.onAddToChat)
82
- : undefined, className: props.className }));
227
+ const multiProps = {
228
+ oldFile,
229
+ newFile,
230
+ options,
231
+ edit: editable,
232
+ editStateKey: editable ? editKey : undefined,
233
+ onEditChange: editable ? handleEditChange : undefined,
234
+ onEditComplete: editable ? handleEditComplete : undefined,
235
+ lineAnnotations,
236
+ renderAnnotation: lineAnnotations ? renderAnnotation : undefined,
237
+ className: props.className,
238
+ };
239
+ rendered = _jsx(MultiFileDiff, { ...multiProps });
83
240
  }
84
241
  else if (props.patch && diffs.PatchDiff) {
85
242
  const PatchDiff = diffs.PatchDiff;
86
- rendered = (_jsx(PatchDiff, { patch: props.patch, options: options, lineAnnotations: lineAnnotations, renderAnnotation: lineAnnotations ? (ann) => ann.metadata : undefined, renderSelectionAction: props.onAddToChat
87
- ? (sel) => renderChatSelectionButton(props.selectedFile ?? 'diff', props.patch, sel, props.onAddToChat)
88
- : undefined, className: props.className }));
243
+ const patchProps = {
244
+ patch: props.patch,
245
+ options,
246
+ edit: editable,
247
+ editStateKey: editable ? editKey : undefined,
248
+ onEditChange: editable ? handleEditChange : undefined,
249
+ onEditComplete: editable ? handleEditComplete : undefined,
250
+ lineAnnotations,
251
+ renderAnnotation: lineAnnotations ? renderAnnotation : undefined,
252
+ className: props.className,
253
+ };
254
+ rendered = _jsx(PatchDiff, { ...patchProps });
89
255
  }
90
256
  else {
91
257
  return _jsx(DefaultDiffSurface, { ...props });
92
258
  }
93
- if (props.editable && EditProvider) {
94
- return _jsx(EditProvider, { createEditor: createEditor, children: rendered });
259
+ if (editable && EditProvider) {
260
+ const providerProps = { createEditor };
261
+ return _jsx(EditProvider, { ...providerProps, children: rendered });
95
262
  }
96
263
  return rendered;
97
264
  }
98
- function PierreFileTreeMounted({ trees, ...props }) {
99
- const flatPaths = useMemo(() => {
100
- if (props.paths)
101
- return props.paths;
102
- if (props.entries)
103
- return props.entries.map((entry) => entry.path);
104
- return [];
105
- }, [props.paths, props.entries]);
265
+ function PierreMultiRootDiffSurface(props) {
266
+ const [collapsedRoots, setCollapsedRoots] = useState(() => new Set());
267
+ const roots = props.roots ?? [];
268
+ const toggleRoot = useCallback((rootId) => {
269
+ setCollapsedRoots((prev) => {
270
+ const next = new Set(prev);
271
+ if (next.has(rootId))
272
+ next.delete(rootId);
273
+ else
274
+ next.add(rootId);
275
+ return next;
276
+ });
277
+ }, []);
278
+ if (roots.length === 0) {
279
+ return props.empty ? _jsx("div", { className: props.className, children: props.empty }) : null;
280
+ }
281
+ return (_jsx("div", { className: props.className ? `aui-diff-roots ${props.className}` : 'aui-diff-roots', children: roots.map((root) => {
282
+ const label = root.label ?? root.id;
283
+ const isCollapsed = collapsedRoots.has(root.id);
284
+ return (_jsxs("section", { className: "aui-diff-root", "aria-label": label, children: [_jsxs("button", { type: "button", className: "aui-diff-root-head", "aria-expanded": !isCollapsed, onClick: () => toggleRoot(root.id), children: [_jsx("span", { className: "aui-file-tree-caret", "aria-hidden": "true", children: isCollapsed ? '▸' : '▾' }), _jsx("span", { className: "aui-diff-root-label", children: label }), root.badge ? _jsx(Badge, { tone: "neutral", children: root.badge }) : null] }), !isCollapsed ? (_jsx("div", { className: "aui-diff-root-body", children: _jsx(PierreDiffSurfaceMounted, { ...props, roots: undefined, patch: root.patch, files: root.files, oldFile: root.oldFile, newFile: root.newFile, selectedFile: props.selectedRoot && props.selectedRoot !== root.id ? undefined : props.selectedFile, onSelectFile: (path) => {
285
+ props.onSelectInRoot?.(root.id, path);
286
+ props.onSelectFile?.(path);
287
+ } }) })) : null] }, root.id));
288
+ }) }));
289
+ }
290
+ /**
291
+ * `@pierre/diffs/react` `<MultiFileDiff>` / `<PatchDiff>` surface wrapper with
292
+ * automatic zero-dep fallback and optional multi-root grouping.
293
+ *
294
+ * Note: While `editable` is true, `PierreDiffSurface` keeps `newFile` stable
295
+ * across echoed `onChange` updates per `@pierre/diffs`'s `onEditChange` contract.
296
+ */
297
+ export function PierreDiffSurface(props) {
298
+ if (!props.diffs) {
299
+ const { diffs: _d, theme: _t, themeMode: _tm, unsafeCSS: _u, createEditor: _c, ...rest } = props;
300
+ return _jsx(DefaultDiffSurface, { ...rest });
301
+ }
302
+ if (props.roots && props.roots.length > 0) {
303
+ return _jsx(PierreMultiRootDiffSurface, { ...props, diffs: props.diffs });
304
+ }
305
+ return _jsx(PierreDiffSurfaceMounted, { ...props, diffs: props.diffs });
306
+ }
307
+ function PierreFileTreeMounted({ trees, flatPaths, ...props }) {
106
308
  const { model } = trees.useFileTree({
107
309
  paths: flatPaths,
108
310
  search: props.searchable,
@@ -113,10 +315,42 @@ function PierreFileTreeMounted({ trees, ...props }) {
113
315
  return _jsx(TreeComponent, { model: model, className: props.className });
114
316
  }
115
317
  export function PierreFileTree({ trees, ...props }) {
318
+ const [collapsedRoots, setCollapsedRoots] = useState(() => new Set());
319
+ const resolvedRoots = useMemo(() => resolveFileTreeRoots({ entries: props.entries, roots: props.roots }), [props.entries, props.roots]);
320
+ const flatPaths = useMemo(() => {
321
+ if (props.paths)
322
+ return props.paths;
323
+ if (props.entries)
324
+ return props.entries.map((entry) => entry.path);
325
+ return [];
326
+ }, [props.paths, props.entries]);
327
+ const toggleRoot = useCallback((rootId) => {
328
+ setCollapsedRoots((prev) => {
329
+ const next = new Set(prev);
330
+ if (next.has(rootId))
331
+ next.delete(rootId);
332
+ else
333
+ next.add(rootId);
334
+ return next;
335
+ });
336
+ }, []);
116
337
  if (!trees?.FileTree || !trees?.useFileTree) {
117
338
  return _jsx(DefaultFileTree, { ...props });
118
339
  }
119
- return _jsx(PierreFileTreeMounted, { trees: trees, ...props });
340
+ if (resolvedRoots && resolvedRoots.length > 0) {
341
+ return (_jsx("div", { className: props.className ? `aui-file-tree aui-file-tree-roots ${props.className}` : 'aui-file-tree aui-file-tree-roots', children: resolvedRoots.map((root) => {
342
+ const label = root.label ?? root.id;
343
+ const rootPaths = root.paths ? root.paths : (root.entries ?? []).map((entry) => entry.path);
344
+ const isCollapsed = collapsedRoots.has(root.id);
345
+ return (_jsxs("section", { className: "aui-file-tree-root", "aria-label": label, children: [_jsxs("button", { type: "button", className: "aui-file-tree-root-head", "aria-expanded": !isCollapsed, onClick: () => toggleRoot(root.id), children: [_jsx("span", { className: "aui-file-tree-caret", "aria-hidden": "true", children: isCollapsed ? '▸' : '▾' }), _jsx("span", { className: "aui-file-tree-root-label", children: label }), root.badge ? _jsx(Badge, { tone: "neutral", children: root.badge }) : null] }), !isCollapsed ? (_jsx(PierreFileTreeMounted, { trees: trees, flatPaths: rootPaths, ...props, roots: undefined, className: undefined, onSelect: (path) => {
346
+ props.onSelectInRoot?.(root.id, path);
347
+ props.onSelect(path);
348
+ } }, `${root.id}:${rootPaths.join('\0')}`)) : null] }, root.id));
349
+ }) }));
350
+ }
351
+ /* `@pierre/trees/react`'s `useFileTree` initializes `new FileTree(options)` once on mount inside `useState`,
352
+ so keying on the joined path list ensures async file lists loaded after mount populate the tree cleanly. */
353
+ return _jsx(PierreFileTreeMounted, { trees: trees, flatPaths: flatPaths, ...props }, flatPaths.join('\0'));
120
354
  }
121
355
  /* ============================================================================
122
356
  * 3. Surface Bundle Factory for `<AgentUiProvider surfaces={...}>`
@@ -51,11 +51,22 @@ export interface DiffSurfaceFileInput {
51
51
  readonly contents: string;
52
52
  readonly lang?: string;
53
53
  }
54
+ export interface DiffSurfaceRoot {
55
+ readonly id: string;
56
+ readonly label?: string;
57
+ readonly badge?: string;
58
+ readonly patch?: string;
59
+ readonly files?: readonly DiffFile[];
60
+ readonly oldFile?: DiffSurfaceFileInput;
61
+ readonly newFile?: DiffSurfaceFileInput;
62
+ }
54
63
  export interface DiffSurfaceProps {
55
64
  /** Raw unified diff text (e.g. `git diff`). */
56
65
  readonly patch?: string;
57
66
  /** Structured file list (compatible with `<DiffView>`). */
58
67
  readonly files?: readonly DiffFile[];
68
+ /** Optional multi-root / multi-repo diff groups rendered under collapsible headers. */
69
+ readonly roots?: readonly DiffSurfaceRoot[];
59
70
  /** Explicit old/new file pair for file-to-file diffing (used natively by Pierre `FileDiff`). */
60
71
  readonly oldFile?: DiffSurfaceFileInput;
61
72
  readonly newFile?: DiffSurfaceFileInput;
@@ -63,10 +74,16 @@ export interface DiffSurfaceProps {
63
74
  readonly editable?: boolean;
64
75
  readonly onChange?: (nextNewContent: string) => void;
65
76
  readonly selectedFile?: string;
77
+ /** Optional selected root id when rendering multi-root diffs. */
78
+ readonly selectedRoot?: string;
66
79
  readonly onSelectFile?: (path: string) => void;
80
+ /** Called when selecting a file inside a multi-root diff. */
81
+ readonly onSelectInRoot?: (rootId: string, path: string) => void;
67
82
  readonly annotations?: readonly DiffAnnotation[];
68
83
  readonly onLineComment?: (file: string, line: number, content: string) => void;
69
84
  readonly onAddToChat?: (snippet: CodeSelectionSnippet) => void;
85
+ /** Maximum lines rendered per file in the fallback `<DiffView>` before truncation. */
86
+ readonly maxLinesPerFile?: number;
70
87
  readonly empty?: ReactNode;
71
88
  readonly className?: string;
72
89
  }
@@ -84,7 +101,7 @@ export declare function AgentUiProvider({ surfaces, children }: AgentUiProviderP
84
101
  /** Read the currently registered code/diff/file-tree surface renderers. */
85
102
  export declare function useAgentUiSurfaces(): AgentUiSurfaces;
86
103
  export declare function DefaultCodeSurface({ path, content, language, editable, onChange, markers, annotations, onAddToChat, className, }: CodeSurfaceProps): import("react").JSX.Element;
87
- export declare function DefaultDiffSurface({ patch, files, oldFile, newFile, selectedFile, onSelectFile, onLineComment, empty, className, }: DiffSurfaceProps): import("react").JSX.Element;
104
+ export declare function DefaultDiffSurface({ patch, files, roots, oldFile, newFile, selectedFile, selectedRoot, onSelectFile, onSelectInRoot, onLineComment, maxLinesPerFile, empty, className, }: DiffSurfaceProps): import("react").JSX.Element;
88
105
  /** Code viewer/editor surface: delegates to registered `surfaces.code` (e.g. Pierre) or uses the built-in fallback. */
89
106
  export declare function CodeSurface(props: CodeSurfaceProps): import("react").JSX.Element;
90
107
  /** Diff viewer/editor surface: delegates to registered `surfaces.diff` (e.g. Pierre) or uses `<DiffView>`. */
package/dist/surfaces.js CHANGED
@@ -100,7 +100,7 @@ function buildFallbackPatchFromPair(oldFile, newFile) {
100
100
  }
101
101
  return out.join('\n');
102
102
  }
103
- export function DefaultDiffSurface({ patch, files, oldFile, newFile, selectedFile, onSelectFile, onLineComment, empty, className, }) {
103
+ export function DefaultDiffSurface({ patch, files, roots, oldFile, newFile, selectedFile, selectedRoot, onSelectFile, onSelectInRoot, onLineComment, maxLinesPerFile, empty, className, }) {
104
104
  const resolvedPatch = useMemo(() => {
105
105
  if (patch)
106
106
  return patch;
@@ -108,7 +108,18 @@ export function DefaultDiffSurface({ patch, files, oldFile, newFile, selectedFil
108
108
  return buildFallbackPatchFromPair(oldFile, newFile);
109
109
  return undefined;
110
110
  }, [patch, oldFile, newFile]);
111
- return (_jsx(DiffView, { diff: resolvedPatch, files: files, selectedFile: selectedFile, onSelectFile: onSelectFile, onLineComment: onLineComment, empty: empty, className: className }));
111
+ const resolvedRoots = useMemo(() => {
112
+ if (!roots || roots.length === 0)
113
+ return undefined;
114
+ return roots.map((root) => ({
115
+ id: root.id,
116
+ label: root.label,
117
+ badge: root.badge,
118
+ files: root.files,
119
+ diff: root.patch ?? (root.oldFile && root.newFile ? buildFallbackPatchFromPair(root.oldFile, root.newFile) : undefined),
120
+ }));
121
+ }, [roots]);
122
+ return (_jsx(DiffView, { diff: resolvedPatch, files: files, roots: resolvedRoots, selectedFile: selectedFile, selectedRoot: selectedRoot, onSelectFile: onSelectFile, onSelectInRoot: onSelectInRoot, onLineComment: onLineComment, maxLinesPerFile: maxLinesPerFile, empty: empty, className: className }));
112
123
  }
113
124
  /** Code viewer/editor surface: delegates to registered `surfaces.code` (e.g. Pierre) or uses the built-in fallback. */
114
125
  export function CodeSurface(props) {
package/dist/tools.d.ts CHANGED
@@ -14,10 +14,16 @@ export interface ToolCallInspectorProps {
14
14
  readonly selectedId?: string;
15
15
  readonly onSelect?: (id: string) => void;
16
16
  readonly title?: string;
17
+ /** Number of tool calls rendered initially before showing a "Show more" control. Default `50`. */
18
+ readonly initialVisibleCount?: number;
19
+ /** How many additional calls to reveal per click on "Show more". Default `50`. */
20
+ readonly loadMoreStep?: number;
21
+ /** Maximum characters rendered inline for a single tool call output before showing a "Show full output" toggle. Default `8000`. */
22
+ readonly maxOutputChars?: number;
17
23
  readonly empty?: ReactNode;
18
24
  readonly className?: string;
19
25
  }
20
- export declare function ToolCallInspector({ calls, selectedId, onSelect, title, empty, className }: ToolCallInspectorProps): import("react").JSX.Element;
26
+ export declare function ToolCallInspector({ calls, selectedId, onSelect, title, initialVisibleCount, loadMoreStep, maxOutputChars, empty, className, }: ToolCallInspectorProps): import("react").JSX.Element;
21
27
  export interface AnsiSegment {
22
28
  readonly text: string;
23
29
  readonly className?: string;
@@ -34,10 +40,16 @@ export interface TerminalOutputProps {
34
40
  readonly searchable?: boolean;
35
41
  readonly autoFollow?: boolean;
36
42
  readonly defaultWrap?: boolean;
43
+ /** Line count threshold above which `<TerminalOutput>` virtualizes line rendering so 50k+ line logs stay 60 FPS. Default `200`. */
44
+ readonly virtualizeThreshold?: number;
45
+ /** Estimated line height in pixels used for virtualized scrolling. Default `20`. */
46
+ readonly rowHeight?: number;
47
+ /** Extra lines rendered above and below the viewport when virtualized. Default `25`. */
48
+ readonly overscan?: number;
37
49
  readonly onClear?: () => void;
38
50
  readonly className?: string;
39
51
  }
40
- export declare function TerminalOutput({ text, lines, title, running, searchable, autoFollow, defaultWrap, onClear, className, }: TerminalOutputProps): import("react").JSX.Element;
52
+ export declare function TerminalOutput({ text, lines, title, running, searchable, autoFollow, defaultWrap, virtualizeThreshold, rowHeight, overscan, onClear, className, }: TerminalOutputProps): import("react").JSX.Element;
41
53
  export interface AgentModeOption<T extends string = string> {
42
54
  readonly value: T;
43
55
  readonly label: string;