@mistriwork/agent-ui 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pierre.d.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * (and lazy `@pierre/diffs/edit`) and `@pierre/trees` into `@mistriwork/agent-ui`.
4
4
  */
5
5
  export { PierreCodeSurface, PierreDiffSurface, PierreFileTree, createPierreSurfaces } from './pierreAdapter.js';
6
- export type { PierreAdapterOptions, PierreCodeSurfaceProps, PierreCommonOptions, PierreDiffLineAnnotation, PierreDiffSurfaceProps, PierreDiffsReactModule, PierreEditProviderProps, PierreFileContents, PierreFileProps, PierreFileTreeProps, PierreLineAnnotation, PierreMultiFileDiffProps, PierrePatchDiffProps, PierreSelectionRange, PierreThemeConfig, PierreTreesReactModule, } from './pierreAdapter.js';
6
+ export type { PierreAdapterOptions, PierreCodeSurfaceProps, PierreCommonOptions, PierreDiffLineAnnotation, PierreDiffSurfaceProps, PierreDiffsReactModule, PierreEditCompleteResult, PierreEditEvent, PierreEditProviderProps, PierreEditorFactory, PierreFileContents, PierreFileProps, PierreFileTreeProps, PierreLineAnnotation, PierreMultiFileDiffProps, PierrePatchDiffProps, PierreSelectionRange, PierreThemeConfig, PierreTreesReactModule, } from './pierreAdapter.js';
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * `@mistriwork/agent-ui/pierre`: Optional adapter connecting `@pierre/diffs`
3
- * (Shiki code/diff viewer, virtualized split/unified diffs, inline annotations,
4
- * `renderSelectionAction` -> "Add to chat", and lazy `@pierre/diffs/edit`) and
3
+ * (`@pierre/diffs@1.7.2` Shiki code/diff viewer, virtualized split/unified
4
+ * diffs, inline annotations, `enableGutterUtility` / `onGutterUtilityClick`,
5
+ * and top-level `edit` + `EditProvider` / `@pierre/diffs/edit`) and
5
6
  * `@pierre/trees` (virtualized file tree) into `@mistriwork/agent-ui`'s
6
7
  * `<AgentUiProvider>` surface seam.
7
8
  *
@@ -34,8 +35,16 @@ export interface PierreDiffLineAnnotation<T = unknown> {
34
35
  export interface PierreSelectionRange {
35
36
  readonly start: number;
36
37
  readonly end: number;
38
+ readonly side?: 'additions' | 'deletions';
39
+ readonly endSide?: 'additions' | 'deletions';
37
40
  readonly text?: string;
38
41
  }
42
+ export interface PierreEditEvent {
43
+ readonly file: PierreFileContents;
44
+ }
45
+ export type PierreEditCompleteResult = 'accept' | 'reject' | void;
46
+ /** Compatible with `@pierre/diffs/edit`'s generic `EditorFactory` without requiring casts. */
47
+ export type PierreEditorFactory = (...args: any[]) => any;
39
48
  export interface PierreCommonOptions {
40
49
  readonly theme?: string | PierreThemeConfig;
41
50
  readonly themeType?: 'light' | 'dark' | 'system';
@@ -43,57 +52,64 @@ export interface PierreCommonOptions {
43
52
  readonly overflow?: 'scroll' | 'wrap';
44
53
  readonly disableLineNumbers?: boolean;
45
54
  readonly unsafeCSS?: string;
46
- readonly edit?: boolean;
47
- readonly onChange?: (value: string) => void;
55
+ readonly enableLineSelection?: boolean;
56
+ readonly enableGutterUtility?: boolean;
57
+ readonly onGutterUtilityClick?: (range: PierreSelectionRange) => void;
48
58
  }
49
59
  export interface PierreFileProps {
50
60
  readonly file: PierreFileContents;
51
61
  readonly options?: PierreCommonOptions;
52
- readonly lineAnnotations?: readonly PierreLineAnnotation[];
62
+ readonly edit?: boolean;
63
+ readonly editStateKey?: string;
64
+ readonly onEditChange?: (event: PierreEditEvent) => void;
65
+ readonly onEditComplete?: (event: PierreEditEvent) => PierreEditCompleteResult;
66
+ readonly lineAnnotations?: PierreLineAnnotation[];
53
67
  readonly renderAnnotation?: (annotation: PierreLineAnnotation) => ReactNode;
54
- readonly renderSelectionAction?: (selection: PierreSelectionRange) => ReactNode;
55
68
  readonly className?: string;
56
69
  }
57
70
  export interface PierreMultiFileDiffProps {
58
71
  readonly oldFile: PierreFileContents;
59
72
  readonly newFile: PierreFileContents;
60
73
  readonly options?: PierreCommonOptions;
61
- readonly lineAnnotations?: readonly PierreDiffLineAnnotation[];
74
+ readonly edit?: boolean;
75
+ readonly editStateKey?: string;
76
+ readonly onEditChange?: (event: PierreEditEvent) => void;
77
+ readonly onEditComplete?: (event: PierreEditEvent) => PierreEditCompleteResult;
78
+ readonly lineAnnotations?: PierreDiffLineAnnotation[];
62
79
  readonly renderAnnotation?: (annotation: PierreDiffLineAnnotation) => ReactNode;
63
- readonly renderSelectionAction?: (selection: PierreSelectionRange) => ReactNode;
64
80
  readonly className?: string;
65
81
  }
66
82
  export interface PierrePatchDiffProps {
67
83
  readonly patch: string;
68
84
  readonly options?: PierreCommonOptions;
69
- readonly lineAnnotations?: readonly PierreDiffLineAnnotation[];
85
+ readonly edit?: boolean;
86
+ readonly editStateKey?: string;
87
+ readonly onEditChange?: (event: PierreEditEvent) => void;
88
+ readonly onEditComplete?: (event: PierreEditEvent) => PierreEditCompleteResult;
89
+ readonly lineAnnotations?: PierreDiffLineAnnotation[];
70
90
  readonly renderAnnotation?: (annotation: PierreDiffLineAnnotation) => ReactNode;
71
- readonly renderSelectionAction?: (selection: PierreSelectionRange) => ReactNode;
72
91
  readonly className?: string;
73
92
  }
74
93
  export interface PierreEditProviderProps {
75
94
  readonly children: ReactNode;
76
- readonly createEditor?: unknown;
95
+ readonly createEditor?: PierreEditorFactory;
77
96
  }
78
- /** Structural subset of `@pierre/diffs/react`. */
97
+ /**
98
+ * Structural subset of `@pierre/diffs/react`.
99
+ * Component prop types use `any` so real `@pierre/diffs/react` generic components
100
+ * (with narrow literal `SupportedLanguages`/`ThemesType` unions and `EditorFactory`)
101
+ * assign directly without caller-side type casts.
102
+ */
79
103
  export interface PierreDiffsReactModule {
80
- readonly File: ComponentType<PierreFileProps>;
81
- readonly MultiFileDiff?: ComponentType<PierreMultiFileDiffProps>;
82
- readonly PatchDiff?: ComponentType<PierrePatchDiffProps>;
83
- readonly EditProvider?: ComponentType<PierreEditProviderProps>;
104
+ readonly File: ComponentType<any>;
105
+ readonly MultiFileDiff?: ComponentType<any>;
106
+ readonly PatchDiff?: ComponentType<any>;
107
+ readonly EditProvider?: ComponentType<any>;
84
108
  }
85
109
  /** Structural subset of `@pierre/trees/react`. */
86
110
  export interface PierreTreesReactModule {
87
- readonly FileTree: ComponentType<{
88
- readonly model: unknown;
89
- readonly className?: string;
90
- }>;
91
- readonly useFileTree: (options: {
92
- readonly paths: readonly string[];
93
- readonly search?: boolean;
94
- readonly initialExpandedPaths?: readonly string[];
95
- readonly onSelect?: (path: string) => void;
96
- }) => {
111
+ readonly FileTree: ComponentType<any>;
112
+ readonly useFileTree: (options: any) => {
97
113
  readonly model: unknown;
98
114
  };
99
115
  }
@@ -110,25 +126,39 @@ export interface PierreAdapterOptions {
110
126
  readonly diffStyle?: 'split' | 'unified';
111
127
  /** Optional custom CSS injected into Pierre's Shadow DOM. */
112
128
  readonly unsafeCSS?: string;
113
- /** Optional custom `@pierre/diffs/edit` editor factory passed to `EditProvider`. */
114
- readonly createEditor?: unknown;
129
+ /** Optional `@pierre/diffs/edit` editor factory passed to `EditProvider`. */
130
+ readonly createEditor?: PierreEditorFactory;
115
131
  }
116
132
  export interface PierreCodeSurfaceProps extends CodeSurfaceProps {
117
133
  readonly diffs?: PierreDiffsReactModule;
118
134
  readonly theme?: string | PierreThemeConfig;
119
135
  readonly themeMode?: 'light' | 'dark' | 'system';
120
136
  readonly unsafeCSS?: string;
121
- readonly createEditor?: unknown;
137
+ readonly createEditor?: PierreEditorFactory;
122
138
  }
123
- export declare function PierreCodeSurface({ diffs, theme, themeMode, unsafeCSS, createEditor, ...props }: PierreCodeSurfaceProps): import("react").JSX.Element;
139
+ /**
140
+ * `@pierre/diffs/react` `<File>` surface wrapper with automatic zero-dep fallback.
141
+ *
142
+ * Note: While `editable` is true, avoid replacing `content` from parent state on
143
+ * every keystroke unless needed — `PierreCodeSurface` shields echoed `onChange`
144
+ * values so `@pierre/diffs`'s active editor stays stable.
145
+ */
146
+ export declare function PierreCodeSurface(props: PierreCodeSurfaceProps): import("react").JSX.Element;
124
147
  export interface PierreDiffSurfaceProps extends DiffSurfaceProps {
125
148
  readonly diffs?: PierreDiffsReactModule;
126
149
  readonly theme?: string | PierreThemeConfig;
127
150
  readonly themeMode?: 'light' | 'dark' | 'system';
128
151
  readonly unsafeCSS?: string;
129
- readonly createEditor?: unknown;
152
+ readonly createEditor?: PierreEditorFactory;
130
153
  }
131
- export declare function PierreDiffSurface({ diffs, theme, themeMode, unsafeCSS, createEditor, ...props }: PierreDiffSurfaceProps): import("react").JSX.Element;
154
+ /**
155
+ * `@pierre/diffs/react` `<MultiFileDiff>` / `<PatchDiff>` surface wrapper with
156
+ * automatic zero-dep fallback.
157
+ *
158
+ * Note: While `editable` is true, `PierreDiffSurface` keeps `newFile` stable
159
+ * across echoed `onChange` updates per `@pierre/diffs`'s `onEditChange` contract.
160
+ */
161
+ export declare function PierreDiffSurface(props: PierreDiffSurfaceProps): import("react").JSX.Element;
132
162
  export interface PierreFileTreeProps extends FileTreeProps {
133
163
  readonly trees?: PierreTreesReactModule;
134
164
  }
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx } 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,93 @@ 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';
15
+ import { useCallback, useMemo, useRef } from 'react';
16
16
  import { DefaultFileTree } from './fileTree.js';
17
17
  import { DefaultCodeSurface, DefaultDiffSurface, } from './surfaces.js';
18
18
  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" }));
19
+ function extractLineRange(content, startLine, endLine) {
20
+ return content
21
+ .split('\n')
22
+ .slice(Math.max(0, startLine - 1), endLine)
23
+ .join('\n');
28
24
  }
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 } : {}),
25
+ function buildSelectionSnippet(path, content, range) {
26
+ const startLine = Math.min(range.start, range.end);
27
+ const endLine = Math.max(range.start, range.end);
28
+ const text = range.text ?? extractLineRange(content, startLine, endLine);
29
+ return { path, startLine, endLine, text };
30
+ }
31
+ /**
32
+ * Keep a memoized `PierreFileContents` reference stable while live editing is
33
+ * active: per `@pierre/diffs@1.7.2`'s `onEditChange` contract, `file.contents`
34
+ * must not be mutated on every keystroke while `edit` is enabled, otherwise
35
+ * Pierre resets the active editor state. If a parent mirrors `onChange` into
36
+ * state and passes the echoed text back as `contents`, this hook shields the
37
+ * `file` object reference until `name`/`lang` changes, editing ends, or an
38
+ * external update provides different contents.
39
+ */
40
+ function useStableEditableFile(name, contents, lang, editable, lastEmittedRef) {
41
+ const fileRef = useRef(null);
42
+ return useMemo(() => {
43
+ const prev = fileRef.current;
44
+ if (prev && prev.name === name && prev.lang === lang) {
45
+ if (prev.contents === contents)
46
+ return prev;
47
+ if (editable && lastEmittedRef.current?.key === name && lastEmittedRef.current.contents === contents) {
48
+ return prev;
49
+ }
50
+ }
51
+ const next = { name, contents, ...(lang ? { lang } : {}) };
52
+ fileRef.current = next;
53
+ return next;
54
+ }, [name, contents, lang, editable, lastEmittedRef]);
55
+ }
56
+ function PierreCodeSurfaceMounted({ diffs, theme = DEFAULT_THEME, themeMode = 'system', unsafeCSS, createEditor, ...props }) {
57
+ const editable = Boolean(props.editable);
58
+ const lastEmittedRef = useRef(null);
59
+ const latestRef = useRef({
60
+ path: props.path,
61
+ content: props.content,
62
+ onChange: props.onChange,
63
+ onAddToChat: props.onAddToChat,
64
+ });
65
+ latestRef.current = {
66
+ path: props.path,
67
+ content: props.content,
68
+ onChange: props.onChange,
69
+ onAddToChat: props.onAddToChat,
38
70
  };
39
- const lineAnnotations = [
71
+ const file = useStableEditableFile(props.path, props.content, props.language, editable, lastEmittedRef);
72
+ const handleEditChange = useCallback((ev) => {
73
+ lastEmittedRef.current = { key: latestRef.current.path, contents: ev.file.contents };
74
+ latestRef.current.onChange?.(ev.file.contents);
75
+ }, []);
76
+ const handleEditComplete = useCallback((ev) => {
77
+ lastEmittedRef.current = { key: latestRef.current.path, contents: ev.file.contents };
78
+ latestRef.current.onChange?.(ev.file.contents);
79
+ return 'accept';
80
+ }, []);
81
+ const hasGutterAction = Boolean(props.onAddToChat);
82
+ const handleGutterUtilityClick = useCallback((range) => {
83
+ const { path, content, onAddToChat } = latestRef.current;
84
+ if (!onAddToChat)
85
+ return;
86
+ const activeContent = lastEmittedRef.current?.key === path ? lastEmittedRef.current.contents : content;
87
+ onAddToChat(buildSelectionSnippet(path, activeContent, range));
88
+ }, []);
89
+ const options = useMemo(() => ({
90
+ theme,
91
+ themeType: themeMode,
92
+ ...(unsafeCSS ? { unsafeCSS } : {}),
93
+ ...(hasGutterAction
94
+ ? {
95
+ enableLineSelection: true,
96
+ enableGutterUtility: true,
97
+ onGutterUtilityClick: handleGutterUtilityClick,
98
+ }
99
+ : {}),
100
+ }), [theme, themeMode, unsafeCSS, hasGutterAction, handleGutterUtilityClick]);
101
+ const lineAnnotations = useMemo(() => [
40
102
  ...(props.markers ?? []).map((m) => ({
41
103
  lineNumber: m.line,
42
104
  metadata: `${m.severity.toUpperCase()}: ${m.message}`,
@@ -45,64 +107,175 @@ export function PierreCodeSurface({ diffs, theme = DEFAULT_THEME, themeMode = 's
45
107
  lineNumber: a.line,
46
108
  metadata: a.body,
47
109
  })),
48
- ];
49
- const options = {
50
- theme,
51
- themeType: themeMode,
52
- ...(unsafeCSS ? { unsafeCSS } : {}),
53
- ...(props.editable ? { edit: true, onChange: props.onChange } : {}),
110
+ ], [props.markers, props.annotations]);
111
+ const renderAnnotation = useCallback((ann) => ann.metadata, []);
112
+ const PierreFile = diffs.File;
113
+ const EditProvider = diffs.EditProvider;
114
+ const fileProps = {
115
+ file,
116
+ options,
117
+ edit: editable,
118
+ editStateKey: editable ? props.path : undefined,
119
+ onEditChange: editable ? handleEditChange : undefined,
120
+ onEditComplete: editable ? handleEditComplete : undefined,
121
+ lineAnnotations: lineAnnotations.length > 0 ? lineAnnotations : undefined,
122
+ renderAnnotation: lineAnnotations.length > 0 ? renderAnnotation : undefined,
123
+ className: props.className,
54
124
  };
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 });
125
+ const rendered = _jsx(PierreFile, { ...fileProps });
126
+ if (editable && EditProvider) {
127
+ const providerProps = { createEditor };
128
+ return _jsx(EditProvider, { ...providerProps, children: rendered });
58
129
  }
59
130
  return rendered;
60
131
  }
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 = {
132
+ /**
133
+ * `@pierre/diffs/react` `<File>` surface wrapper with automatic zero-dep fallback.
134
+ *
135
+ * Note: While `editable` is true, avoid replacing `content` from parent state on
136
+ * every keystroke unless needed — `PierreCodeSurface` shields echoed `onChange`
137
+ * values so `@pierre/diffs`'s active editor stays stable.
138
+ */
139
+ export function PierreCodeSurface(props) {
140
+ if (!props.diffs?.File) {
141
+ const { diffs: _d, theme: _t, themeMode: _tm, unsafeCSS: _u, createEditor: _c, ...rest } = props;
142
+ return _jsx(DefaultCodeSurface, { ...rest });
143
+ }
144
+ return _jsx(PierreCodeSurfaceMounted, { ...props, diffs: props.diffs });
145
+ }
146
+ function PierreDiffSurfaceMounted({ diffs, theme = DEFAULT_THEME, themeMode = 'system', unsafeCSS, createEditor, ...props }) {
147
+ const editable = Boolean(props.editable);
148
+ const editKey = props.newFile?.name ?? props.selectedFile;
149
+ const lastEmittedRef = useRef(null);
150
+ const latestRef = useRef({
151
+ editKey,
152
+ oldFile: props.oldFile,
153
+ newFile: props.newFile,
154
+ patch: props.patch,
155
+ selectedFile: props.selectedFile,
156
+ onChange: props.onChange,
157
+ onLineComment: props.onLineComment,
158
+ onAddToChat: props.onAddToChat,
159
+ });
160
+ latestRef.current = {
161
+ editKey,
162
+ oldFile: props.oldFile,
163
+ newFile: props.newFile,
164
+ patch: props.patch,
165
+ selectedFile: props.selectedFile,
166
+ onChange: props.onChange,
167
+ onLineComment: props.onLineComment,
168
+ onAddToChat: props.onAddToChat,
169
+ };
170
+ const oldFile = useMemo(() => props.oldFile
171
+ ? { name: props.oldFile.name, contents: props.oldFile.contents, ...(props.oldFile.lang ? { lang: props.oldFile.lang } : {}) }
172
+ : undefined, [props.oldFile?.name, props.oldFile?.contents, props.oldFile?.lang]);
173
+ const stableNewFile = useStableEditableFile(props.newFile?.name ?? '', props.newFile?.contents ?? '', props.newFile?.lang, editable, lastEmittedRef);
174
+ const newFile = props.newFile ? stableNewFile : undefined;
175
+ const handleEditChange = useCallback((ev) => {
176
+ const key = latestRef.current.editKey ?? ev.file.name;
177
+ lastEmittedRef.current = { key, contents: ev.file.contents };
178
+ latestRef.current.onChange?.(ev.file.contents);
179
+ }, []);
180
+ const handleEditComplete = useCallback((ev) => {
181
+ const key = latestRef.current.editKey ?? ev.file.name;
182
+ lastEmittedRef.current = { key, contents: ev.file.contents };
183
+ latestRef.current.onChange?.(ev.file.contents);
184
+ return 'accept';
185
+ }, []);
186
+ const hasGutterAction = Boolean(props.onLineComment || props.onAddToChat);
187
+ const handleGutterUtilityClick = useCallback((range) => {
188
+ const { oldFile: oldF, newFile: newF, patch, selectedFile, onLineComment, onAddToChat } = latestRef.current;
189
+ const isDeletion = range.side === 'deletions';
190
+ const targetPath = newF ? (isDeletion && oldF ? oldF.name : newF.name) : (selectedFile ?? 'diff');
191
+ const sourceContent = newF
192
+ ? isDeletion && oldF
193
+ ? oldF.contents
194
+ : lastEmittedRef.current?.key === newF.name
195
+ ? lastEmittedRef.current.contents
196
+ : newF.contents
197
+ : (patch ?? '');
198
+ const snippet = buildSelectionSnippet(targetPath, sourceContent, range);
199
+ onLineComment?.(snippet.path, snippet.startLine, snippet.text);
200
+ onAddToChat?.(snippet);
201
+ }, []);
202
+ const diffStyle = props.diffStyle ?? 'split';
203
+ const options = useMemo(() => ({
71
204
  theme,
72
205
  themeType: themeMode,
73
- diffStyle: props.diffStyle ?? 'split',
206
+ diffStyle,
74
207
  ...(unsafeCSS ? { unsafeCSS } : {}),
75
- ...(props.editable ? { edit: true, onChange: props.onChange } : {}),
76
- };
208
+ ...(hasGutterAction
209
+ ? {
210
+ enableLineSelection: true,
211
+ enableGutterUtility: true,
212
+ onGutterUtilityClick: handleGutterUtilityClick,
213
+ }
214
+ : {}),
215
+ }), [theme, themeMode, diffStyle, unsafeCSS, hasGutterAction, handleGutterUtilityClick]);
216
+ const lineAnnotations = useMemo(() => props.annotations?.map((ann) => ({
217
+ side: ann.side,
218
+ lineNumber: ann.line,
219
+ metadata: ann.body,
220
+ })), [props.annotations]);
221
+ const renderAnnotation = useCallback((ann) => ann.metadata, []);
222
+ const EditProvider = diffs.EditProvider;
77
223
  let rendered = null;
78
- if (props.oldFile && props.newFile && diffs.MultiFileDiff) {
224
+ if (oldFile && newFile && diffs.MultiFileDiff) {
79
225
  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 }));
226
+ const multiProps = {
227
+ oldFile,
228
+ newFile,
229
+ options,
230
+ edit: editable,
231
+ editStateKey: editable ? editKey : undefined,
232
+ onEditChange: editable ? handleEditChange : undefined,
233
+ onEditComplete: editable ? handleEditComplete : undefined,
234
+ lineAnnotations,
235
+ renderAnnotation: lineAnnotations ? renderAnnotation : undefined,
236
+ className: props.className,
237
+ };
238
+ rendered = _jsx(MultiFileDiff, { ...multiProps });
83
239
  }
84
240
  else if (props.patch && diffs.PatchDiff) {
85
241
  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 }));
242
+ const patchProps = {
243
+ patch: props.patch,
244
+ options,
245
+ edit: editable,
246
+ editStateKey: editable ? editKey : undefined,
247
+ onEditChange: editable ? handleEditChange : undefined,
248
+ onEditComplete: editable ? handleEditComplete : undefined,
249
+ lineAnnotations,
250
+ renderAnnotation: lineAnnotations ? renderAnnotation : undefined,
251
+ className: props.className,
252
+ };
253
+ rendered = _jsx(PatchDiff, { ...patchProps });
89
254
  }
90
255
  else {
91
256
  return _jsx(DefaultDiffSurface, { ...props });
92
257
  }
93
- if (props.editable && EditProvider) {
94
- return _jsx(EditProvider, { createEditor: createEditor, children: rendered });
258
+ if (editable && EditProvider) {
259
+ const providerProps = { createEditor };
260
+ return _jsx(EditProvider, { ...providerProps, children: rendered });
95
261
  }
96
262
  return rendered;
97
263
  }
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]);
264
+ /**
265
+ * `@pierre/diffs/react` `<MultiFileDiff>` / `<PatchDiff>` surface wrapper with
266
+ * automatic zero-dep fallback.
267
+ *
268
+ * Note: While `editable` is true, `PierreDiffSurface` keeps `newFile` stable
269
+ * across echoed `onChange` updates per `@pierre/diffs`'s `onEditChange` contract.
270
+ */
271
+ export function PierreDiffSurface(props) {
272
+ if (!props.diffs) {
273
+ const { diffs: _d, theme: _t, themeMode: _tm, unsafeCSS: _u, createEditor: _c, ...rest } = props;
274
+ return _jsx(DefaultDiffSurface, { ...rest });
275
+ }
276
+ return _jsx(PierreDiffSurfaceMounted, { ...props, diffs: props.diffs });
277
+ }
278
+ function PierreFileTreeMounted({ trees, flatPaths, ...props }) {
106
279
  const { model } = trees.useFileTree({
107
280
  paths: flatPaths,
108
281
  search: props.searchable,
@@ -113,10 +286,19 @@ function PierreFileTreeMounted({ trees, ...props }) {
113
286
  return _jsx(TreeComponent, { model: model, className: props.className });
114
287
  }
115
288
  export function PierreFileTree({ trees, ...props }) {
289
+ const flatPaths = useMemo(() => {
290
+ if (props.paths)
291
+ return props.paths;
292
+ if (props.entries)
293
+ return props.entries.map((entry) => entry.path);
294
+ return [];
295
+ }, [props.paths, props.entries]);
116
296
  if (!trees?.FileTree || !trees?.useFileTree) {
117
297
  return _jsx(DefaultFileTree, { ...props });
118
298
  }
119
- return _jsx(PierreFileTreeMounted, { trees: trees, ...props });
299
+ /* `@pierre/trees/react`'s `useFileTree` initializes `new FileTree(options)` once on mount inside `useState`,
300
+ so keying on the joined path list ensures async file lists loaded after mount populate the tree cleanly. */
301
+ return _jsx(PierreFileTreeMounted, { trees: trees, flatPaths: flatPaths, ...props }, flatPaths.join('\0'));
120
302
  }
121
303
  /* ============================================================================
122
304
  * 3. Surface Bundle Factory for `<AgentUiProvider surfaces={...}>`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/agent-ui",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Opt-in React workbench, orchestrator, and AI IDE primitives for Mistri Apps, with an optional @pierre/diffs & @pierre/trees adapter.",
5
5
  "keywords": [
6
6
  "mistri",
@@ -40,7 +40,7 @@
40
40
  }
41
41
  },
42
42
  "peerDependencies": {
43
- "@mistriwork/mistri": "1.4.0",
43
+ "@mistriwork/mistri": "1.4.2",
44
44
  "@pierre/diffs": ">=1.0.0",
45
45
  "@pierre/trees": ">=1.0.0",
46
46
  "react": ">=19"