@mistriwork/agent-ui 0.0.1 → 1.4.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Baljinder Randhawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # `@mistriwork/agent-ui`
2
+
3
+ Opt-in React workbench, orchestrator, and AI IDE primitives for Mistri Apps, built on `@mistriwork/mistri/ui` controls and design tokens.
4
+
5
+ ## Primitives
6
+
7
+ - **Workbench shell:** `<WorkbenchLayout>`, `<TabStrip>`, `<StatusBar>`, `<CommandPalette>`
8
+ - **Orchestrator:** `<SessionTree>`, `<RaceCompare>`, `<ApprovalQueue>`, `<PlanView>`
9
+ - **Agent interaction & tooling:** `<AgentThread>`, `<AgentComposer>` (with attachment chips & slash commands), `<ToolCallInspector>`, `<TerminalOutput>` (safe ANSI SGR parser), `<ModeSwitcher>`, `<ModelPicker>`
10
+ - **Stream bridges:** `streamStateToThreadMessage`, `mergeStreamingTurn`, `streamStateToToolCalls`, `streamStateToApprovals`, `streamStateToDiffFiles`
11
+ - **Pluggable surfaces (zero-dep fallbacks built in):** `<AgentUiProvider>`, `<CodeSurface>`, `<DiffSurface>`, `<DiffView>`, `parseUnifiedDiff`, `<FileTree>`, `buildFileTreeNodes`
12
+ - **Optional Pierre adapter (`@mistriwork/agent-ui/pierre`):** `createPierreSurfaces`, `<PierreCodeSurface>`, `<PierreDiffSurface>`, `<PierreFileTree>`
13
+
14
+ ## Quick Start (Zero Extra Dependencies)
15
+
16
+ ```tsx
17
+ import { useState } from 'react';
18
+ import {
19
+ AgentComposer,
20
+ AgentThread,
21
+ DiffSurface,
22
+ FileTree,
23
+ StatusBar,
24
+ WorkbenchLayout,
25
+ mergeStreamingTurn,
26
+ } from '@mistriwork/agent-ui';
27
+ import { useAgentStream } from '@mistriwork/mistri/page';
28
+
29
+ export function CodingWorkbench({ sessionId }: { sessionId: string }) {
30
+ const [prompt, setPrompt] = useState('');
31
+ const [selectedFile, setSelectedFile] = useState('src/index.ts');
32
+ const stream = useAgentStream(sessionId);
33
+ const messages = mergeStreamingTurn([], stream, { model: 'claude-sonnet' });
34
+
35
+ return (
36
+ <WorkbenchLayout
37
+ sidebar={<FileTree paths={['src/index.ts', 'src/parser.ts']} selectedPath={selectedFile} onSelect={setSelectedFile} searchable />}
38
+ main={<DiffSurface patch={stream.diffs[0]?.patch} />}
39
+ inspector={
40
+ <>
41
+ <AgentThread messages={messages} />
42
+ <AgentComposer value={prompt} onValueChange={setPrompt} onSubmit={() => {}} />
43
+ </>
44
+ }
45
+ statusBar={<StatusBar items={[{ id: 'status', label: 'Agent', value: stream.status, tone: 'info' }]} />}
46
+ />
47
+ );
48
+ }
49
+ ```
50
+
51
+ ## Upgrading Code, Diff & File Tree Surfaces with Pierre
52
+
53
+ Install `@pierre/diffs` (and optionally `@pierre/trees`) in your app, then wrap your workbench with `<AgentUiProvider>`:
54
+
55
+ ```tsx
56
+ import * as pierreDiffs from '@pierre/diffs/react';
57
+ import * as pierreTrees from '@pierre/trees/react';
58
+ import { AgentUiProvider, CodeSurface, DiffSurface, FileTree } from '@mistriwork/agent-ui';
59
+ import { createPierreSurfaces } from '@mistriwork/agent-ui/pierre';
60
+ import { useLook } from '@mistriwork/mistri/ui';
61
+
62
+ export function PierreWorkbench({ children }: { children: React.ReactNode }) {
63
+ const { mode } = useLook();
64
+ const surfaces = createPierreSurfaces({
65
+ diffs: pierreDiffs,
66
+ trees: pierreTrees,
67
+ themeMode: mode,
68
+ diffStyle: 'split',
69
+ });
70
+ return <AgentUiProvider surfaces={surfaces}>{children}</AgentUiProvider>;
71
+ }
72
+ ```
73
+
74
+ Every `<CodeSurface>`, `<DiffSurface>`, and `<FileTree>` inside the provider upgrades automatically to Pierre's Shiki viewer, virtualized split/unified diff, lazy `@pierre/diffs/edit` editor (`editable`), "Add to chat" selection action (`onAddToChat`), and `@pierre/trees` explorer.
@@ -0,0 +1,264 @@
1
+ /* Token-only stylesheet for `@mistriwork/agent-ui` (`<AgentThread>`, `<AgentComposer>`, `<DiffView>`).
2
+ Uses Mistri design tokens (`--space-*`, `--text-*`, `--radius-*`, `--status-*`) so every look dresses it. */
3
+ @layer components {
4
+ .kit-agent-thread {
5
+ display: flex;
6
+ flex-direction: column;
7
+ gap: var(--space-3);
8
+ min-width: 0;
9
+ }
10
+ .kit-agent-msg {
11
+ display: flex;
12
+ flex-direction: column;
13
+ gap: var(--space-2);
14
+ padding: var(--space-3h) var(--space-4);
15
+ border: 1px solid var(--line);
16
+ border-radius: var(--radius-lg, var(--radius));
17
+ background: var(--surface);
18
+ color: var(--ink);
19
+ min-width: 0;
20
+ }
21
+ .kit-agent-msg[data-role='user'] {
22
+ background: var(--raised);
23
+ }
24
+ .kit-agent-msg[data-role='steer'] {
25
+ border-color: color-mix(in srgb, var(--status-info) 45%, var(--line));
26
+ background: color-mix(in srgb, var(--status-info) 6%, var(--surface));
27
+ }
28
+ .kit-agent-msg-head {
29
+ display: flex;
30
+ flex-wrap: wrap;
31
+ align-items: center;
32
+ gap: var(--space-2);
33
+ font-size: var(--text-xs);
34
+ color: var(--ink-muted);
35
+ }
36
+ .kit-agent-msg-role {
37
+ font-weight: 600;
38
+ color: var(--ink);
39
+ }
40
+ .kit-agent-msg-meta {
41
+ margin-inline-start: auto;
42
+ font-family: var(--mono);
43
+ font-size: var(--text-xs);
44
+ color: var(--ink-muted);
45
+ }
46
+ .kit-agent-msg-body {
47
+ display: flex;
48
+ flex-direction: column;
49
+ gap: var(--space-2);
50
+ font-size: var(--text-sm);
51
+ line-height: 1.5;
52
+ min-width: 0;
53
+ }
54
+ .kit-agent-msg-para {
55
+ margin: 0;
56
+ white-space: pre-wrap;
57
+ overflow-wrap: anywhere;
58
+ }
59
+ .kit-agent-code {
60
+ margin: 0;
61
+ padding: var(--space-3);
62
+ border: 1px solid var(--line);
63
+ border-radius: var(--radius);
64
+ background: var(--raised);
65
+ font-family: var(--mono);
66
+ font-size: var(--text-xs);
67
+ line-height: 1.45;
68
+ overflow-x: auto;
69
+ }
70
+ .kit-agent-reasoning {
71
+ border: 1px solid var(--line);
72
+ border-radius: var(--radius);
73
+ background: var(--raised);
74
+ padding: var(--space-2) var(--space-3);
75
+ font-size: var(--text-xs);
76
+ color: var(--ink-muted);
77
+ }
78
+ .kit-agent-reasoning > summary {
79
+ cursor: pointer;
80
+ font-weight: 500;
81
+ color: var(--ink-muted);
82
+ }
83
+ .kit-agent-reasoning-body {
84
+ margin: var(--space-2) 0 0;
85
+ white-space: pre-wrap;
86
+ font-family: var(--mono);
87
+ font-size: var(--text-xs);
88
+ }
89
+ .kit-agent-tools {
90
+ display: flex;
91
+ flex-wrap: wrap;
92
+ gap: var(--space-2);
93
+ }
94
+ .kit-agent-tool {
95
+ display: inline-flex;
96
+ flex-direction: column;
97
+ gap: var(--space-1);
98
+ padding: var(--space-1h) var(--space-2h);
99
+ border: 1px solid var(--line);
100
+ border-radius: var(--radius);
101
+ background: var(--raised);
102
+ font-family: var(--mono);
103
+ font-size: var(--text-xs);
104
+ max-width: 100%;
105
+ }
106
+ .kit-agent-tool-head {
107
+ display: inline-flex;
108
+ align-items: center;
109
+ gap: var(--space-2);
110
+ }
111
+ .kit-agent-tool-out {
112
+ margin: 0;
113
+ padding-top: var(--space-1);
114
+ border-top: 1px solid var(--line);
115
+ white-space: pre-wrap;
116
+ overflow-wrap: anywhere;
117
+ color: var(--ink-muted);
118
+ max-height: 12em;
119
+ overflow-y: auto;
120
+ }
121
+ .kit-agent-approval {
122
+ display: flex;
123
+ flex-direction: column;
124
+ gap: var(--space-2);
125
+ padding: var(--space-3);
126
+ border: 1px solid color-mix(in srgb, var(--status-warning) 50%, var(--line));
127
+ border-radius: var(--radius);
128
+ background: color-mix(in srgb, var(--status-warning) 8%, var(--surface));
129
+ }
130
+ .kit-agent-approval-head {
131
+ display: flex;
132
+ flex-wrap: wrap;
133
+ align-items: center;
134
+ gap: var(--space-2);
135
+ font-size: var(--text-xs);
136
+ }
137
+ .kit-agent-approval-summary {
138
+ margin: 0;
139
+ font-size: var(--text-sm);
140
+ color: var(--ink);
141
+ }
142
+ .kit-agent-approval-actions {
143
+ display: flex;
144
+ flex-wrap: wrap;
145
+ gap: var(--space-2);
146
+ }
147
+
148
+ .kit-agent-composer {
149
+ display: flex;
150
+ flex-direction: column;
151
+ gap: var(--space-2);
152
+ padding: var(--space-3);
153
+ border: 1px solid var(--line);
154
+ border-radius: var(--radius-lg, var(--radius));
155
+ background: var(--surface);
156
+ }
157
+ .kit-agent-composer-foot {
158
+ display: flex;
159
+ flex-wrap: wrap;
160
+ align-items: center;
161
+ justify-content: space-between;
162
+ gap: var(--space-2);
163
+ }
164
+ .kit-agent-composer-slots {
165
+ display: flex;
166
+ flex-wrap: wrap;
167
+ align-items: center;
168
+ gap: var(--space-2);
169
+ min-width: 0;
170
+ }
171
+ .kit-agent-composer-actions {
172
+ display: flex;
173
+ align-items: center;
174
+ gap: var(--space-2);
175
+ margin-inline-start: auto;
176
+ }
177
+
178
+ .kit-diff-view {
179
+ display: flex;
180
+ flex-direction: column;
181
+ gap: var(--space-3);
182
+ min-width: 0;
183
+ }
184
+ .kit-diff-files {
185
+ display: flex;
186
+ flex-wrap: wrap;
187
+ gap: var(--space-2);
188
+ }
189
+ .kit-diff-file {
190
+ border: 1px solid var(--line);
191
+ border-radius: var(--radius-lg, var(--radius));
192
+ background: var(--surface);
193
+ overflow: hidden;
194
+ }
195
+ .kit-diff-file-head {
196
+ display: flex;
197
+ flex-wrap: wrap;
198
+ align-items: center;
199
+ gap: var(--space-2);
200
+ padding: var(--space-2) var(--space-3);
201
+ border-bottom: 1px solid var(--line);
202
+ background: var(--raised);
203
+ font-family: var(--mono);
204
+ font-size: var(--text-xs);
205
+ }
206
+ .kit-diff-file-path {
207
+ font-weight: 600;
208
+ color: var(--ink);
209
+ overflow-wrap: anywhere;
210
+ }
211
+ .kit-diff-file-stats {
212
+ display: inline-flex;
213
+ align-items: center;
214
+ gap: var(--space-2);
215
+ margin-inline-start: auto;
216
+ }
217
+ .kit-diff-stat-add {
218
+ color: color-mix(in srgb, var(--status-good) 85%, var(--ink));
219
+ }
220
+ .kit-diff-stat-del {
221
+ color: color-mix(in srgb, var(--status-critical) 85%, var(--ink));
222
+ }
223
+ .kit-diff-table {
224
+ width: 100%;
225
+ border-collapse: collapse;
226
+ font-family: var(--mono);
227
+ font-size: var(--text-xs);
228
+ line-height: 1.45;
229
+ }
230
+ .kit-diff-line[data-kind='add'] {
231
+ background: color-mix(in srgb, var(--status-good) 12%, var(--surface));
232
+ }
233
+ .kit-diff-line[data-kind='del'] {
234
+ background: color-mix(in srgb, var(--status-critical) 12%, var(--surface));
235
+ }
236
+ .kit-diff-line[data-kind='hunk'] {
237
+ background: color-mix(in srgb, var(--status-info) 10%, var(--raised));
238
+ color: var(--ink-muted);
239
+ }
240
+ .kit-diff-ln {
241
+ width: 1%;
242
+ white-space: nowrap;
243
+ padding: 0 var(--space-2);
244
+ text-align: right;
245
+ color: var(--ink-muted);
246
+ user-select: none;
247
+ border-inline-end: 1px solid var(--line);
248
+ }
249
+ .kit-diff-code {
250
+ padding: 0 var(--space-3);
251
+ white-space: pre-wrap;
252
+ overflow-wrap: anywhere;
253
+ }
254
+ .kit-diff-comment-cell {
255
+ width: 1%;
256
+ white-space: nowrap;
257
+ padding: 0 var(--space-1);
258
+ }
259
+ @media (hover: hover) {
260
+ .kit-diff-line:hover {
261
+ background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface));
262
+ }
263
+ }
264
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * `@mistriwork/agent-ui` workbench components built on `@mistriwork/mistri/ui`
3
+ * primitives and Mistri design tokens:
4
+ * - `<AgentThread>`: chronological conversation with fenced code blocks,
5
+ * collapsible reasoning traces, tool-call pills, and inline approval cards.
6
+ * - `<AgentComposer>`: docked composer with hidden-label `TextArea`,
7
+ * model/mode slot bar, Cmd/Ctrl+Enter submit, and optional Stop action.
8
+ * - `<DiffView>`: unified diff parser + line-numbered renderer with file
9
+ * summary pills (`M`/`A`/`D`/`R` + `+add`/`-del`) and `onLineComment`.
10
+ */
11
+ import { type ReactNode } from 'react';
12
+ import './agentIde.css';
13
+ import './workbench.css';
14
+ export interface AgentThreadToolCall {
15
+ readonly id: string;
16
+ readonly name: string;
17
+ readonly label?: string;
18
+ readonly status: 'running' | 'completed' | 'failed';
19
+ readonly input?: Readonly<Record<string, unknown>>;
20
+ readonly output?: string;
21
+ }
22
+ export interface AgentThreadApproval {
23
+ readonly id: string;
24
+ readonly tool: string;
25
+ readonly risk?: 'low' | 'medium' | 'high';
26
+ readonly summary: string;
27
+ readonly input?: Readonly<Record<string, unknown>>;
28
+ }
29
+ export interface AgentThreadMessage {
30
+ readonly id: string;
31
+ readonly role: 'user' | 'assistant' | 'system' | 'steer';
32
+ readonly content: string;
33
+ readonly reasoning?: string;
34
+ readonly toolCalls?: readonly AgentThreadToolCall[];
35
+ readonly approvals?: readonly AgentThreadApproval[];
36
+ readonly model?: string;
37
+ readonly timestamp?: string;
38
+ readonly streaming?: boolean;
39
+ }
40
+ export interface AgentThreadLabels {
41
+ readonly user?: string;
42
+ readonly assistant?: string;
43
+ readonly steer?: string;
44
+ readonly system?: string;
45
+ readonly reasoning?: string;
46
+ readonly toolCalls?: string;
47
+ readonly approvalRequired?: string;
48
+ readonly approve?: string;
49
+ readonly deny?: string;
50
+ readonly streaming?: string;
51
+ }
52
+ export interface AgentThreadCodeBlock {
53
+ readonly messageId: string;
54
+ readonly index: number;
55
+ readonly lang: string;
56
+ readonly code: string;
57
+ }
58
+ export interface AgentThreadProps {
59
+ readonly messages: readonly AgentThreadMessage[];
60
+ readonly onApprove?: (callId: string) => void;
61
+ readonly onDeny?: (callId: string) => void;
62
+ /** Optional custom renderer for fenced code blocks (e.g. `<CodeSurface>` / Pierre). */
63
+ readonly renderCodeBlock?: (block: AgentThreadCodeBlock) => ReactNode;
64
+ readonly labels?: AgentThreadLabels;
65
+ readonly empty?: ReactNode;
66
+ readonly className?: string;
67
+ }
68
+ export declare function AgentThread({ messages, onApprove, onDeny, renderCodeBlock, labels, empty, className }: AgentThreadProps): import("react").JSX.Element | null;
69
+ export interface ComposerAttachment {
70
+ readonly id: string;
71
+ readonly label: string;
72
+ readonly path?: string;
73
+ readonly range?: string;
74
+ readonly text?: string;
75
+ }
76
+ export interface ComposerSlashCommand {
77
+ readonly name: string;
78
+ readonly description?: string;
79
+ /** Text inserted when selected (defaults to `/${name} `). */
80
+ readonly insertText?: string;
81
+ }
82
+ export interface AgentComposerProps {
83
+ readonly value: string;
84
+ readonly onValueChange: (value: string) => void;
85
+ readonly onSubmit: (value: string) => void | Promise<void>;
86
+ readonly label?: string;
87
+ readonly placeholder?: string;
88
+ readonly submitLabel?: string;
89
+ readonly stopLabel?: string;
90
+ readonly busy?: boolean;
91
+ readonly disabled?: boolean;
92
+ readonly rows?: number;
93
+ readonly onStop?: () => void;
94
+ readonly slots?: ReactNode;
95
+ /** Optional context chips attached to the prompt (e.g. code snippets from Pierre "Add to chat"). */
96
+ readonly attachments?: readonly ComposerAttachment[];
97
+ readonly onRemoveAttachment?: (id: string) => void;
98
+ /** Optional slash-command suggestions shown when the prompt starts with `/`. */
99
+ readonly slashCommands?: readonly ComposerSlashCommand[];
100
+ readonly onSelectSlashCommand?: (command: ComposerSlashCommand) => void;
101
+ readonly className?: string;
102
+ }
103
+ export declare function AgentComposer({ value, onValueChange, onSubmit, label, placeholder, submitLabel, stopLabel, busy, disabled, rows, onStop, slots, attachments, onRemoveAttachment, slashCommands, onSelectSlashCommand, className, }: AgentComposerProps): import("react").JSX.Element;
104
+ export interface DiffLine {
105
+ readonly kind: 'context' | 'add' | 'del' | 'hunk';
106
+ readonly oldLine?: number;
107
+ readonly newLine?: number;
108
+ readonly content: string;
109
+ }
110
+ export interface DiffFile {
111
+ readonly path: string;
112
+ readonly status?: 'M' | 'A' | 'D' | 'R';
113
+ readonly additions?: number;
114
+ readonly deletions?: number;
115
+ readonly lines?: readonly DiffLine[];
116
+ readonly patch?: string;
117
+ }
118
+ export interface DiffViewProps {
119
+ /** Raw unified diff text (e.g. from `git diff` or `worktree.diff()`). */
120
+ readonly diff?: string;
121
+ /** Structured file list (alternative to raw `diff` string). */
122
+ readonly files?: readonly DiffFile[];
123
+ /** Optional selected file path to filter the displayed diff. */
124
+ readonly selectedFile?: string;
125
+ /** Called when a user selects a file pill in the summary bar. */
126
+ readonly onSelectFile?: (path: string) => void;
127
+ /** Called when a user clicks the comment action on a diff line. */
128
+ readonly onLineComment?: (file: string, line: number, content: string) => void;
129
+ readonly empty?: ReactNode;
130
+ readonly className?: string;
131
+ }
132
+ /** Parse raw unified `git diff` output into structured `DiffFile[]` entries. */
133
+ export declare function parseUnifiedDiff(diff: string): DiffFile[];
134
+ export declare function DiffView({ diff, files, selectedFile, onSelectFile, onLineComment, empty, className }: DiffViewProps): import("react").JSX.Element;