@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 +21 -0
- package/README.md +74 -0
- package/dist/agentIde.css +264 -0
- package/dist/agentIde.d.ts +134 -0
- package/dist/agentIde.js +227 -0
- package/dist/fileTree.d.ts +42 -0
- package/dist/fileTree.js +144 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +11 -0
- package/dist/orchestrator.d.ts +87 -0
- package/dist/orchestrator.js +133 -0
- package/dist/pierre.d.ts +6 -0
- package/dist/pierre.js +5 -0
- package/dist/pierreAdapter.d.ts +140 -0
- package/dist/pierreAdapter.js +137 -0
- package/dist/shell.d.ts +101 -0
- package/dist/shell.js +191 -0
- package/dist/streamBridge.d.ts +68 -0
- package/dist/streamBridge.js +93 -0
- package/dist/surfaces.d.ts +93 -0
- package/dist/surfaces.js +127 -0
- package/dist/tools.d.ts +71 -0
- package/dist/tools.js +172 -0
- package/dist/workbench.css +794 -0
- package/package.json +53 -2
package/dist/agentIde.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* `@mistriwork/agent-ui` workbench components built on `@mistriwork/mistri/ui`
|
|
4
|
+
* primitives and Mistri design tokens:
|
|
5
|
+
* - `<AgentThread>`: chronological conversation with fenced code blocks,
|
|
6
|
+
* collapsible reasoning traces, tool-call pills, and inline approval cards.
|
|
7
|
+
* - `<AgentComposer>`: docked composer with hidden-label `TextArea`,
|
|
8
|
+
* model/mode slot bar, Cmd/Ctrl+Enter submit, and optional Stop action.
|
|
9
|
+
* - `<DiffView>`: unified diff parser + line-numbered renderer with file
|
|
10
|
+
* summary pills (`M`/`A`/`D`/`R` + `+add`/`-del`) and `onLineComment`.
|
|
11
|
+
*/
|
|
12
|
+
import { useMemo, useState } from 'react';
|
|
13
|
+
import { Badge, Button, Chip, TextArea } from '@mistriwork/mistri/ui';
|
|
14
|
+
import './agentIde.css';
|
|
15
|
+
import './workbench.css';
|
|
16
|
+
function parseBodySegments(content) {
|
|
17
|
+
const segments = [];
|
|
18
|
+
const fence = /```([A-Za-z0-9_+-]*)\n([\s\S]*?)```/g;
|
|
19
|
+
let last = 0;
|
|
20
|
+
for (const match of content.matchAll(fence)) {
|
|
21
|
+
const idx = match.index ?? 0;
|
|
22
|
+
if (idx > last) {
|
|
23
|
+
const text = content.slice(last, idx).trim();
|
|
24
|
+
if (text)
|
|
25
|
+
segments.push({ kind: 'text', text });
|
|
26
|
+
}
|
|
27
|
+
segments.push({ kind: 'code', lang: match[1] ?? '', code: (match[2] ?? '').replace(/\n$/, '') });
|
|
28
|
+
last = idx + match[0].length;
|
|
29
|
+
}
|
|
30
|
+
const tail = content.slice(last).trim();
|
|
31
|
+
if (tail)
|
|
32
|
+
segments.push({ kind: 'text', text: tail });
|
|
33
|
+
return segments;
|
|
34
|
+
}
|
|
35
|
+
function roleLabel(role, labels) {
|
|
36
|
+
if (role === 'user')
|
|
37
|
+
return labels?.user ?? 'You';
|
|
38
|
+
if (role === 'steer')
|
|
39
|
+
return labels?.steer ?? 'Steer';
|
|
40
|
+
if (role === 'system')
|
|
41
|
+
return labels?.system ?? 'System';
|
|
42
|
+
return labels?.assistant ?? 'Agent';
|
|
43
|
+
}
|
|
44
|
+
function toolTone(status) {
|
|
45
|
+
if (status === 'completed')
|
|
46
|
+
return 'good';
|
|
47
|
+
if (status === 'failed')
|
|
48
|
+
return 'critical';
|
|
49
|
+
return 'info';
|
|
50
|
+
}
|
|
51
|
+
function riskTone(risk) {
|
|
52
|
+
if (risk === 'high')
|
|
53
|
+
return 'critical';
|
|
54
|
+
if (risk === 'medium')
|
|
55
|
+
return 'warning';
|
|
56
|
+
return 'neutral';
|
|
57
|
+
}
|
|
58
|
+
export function AgentThread({ messages, onApprove, onDeny, renderCodeBlock, labels, empty, className }) {
|
|
59
|
+
if (messages.length === 0) {
|
|
60
|
+
return empty ? _jsx("div", { className: className, children: empty }) : null;
|
|
61
|
+
}
|
|
62
|
+
return (_jsx("div", { className: className ? `kit-agent-thread ${className}` : 'kit-agent-thread', children: messages.map((msg) => {
|
|
63
|
+
const segments = parseBodySegments(msg.content);
|
|
64
|
+
return (_jsxs("article", { className: "kit-agent-msg", "data-role": msg.role, children: [_jsxs("header", { className: "kit-agent-msg-head", children: [_jsx("span", { className: "kit-agent-msg-role", children: roleLabel(msg.role, labels) }), msg.model ? _jsx(Badge, { tone: "neutral", children: msg.model }) : null, msg.streaming ? _jsx(Badge, { tone: "info", children: labels?.streaming ?? 'Streaming…' }) : null, msg.timestamp ? _jsx("span", { className: "kit-agent-msg-meta", children: msg.timestamp }) : null] }), msg.reasoning ? (_jsxs("details", { className: "kit-agent-reasoning", children: [_jsx("summary", { children: labels?.reasoning ?? 'Reasoning' }), _jsx("pre", { className: "kit-agent-reasoning-body", children: msg.reasoning })] })) : null, segments.length > 0 ? (_jsx("div", { className: "kit-agent-msg-body", children: segments.map((seg, i) => seg.kind === 'code' ? (renderCodeBlock ? (_jsx("div", { children: renderCodeBlock({ messageId: msg.id, index: i, lang: seg.lang, code: seg.code }) }, i)) : (_jsx("pre", { className: "kit-agent-code", "data-lang": seg.lang || undefined, children: _jsx("code", { children: seg.code }) }, i))) : (_jsx("p", { className: "kit-agent-msg-para", children: seg.text }, i))) })) : null, msg.toolCalls && msg.toolCalls.length > 0 ? (_jsx("div", { className: "kit-agent-tools", "aria-label": labels?.toolCalls ?? 'Tool calls', children: msg.toolCalls.map((tool) => (_jsxs("div", { className: "kit-agent-tool", "data-status": tool.status, children: [_jsxs("div", { className: "kit-agent-tool-head", children: [_jsx("span", { children: tool.label ?? tool.name }), _jsx(Badge, { tone: toolTone(tool.status), children: tool.status })] }), tool.input ? (_jsxs("details", { className: "kit-agent-reasoning", children: [_jsx("summary", { children: "Input" }), _jsx("pre", { className: "kit-agent-reasoning-body", children: JSON.stringify(tool.input, null, 2) })] })) : null, tool.output ? _jsx("pre", { className: "kit-agent-tool-out", children: tool.output }) : null] }, tool.id))) })) : null, msg.approvals && msg.approvals.length > 0
|
|
65
|
+
? msg.approvals.map((approval) => (_jsxs("div", { className: "kit-agent-approval", role: "region", "aria-label": labels?.approvalRequired ?? 'Approval required', children: [_jsxs("div", { className: "kit-agent-approval-head", children: [_jsx(Badge, { tone: riskTone(approval.risk), children: approval.risk ?? 'medium' }), _jsx("code", { children: approval.tool })] }), _jsx("p", { className: "kit-agent-approval-summary", children: approval.summary }), approval.input ? (_jsx("pre", { className: "kit-agent-code", children: _jsx("code", { children: JSON.stringify(approval.input, null, 2) }) })) : null, onApprove || onDeny ? (_jsxs("div", { className: "kit-agent-approval-actions", children: [onApprove ? (_jsx(Button, { size: "sm", variant: "primary", onClick: () => onApprove(approval.id), children: labels?.approve ?? 'Approve' })) : null, onDeny ? (_jsx(Button, { size: "sm", variant: "secondary", onClick: () => onDeny(approval.id), children: labels?.deny ?? 'Deny' })) : null] })) : null] }, approval.id)))
|
|
66
|
+
: null] }, msg.id));
|
|
67
|
+
}) }));
|
|
68
|
+
}
|
|
69
|
+
export function AgentComposer({ value, onValueChange, onSubmit, label = 'Message', placeholder = 'Send a prompt or instruction…', submitLabel = 'Send', stopLabel = 'Stop', busy = false, disabled = false, rows = 2, onStop, slots, attachments, onRemoveAttachment, slashCommands, onSelectSlashCommand, className, }) {
|
|
70
|
+
const [slashIndex, setSlashIndex] = useState(0);
|
|
71
|
+
const canSend = !busy && !disabled && (value.trim().length > 0 || Boolean(attachments && attachments.length > 0));
|
|
72
|
+
const matchingSlashCommands = useMemo(() => {
|
|
73
|
+
if (!slashCommands || slashCommands.length === 0)
|
|
74
|
+
return [];
|
|
75
|
+
const trimmed = value.trimStart();
|
|
76
|
+
if (!trimmed.startsWith('/') || trimmed.includes(' ') || trimmed.includes('\n'))
|
|
77
|
+
return [];
|
|
78
|
+
const prefix = trimmed.slice(1).toLowerCase();
|
|
79
|
+
return slashCommands.filter((cmd) => cmd.name.toLowerCase().startsWith(prefix));
|
|
80
|
+
}, [slashCommands, value]);
|
|
81
|
+
const activeSlashIdx = matchingSlashCommands.length === 0 ? 0 : Math.min(slashIndex, matchingSlashCommands.length - 1);
|
|
82
|
+
const applySlashCommand = (command) => {
|
|
83
|
+
onSelectSlashCommand?.(command);
|
|
84
|
+
onValueChange(command.insertText ?? `/${command.name} `);
|
|
85
|
+
setSlashIndex(0);
|
|
86
|
+
};
|
|
87
|
+
const triggerSubmit = () => {
|
|
88
|
+
if (!canSend)
|
|
89
|
+
return;
|
|
90
|
+
void onSubmit(value);
|
|
91
|
+
};
|
|
92
|
+
const handleKeyDown = (event) => {
|
|
93
|
+
if (matchingSlashCommands.length > 0) {
|
|
94
|
+
if (event.key === 'ArrowDown') {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
setSlashIndex((activeSlashIdx + 1) % matchingSlashCommands.length);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (event.key === 'ArrowUp') {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
setSlashIndex((activeSlashIdx - 1 + matchingSlashCommands.length) % matchingSlashCommands.length);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (event.key === 'Tab' && matchingSlashCommands[activeSlashIdx]) {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
applySlashCommand(matchingSlashCommands[activeSlashIdx]);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
triggerSubmit();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return (_jsxs("form", { className: className ? `kit-agent-composer ${className}` : 'kit-agent-composer', onSubmit: (e) => {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
triggerSubmit();
|
|
118
|
+
}, children: [attachments && attachments.length > 0 ? (_jsx("div", { className: "kit-agent-composer-attachments", "aria-label": "Attached context", children: attachments.map((att) => (_jsx(Chip, { size: "sm", tone: "neutral", onRemove: onRemoveAttachment ? () => onRemoveAttachment(att.id) : undefined, removeLabel: `Remove ${att.label}`, children: att.range ? `${att.label}:${att.range}` : att.label }, att.id))) })) : null, matchingSlashCommands.length > 0 ? (_jsx("div", { className: "kit-agent-composer-slash", role: "listbox", "aria-label": "Slash commands", children: matchingSlashCommands.map((cmd, idx) => (_jsxs("button", { type: "button", role: "option", "aria-selected": idx === activeSlashIdx, "data-active": idx === activeSlashIdx ? 'true' : undefined, className: "kit-agent-composer-slash-item", onClick: () => applySlashCommand(cmd), children: [_jsx("code", { children: `/${cmd.name}` }), cmd.description ? _jsx("span", { className: "aui-palette-item-desc", children: cmd.description }) : null] }, cmd.name))) })) : null, _jsx("div", { onKeyDown: handleKeyDown, children: _jsx(TextArea, { label: label, labelHidden: true, reserve: false, rows: rows, value: value, onValueChange: (next) => {
|
|
119
|
+
onValueChange(next);
|
|
120
|
+
setSlashIndex(0);
|
|
121
|
+
}, placeholder: placeholder, disabled: disabled }) }), _jsxs("div", { className: "kit-agent-composer-foot", children: [slots ? _jsx("div", { className: "kit-agent-composer-slots", children: slots }) : null, _jsxs("div", { className: "kit-agent-composer-actions", children: [busy && onStop ? (_jsx(Button, { type: "button", size: "sm", variant: "secondary", onClick: onStop, children: stopLabel })) : null, _jsx(Button, { type: "submit", size: "sm", variant: "primary", loading: busy, disabled: !canSend, children: submitLabel })] })] })] }));
|
|
122
|
+
}
|
|
123
|
+
function parsePatchLines(patch) {
|
|
124
|
+
const out = [];
|
|
125
|
+
let oldLn = 0;
|
|
126
|
+
let newLn = 0;
|
|
127
|
+
let additions = 0;
|
|
128
|
+
let deletions = 0;
|
|
129
|
+
for (const raw of patch.split('\n')) {
|
|
130
|
+
if (raw.startsWith('diff --git ') ||
|
|
131
|
+
raw.startsWith('index ') ||
|
|
132
|
+
raw.startsWith('--- ') ||
|
|
133
|
+
raw.startsWith('+++ ') ||
|
|
134
|
+
raw.startsWith('new file mode') ||
|
|
135
|
+
raw.startsWith('deleted file mode')) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const hunk = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(raw);
|
|
139
|
+
if (hunk) {
|
|
140
|
+
oldLn = Number(hunk[1]);
|
|
141
|
+
newLn = Number(hunk[2]);
|
|
142
|
+
out.push({ kind: 'hunk', content: raw });
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (raw.startsWith('+')) {
|
|
146
|
+
additions += 1;
|
|
147
|
+
out.push({ kind: 'add', newLine: newLn, content: raw.slice(1) });
|
|
148
|
+
newLn += 1;
|
|
149
|
+
}
|
|
150
|
+
else if (raw.startsWith('-')) {
|
|
151
|
+
deletions += 1;
|
|
152
|
+
out.push({ kind: 'del', oldLine: oldLn, content: raw.slice(1) });
|
|
153
|
+
oldLn += 1;
|
|
154
|
+
}
|
|
155
|
+
else if (raw.startsWith(' ') || raw === '') {
|
|
156
|
+
if (out.length === 0 && raw === '')
|
|
157
|
+
continue;
|
|
158
|
+
out.push({ kind: 'context', oldLine: oldLn, newLine: newLn, content: raw.startsWith(' ') ? raw.slice(1) : raw });
|
|
159
|
+
oldLn += 1;
|
|
160
|
+
newLn += 1;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return { lines: out, additions, deletions };
|
|
164
|
+
}
|
|
165
|
+
/** Parse raw unified `git diff` output into structured `DiffFile[]` entries. */
|
|
166
|
+
export function parseUnifiedDiff(diff) {
|
|
167
|
+
const trimmed = diff.trim();
|
|
168
|
+
if (!trimmed)
|
|
169
|
+
return [];
|
|
170
|
+
const chunks = trimmed.split(/(?=^diff --git )/m).filter((part) => part.trim().length > 0);
|
|
171
|
+
const results = [];
|
|
172
|
+
for (const chunk of chunks) {
|
|
173
|
+
const header = /^diff --git a\/(.+?) b\/(.+)$/m.exec(chunk);
|
|
174
|
+
const plus = /^\+\+\+ (?:b\/)?(.+)$/m.exec(chunk);
|
|
175
|
+
const minus = /^--- (?:a\/)?(.+)$/m.exec(chunk);
|
|
176
|
+
const path = (plus && plus[1] !== '/dev/null' ? plus[1] : undefined) ??
|
|
177
|
+
header?.[2] ??
|
|
178
|
+
(minus && minus[1] !== '/dev/null' ? minus[1] : undefined) ??
|
|
179
|
+
'diff';
|
|
180
|
+
const status = chunk.includes('new file mode') || minus?.[1] === '/dev/null'
|
|
181
|
+
? 'A'
|
|
182
|
+
: chunk.includes('deleted file mode') || plus?.[1] === '/dev/null'
|
|
183
|
+
? 'D'
|
|
184
|
+
: header && header[1] !== header[2]
|
|
185
|
+
? 'R'
|
|
186
|
+
: 'M';
|
|
187
|
+
const parsed = parsePatchLines(chunk);
|
|
188
|
+
results.push({ path, status, additions: parsed.additions, deletions: parsed.deletions, lines: parsed.lines });
|
|
189
|
+
}
|
|
190
|
+
return results;
|
|
191
|
+
}
|
|
192
|
+
function statusBadgeTone(status) {
|
|
193
|
+
if (status === 'A')
|
|
194
|
+
return 'good';
|
|
195
|
+
if (status === 'D')
|
|
196
|
+
return 'critical';
|
|
197
|
+
if (status === 'R')
|
|
198
|
+
return 'info';
|
|
199
|
+
return 'warning';
|
|
200
|
+
}
|
|
201
|
+
export function DiffView({ diff, files, selectedFile, onSelectFile, onLineComment, empty, className }) {
|
|
202
|
+
const parsedFiles = useMemo(() => {
|
|
203
|
+
if (files && files.length > 0) {
|
|
204
|
+
return files.map((file) => {
|
|
205
|
+
if (file.lines)
|
|
206
|
+
return file;
|
|
207
|
+
const parsed = file.patch ? parsePatchLines(file.patch) : { lines: [], additions: 0, deletions: 0 };
|
|
208
|
+
return {
|
|
209
|
+
...file,
|
|
210
|
+
lines: parsed.lines,
|
|
211
|
+
additions: file.additions ?? parsed.additions,
|
|
212
|
+
deletions: file.deletions ?? parsed.deletions,
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return diff ? parseUnifiedDiff(diff) : [];
|
|
217
|
+
}, [diff, files]);
|
|
218
|
+
if (parsedFiles.length === 0) {
|
|
219
|
+
return (_jsx("div", { className: className ? `kit-diff-view ${className}` : 'kit-diff-view', children: empty ?? _jsx("p", { className: "note", children: "No file changes." }) }));
|
|
220
|
+
}
|
|
221
|
+
const visible = selectedFile ? parsedFiles.filter((file) => file.path === selectedFile) : parsedFiles;
|
|
222
|
+
return (_jsxs("div", { className: className ? `kit-diff-view ${className}` : 'kit-diff-view', children: [parsedFiles.length > 1 && onSelectFile ? (_jsx("div", { className: "kit-diff-files", role: "group", "aria-label": "Changed files", children: parsedFiles.map((file) => (_jsx(Button, { size: "sm", variant: selectedFile === file.path ? 'primary' : 'secondary', onClick: () => onSelectFile(file.path), children: `${file.status ?? 'M'} ${file.path}` }, file.path))) })) : null, visible.map((file) => (_jsxs("section", { className: "kit-diff-file", children: [_jsxs("header", { className: "kit-diff-file-head", children: [_jsx(Badge, { tone: statusBadgeTone(file.status), children: file.status ?? 'M' }), _jsx("span", { className: "kit-diff-file-path", children: file.path }), _jsxs("span", { className: "kit-diff-file-stats", children: [file.additions !== undefined ? _jsx("span", { className: "kit-diff-stat-add", children: `+${file.additions}` }) : null, file.deletions !== undefined ? _jsx("span", { className: "kit-diff-stat-del", children: `-${file.deletions}` }) : null] })] }), _jsx("table", { className: "kit-diff-table", children: _jsx("tbody", { children: (file.lines ?? []).map((line, idx) => {
|
|
223
|
+
const targetLine = line.newLine ?? line.oldLine;
|
|
224
|
+
const prefix = line.kind === 'add' ? '+' : line.kind === 'del' ? '-' : line.kind === 'hunk' ? '' : ' ';
|
|
225
|
+
return (_jsxs("tr", { className: "kit-diff-line", "data-kind": line.kind, children: [_jsx("td", { className: "kit-diff-ln", children: line.oldLine ?? '' }), _jsx("td", { className: "kit-diff-ln", children: line.newLine ?? '' }), onLineComment ? (_jsx("td", { className: "kit-diff-comment-cell", children: line.kind !== 'hunk' && targetLine !== undefined ? (_jsx(Button, { size: "sm", variant: "ghost", ariaLabel: `Comment on line ${targetLine} of ${file.path}`, onClick: () => onLineComment(file.path, targetLine, line.content), children: "+" })) : null })) : null, _jsx("td", { className: "kit-diff-code", children: `${prefix}${line.content}` })] }, idx));
|
|
226
|
+
}) }) })] }, file.path)))] }));
|
|
227
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path-first file tree builder and zero-dep accessible fallback `<DefaultFileTree>`.
|
|
3
|
+
*/
|
|
4
|
+
import { type ReactNode } from 'react';
|
|
5
|
+
import './workbench.css';
|
|
6
|
+
export type FileGitStatus = 'M' | 'A' | 'D' | 'R' | 'U';
|
|
7
|
+
export interface FileTreeEntry {
|
|
8
|
+
readonly path: string;
|
|
9
|
+
readonly kind?: 'file' | 'directory';
|
|
10
|
+
readonly gitStatus?: FileGitStatus;
|
|
11
|
+
}
|
|
12
|
+
export interface FileTreeNode {
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly kind: 'file' | 'directory';
|
|
16
|
+
readonly gitStatus?: FileGitStatus;
|
|
17
|
+
readonly children: readonly FileTreeNode[];
|
|
18
|
+
}
|
|
19
|
+
export interface FileTreeProps {
|
|
20
|
+
/** Flat canonical paths (e.g. `['src/index.ts', 'src/app.ts']`). */
|
|
21
|
+
readonly paths?: readonly string[];
|
|
22
|
+
/** Structured entries with optional directory/git status metadata. */
|
|
23
|
+
readonly entries?: readonly FileTreeEntry[];
|
|
24
|
+
/** Optional map of path -> git status badge when passing flat `paths`. */
|
|
25
|
+
readonly gitStatus?: Readonly<Record<string, FileGitStatus>>;
|
|
26
|
+
readonly selectedPath?: string;
|
|
27
|
+
readonly defaultExpandedPaths?: readonly string[];
|
|
28
|
+
readonly onSelect: (path: string) => void;
|
|
29
|
+
readonly onToggleDirectory?: (path: string, expanded: boolean) => void;
|
|
30
|
+
readonly searchable?: boolean;
|
|
31
|
+
readonly placeholder?: string;
|
|
32
|
+
readonly empty?: ReactNode;
|
|
33
|
+
readonly ariaLabel?: string;
|
|
34
|
+
readonly className?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Build a sorted, directory-first tree from flat paths or entries. */
|
|
37
|
+
export declare function buildFileTreeNodes(input: {
|
|
38
|
+
readonly paths?: readonly string[];
|
|
39
|
+
readonly entries?: readonly FileTreeEntry[];
|
|
40
|
+
readonly gitStatus?: Readonly<Record<string, FileGitStatus>>;
|
|
41
|
+
}): FileTreeNode[];
|
|
42
|
+
export declare function DefaultFileTree({ paths, entries, gitStatus, selectedPath, defaultExpandedPaths, onSelect, onToggleDirectory, searchable, placeholder, empty, ariaLabel, className, }: FileTreeProps): import("react").JSX.Element;
|
package/dist/fileTree.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Path-first file tree builder and zero-dep accessible fallback `<DefaultFileTree>`.
|
|
4
|
+
*/
|
|
5
|
+
import { useMemo, useState } from 'react';
|
|
6
|
+
import { Badge, EmptyState, TextField } from '@mistriwork/mistri/ui';
|
|
7
|
+
import './workbench.css';
|
|
8
|
+
/** Build a sorted, directory-first tree from flat paths or entries. */
|
|
9
|
+
export function buildFileTreeNodes(input) {
|
|
10
|
+
const roots = new Map();
|
|
11
|
+
const normalized = input.entries
|
|
12
|
+
? [...input.entries]
|
|
13
|
+
: (input.paths ?? []).map((p) => ({
|
|
14
|
+
path: p,
|
|
15
|
+
kind: p.endsWith('/') ? 'directory' : 'file',
|
|
16
|
+
...(input.gitStatus?.[p] ? { gitStatus: input.gitStatus[p] } : {}),
|
|
17
|
+
}));
|
|
18
|
+
for (const entry of normalized) {
|
|
19
|
+
const clean = entry.path.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
20
|
+
if (!clean)
|
|
21
|
+
continue;
|
|
22
|
+
const parts = clean.split('/');
|
|
23
|
+
let level = roots;
|
|
24
|
+
let currentPath = '';
|
|
25
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
26
|
+
const part = parts[i];
|
|
27
|
+
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
|
28
|
+
const isLeaf = i === parts.length - 1;
|
|
29
|
+
const kind = isLeaf ? (entry.kind ?? 'file') : 'directory';
|
|
30
|
+
let existing = level.get(part);
|
|
31
|
+
if (!existing) {
|
|
32
|
+
existing = {
|
|
33
|
+
path: currentPath,
|
|
34
|
+
name: part,
|
|
35
|
+
kind,
|
|
36
|
+
children: new Map(),
|
|
37
|
+
};
|
|
38
|
+
level.set(part, existing);
|
|
39
|
+
}
|
|
40
|
+
else if (!isLeaf) {
|
|
41
|
+
existing.kind = 'directory';
|
|
42
|
+
}
|
|
43
|
+
if (isLeaf) {
|
|
44
|
+
const status = entry.gitStatus ?? input.gitStatus?.[clean];
|
|
45
|
+
if (status)
|
|
46
|
+
existing.gitStatus = status;
|
|
47
|
+
}
|
|
48
|
+
level = existing.children;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const freeze = (map) => [...map.values()]
|
|
52
|
+
.sort((a, b) => {
|
|
53
|
+
if (a.kind !== b.kind)
|
|
54
|
+
return a.kind === 'directory' ? -1 : 1;
|
|
55
|
+
return a.name.localeCompare(b.name);
|
|
56
|
+
})
|
|
57
|
+
.map((node) => ({
|
|
58
|
+
path: node.path,
|
|
59
|
+
name: node.name,
|
|
60
|
+
kind: node.kind,
|
|
61
|
+
...(node.gitStatus ? { gitStatus: node.gitStatus } : {}),
|
|
62
|
+
children: freeze(node.children),
|
|
63
|
+
}));
|
|
64
|
+
return freeze(roots);
|
|
65
|
+
}
|
|
66
|
+
function gitTone(status) {
|
|
67
|
+
if (status === 'A' || status === 'U')
|
|
68
|
+
return 'good';
|
|
69
|
+
if (status === 'D')
|
|
70
|
+
return 'critical';
|
|
71
|
+
if (status === 'R')
|
|
72
|
+
return 'info';
|
|
73
|
+
return 'warning';
|
|
74
|
+
}
|
|
75
|
+
function flattenVisible(nodes, expanded, forceExpand, depth = 0) {
|
|
76
|
+
const rows = [];
|
|
77
|
+
for (const node of nodes) {
|
|
78
|
+
rows.push({ node, depth });
|
|
79
|
+
if (node.kind === 'directory' && (forceExpand || expanded.has(node.path))) {
|
|
80
|
+
rows.push(...flattenVisible(node.children, expanded, forceExpand, depth + 1));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return rows;
|
|
84
|
+
}
|
|
85
|
+
function filterNodes(nodes, query) {
|
|
86
|
+
const q = query.trim().toLowerCase();
|
|
87
|
+
if (!q)
|
|
88
|
+
return [...nodes];
|
|
89
|
+
const out = [];
|
|
90
|
+
for (const node of nodes) {
|
|
91
|
+
const kids = node.kind === 'directory' ? filterNodes(node.children, q) : [];
|
|
92
|
+
if (node.path.toLowerCase().includes(q) || kids.length > 0) {
|
|
93
|
+
out.push({ ...node, children: kids });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
export function DefaultFileTree({ paths, entries, gitStatus, selectedPath, defaultExpandedPaths, onSelect, onToggleDirectory, searchable = false, placeholder = 'Filter files…', empty, ariaLabel = 'Files', className, }) {
|
|
99
|
+
const [query, setQuery] = useState('');
|
|
100
|
+
const [expanded, setExpanded] = useState(() => new Set(defaultExpandedPaths ?? []));
|
|
101
|
+
const tree = useMemo(() => buildFileTreeNodes({ paths, entries, gitStatus }), [paths, entries, gitStatus]);
|
|
102
|
+
const filtered = useMemo(() => filterNodes(tree, query), [tree, query]);
|
|
103
|
+
const rows = useMemo(() => flattenVisible(filtered, expanded, query.trim().length > 0), [filtered, expanded, query]);
|
|
104
|
+
const toggleDir = (path) => {
|
|
105
|
+
setExpanded((prev) => {
|
|
106
|
+
const next = new Set(prev);
|
|
107
|
+
const nowOpen = !next.has(path);
|
|
108
|
+
if (nowOpen)
|
|
109
|
+
next.add(path);
|
|
110
|
+
else
|
|
111
|
+
next.delete(path);
|
|
112
|
+
onToggleDirectory?.(path, nowOpen);
|
|
113
|
+
return next;
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
const handleKeyDown = (index, row, event) => {
|
|
117
|
+
if (event.key === 'ArrowDown' && rows[index + 1]) {
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
const next = rows[index + 1];
|
|
120
|
+
if (next.node.kind === 'file')
|
|
121
|
+
onSelect(next.node.path);
|
|
122
|
+
}
|
|
123
|
+
else if (event.key === 'ArrowUp' && rows[index - 1]) {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
const prev = rows[index - 1];
|
|
126
|
+
if (prev.node.kind === 'file')
|
|
127
|
+
onSelect(prev.node.path);
|
|
128
|
+
}
|
|
129
|
+
else if (event.key === 'ArrowRight' && row.node.kind === 'directory' && !expanded.has(row.node.path)) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
toggleDir(row.node.path);
|
|
132
|
+
}
|
|
133
|
+
else if (event.key === 'ArrowLeft' && row.node.kind === 'directory' && expanded.has(row.node.path)) {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
toggleDir(row.node.path);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return (_jsxs("div", { className: className ? `aui-file-tree ${className}` : 'aui-file-tree', children: [searchable ? (_jsx(TextField, { label: "Filter files", labelHidden: true, reserve: false, value: query, onValueChange: (next) => setQuery(next), placeholder: placeholder })) : null, rows.length === 0 ? ((empty ?? _jsx(EmptyState, { compact: true, title: "No files" }))) : (_jsx("ul", { className: "aui-file-tree-list", role: "tree", "aria-label": ariaLabel, children: rows.map((row, idx) => {
|
|
139
|
+
const isDir = row.node.kind === 'directory';
|
|
140
|
+
const isOpen = query.trim().length > 0 || expanded.has(row.node.path);
|
|
141
|
+
const selected = row.node.path === selectedPath;
|
|
142
|
+
return (_jsx("li", { role: "treeitem", "aria-expanded": isDir ? isOpen : undefined, "aria-selected": selected, children: _jsxs("button", { type: "button", className: "aui-file-tree-row", "aria-selected": selected, style: { paddingInlineStart: `calc(var(--space-2) + ${row.depth} * var(--space-3))` }, onClick: () => (isDir ? toggleDir(row.node.path) : onSelect(row.node.path)), onKeyDown: (e) => handleKeyDown(idx, row, e), children: [_jsx("span", { className: "aui-file-tree-caret", "aria-hidden": "true", children: isDir ? (isOpen ? '▾' : '▸') : '·' }), _jsx("span", { className: "aui-file-tree-name", children: row.node.name }), row.node.gitStatus ? _jsx(Badge, { tone: gitTone(row.node.gitStatus), children: row.node.gitStatus }) : null] }) }, row.node.path));
|
|
143
|
+
}) }))] }));
|
|
144
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mistriwork/agent-ui`: Opt-in React primitives for building coding agents,
|
|
3
|
+
* multi-agent orchestrators, and AI IDEs on Mistri.
|
|
4
|
+
*/
|
|
5
|
+
export { AgentComposer, AgentThread, DiffView, parseUnifiedDiff } from './agentIde.js';
|
|
6
|
+
export type { AgentComposerProps, AgentThreadApproval, AgentThreadCodeBlock, AgentThreadLabels, AgentThreadMessage, AgentThreadProps, AgentThreadToolCall, ComposerAttachment, ComposerSlashCommand, DiffFile, DiffLine, DiffViewProps, } from './agentIde.js';
|
|
7
|
+
export { CommandPalette, StatusBar, TabStrip, WorkbenchLayout } from './shell.js';
|
|
8
|
+
export type { CommandPaletteItem, CommandPaletteProps, StatusBarItem, StatusBarProps, TabStripItem, TabStripProps, WorkbenchLayoutProps, WorkbenchLayoutSizes, } from './shell.js';
|
|
9
|
+
export { ApprovalQueue, PlanView, RaceCompare, SessionTree } from './orchestrator.js';
|
|
10
|
+
export type { AgentSessionNode, AgentSessionStatus, ApprovalQueueProps, PlanStep, PlanStepStatus, PlanViewProps, RaceCandidate, RaceCheck, RaceCompareProps, SessionTreeProps, } from './orchestrator.js';
|
|
11
|
+
export { ModeSwitcher, ModelPicker, TerminalOutput, ToolCallInspector, parseAnsiLine } from './tools.js';
|
|
12
|
+
export type { AgentModeOption, AnsiSegment, ModeSwitcherProps, ModelOption, ModelPickerProps, TerminalOutputProps, ToolCallFilter, ToolCallInspectorProps, } from './tools.js';
|
|
13
|
+
export { mergeStreamingTurn, streamStateToApprovals, streamStateToDiffFiles, streamStateToThreadMessage, streamStateToToolCalls, } from './streamBridge.js';
|
|
14
|
+
export type { AgentStreamApprovalLike, AgentStreamDiffLike, AgentStreamSnapshot, AgentStreamStatusLike, AgentStreamToolCallLike, ApprovalQueueItem, StreamToMessageOptions, ToolCallRecord, } from './streamBridge.js';
|
|
15
|
+
export { DefaultFileTree, buildFileTreeNodes } from './fileTree.js';
|
|
16
|
+
export type { FileGitStatus, FileTreeEntry, FileTreeNode, FileTreeProps } from './fileTree.js';
|
|
17
|
+
export { AgentUiProvider, CodeSurface, DefaultCodeSurface, DefaultDiffSurface, DiffSurface, FileTree, useAgentUiSurfaces, } from './surfaces.js';
|
|
18
|
+
export type { AgentUiProviderProps, AgentUiSurfaces, CodeAnnotation, CodeMarker, CodeSelectionSnippet, CodeSurfaceProps, DiffAnnotation, DiffSurfaceFileInput, DiffSurfaceProps, } from './surfaces.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mistriwork/agent-ui`: Opt-in React primitives for building coding agents,
|
|
3
|
+
* multi-agent orchestrators, and AI IDEs on Mistri.
|
|
4
|
+
*/
|
|
5
|
+
export { AgentComposer, AgentThread, DiffView, parseUnifiedDiff } from './agentIde.js';
|
|
6
|
+
export { CommandPalette, StatusBar, TabStrip, WorkbenchLayout } from './shell.js';
|
|
7
|
+
export { ApprovalQueue, PlanView, RaceCompare, SessionTree } from './orchestrator.js';
|
|
8
|
+
export { ModeSwitcher, ModelPicker, TerminalOutput, ToolCallInspector, parseAnsiLine } from './tools.js';
|
|
9
|
+
export { mergeStreamingTurn, streamStateToApprovals, streamStateToDiffFiles, streamStateToThreadMessage, streamStateToToolCalls, } from './streamBridge.js';
|
|
10
|
+
export { DefaultFileTree, buildFileTreeNodes } from './fileTree.js';
|
|
11
|
+
export { AgentUiProvider, CodeSurface, DefaultCodeSurface, DefaultDiffSurface, DiffSurface, FileTree, useAgentUiSurfaces, } from './surfaces.js';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-agent & orchestrator primitives for `@mistriwork/agent-ui`:
|
|
3
|
+
* - `<SessionTree>`: hierarchical tree of agent runs, sub-agents, and worktrees
|
|
4
|
+
* - `<RaceCompare>`: side-by-side comparison of parallel agent / model runs
|
|
5
|
+
* - `<ApprovalQueue>`: cross-agent permission & checkpoint approval inbox
|
|
6
|
+
* - `<PlanView>`: structured agent execution plan with progress meter
|
|
7
|
+
*/
|
|
8
|
+
import { type ReactNode } from 'react';
|
|
9
|
+
import type { ApprovalQueueItem } from './streamBridge.js';
|
|
10
|
+
import './workbench.css';
|
|
11
|
+
export type AgentSessionStatus = 'idle' | 'running' | 'paused' | 'waiting_approval' | 'completed' | 'failed';
|
|
12
|
+
export interface AgentSessionNode {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly title: string;
|
|
15
|
+
readonly status: AgentSessionStatus;
|
|
16
|
+
readonly model?: string;
|
|
17
|
+
readonly branch?: string;
|
|
18
|
+
readonly durationLabel?: string;
|
|
19
|
+
readonly tokensLabel?: string;
|
|
20
|
+
readonly pendingApprovals?: number;
|
|
21
|
+
readonly children?: readonly AgentSessionNode[];
|
|
22
|
+
}
|
|
23
|
+
export interface SessionTreeProps {
|
|
24
|
+
readonly sessions: readonly AgentSessionNode[];
|
|
25
|
+
readonly selectedId?: string;
|
|
26
|
+
readonly onSelect: (id: string) => void;
|
|
27
|
+
readonly onCancel?: (id: string) => void;
|
|
28
|
+
readonly onFork?: (id: string) => void;
|
|
29
|
+
readonly filterable?: boolean;
|
|
30
|
+
readonly empty?: ReactNode;
|
|
31
|
+
readonly className?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function SessionTree({ sessions, selectedId, onSelect, onCancel, onFork, filterable, empty, className }: SessionTreeProps): import("react").JSX.Element;
|
|
34
|
+
export interface RaceCheck {
|
|
35
|
+
readonly label: string;
|
|
36
|
+
readonly passed: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface RaceCandidate {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly label: string;
|
|
41
|
+
readonly model: string;
|
|
42
|
+
readonly status: AgentSessionStatus;
|
|
43
|
+
readonly summary?: string;
|
|
44
|
+
readonly durationLabel?: string;
|
|
45
|
+
readonly costLabel?: string;
|
|
46
|
+
readonly filesChanged?: number;
|
|
47
|
+
readonly additions?: number;
|
|
48
|
+
readonly deletions?: number;
|
|
49
|
+
readonly checks?: readonly RaceCheck[];
|
|
50
|
+
readonly diff?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface RaceCompareProps {
|
|
53
|
+
readonly candidates: readonly RaceCandidate[];
|
|
54
|
+
readonly winnerId?: string;
|
|
55
|
+
readonly onPickWinner?: (id: string) => void;
|
|
56
|
+
readonly onInspect?: (id: string) => void;
|
|
57
|
+
readonly renderDiff?: (candidate: RaceCandidate) => ReactNode;
|
|
58
|
+
readonly empty?: ReactNode;
|
|
59
|
+
readonly className?: string;
|
|
60
|
+
}
|
|
61
|
+
export declare function RaceCompare({ candidates, winnerId, onPickWinner, onInspect, renderDiff, empty, className }: RaceCompareProps): import("react").JSX.Element;
|
|
62
|
+
export interface ApprovalQueueProps {
|
|
63
|
+
readonly approvals: readonly ApprovalQueueItem[];
|
|
64
|
+
readonly onApprove: (id: string) => void;
|
|
65
|
+
readonly onDeny: (id: string) => void;
|
|
66
|
+
readonly onAlwaysAllow?: (approval: ApprovalQueueItem) => void;
|
|
67
|
+
readonly onApproveAllLowRisk?: (ids: readonly string[]) => void;
|
|
68
|
+
readonly title?: string;
|
|
69
|
+
readonly empty?: ReactNode;
|
|
70
|
+
readonly className?: string;
|
|
71
|
+
}
|
|
72
|
+
export declare function ApprovalQueue({ approvals, onApprove, onDeny, onAlwaysAllow, onApproveAllLowRisk, title, empty, className, }: ApprovalQueueProps): import("react").JSX.Element;
|
|
73
|
+
export type PlanStepStatus = 'pending' | 'in_progress' | 'completed' | 'blocked' | 'skipped';
|
|
74
|
+
export interface PlanStep {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly title: string;
|
|
77
|
+
readonly status: PlanStepStatus;
|
|
78
|
+
readonly detail?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface PlanViewProps {
|
|
81
|
+
readonly steps: readonly PlanStep[];
|
|
82
|
+
readonly title?: string;
|
|
83
|
+
readonly summary?: string;
|
|
84
|
+
readonly empty?: ReactNode;
|
|
85
|
+
readonly className?: string;
|
|
86
|
+
}
|
|
87
|
+
export declare function PlanView({ steps, title, summary, empty, className }: PlanViewProps): import("react").JSX.Element;
|