dsh-toolview-kit 0.0.0-stage → 0.3.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/CHANGELOG.md +36 -0
- package/LICENSE +21 -0
- package/README.md +133 -2
- package/assets/dsh-toolview-kit-diff.png +0 -0
- package/assets/dsh-toolview-kit-shell.png +0 -0
- package/config/tools.json +116 -0
- package/cordis.patch.yml +4 -0
- package/docs/cards.md +70 -0
- package/docs/development.md +52 -0
- package/docs/installation.md +93 -0
- package/lib/client.js +823 -0
- package/lib/index.js +12 -0
- package/package.json +80 -4
- package/screenshots.json +4 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,823 @@
|
|
|
1
|
+
/* Generated by scripts/build.mjs. Do not edit lib/client.js directly. */
|
|
2
|
+
(() => {
|
|
3
|
+
try {
|
|
4
|
+
window.__ModuleLoader__.load({
|
|
5
|
+
id: 'dsh-toolview-kit',
|
|
6
|
+
factory: (require) => {
|
|
7
|
+
const React = require('react');
|
|
8
|
+
const TOOL_MAP = {
|
|
9
|
+
"ops_bash": {
|
|
10
|
+
"kind": "shell",
|
|
11
|
+
"label": "Bash",
|
|
12
|
+
"commandKeys": [
|
|
13
|
+
"command",
|
|
14
|
+
"cmd",
|
|
15
|
+
"script",
|
|
16
|
+
"shellCommand"
|
|
17
|
+
],
|
|
18
|
+
"targetKeys": [
|
|
19
|
+
"ips",
|
|
20
|
+
"hosts",
|
|
21
|
+
"targets"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"ops_inspect_local_file": {
|
|
25
|
+
"kind": "file-read",
|
|
26
|
+
"label": "Inspect file",
|
|
27
|
+
"pathKeys": [
|
|
28
|
+
"path",
|
|
29
|
+
"filePath"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"ops_grep": {
|
|
33
|
+
"kind": "file-read",
|
|
34
|
+
"label": "Search files",
|
|
35
|
+
"pathKeys": [
|
|
36
|
+
"path"
|
|
37
|
+
],
|
|
38
|
+
"queryKeys": [
|
|
39
|
+
"pattern"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"ops_glob": {
|
|
43
|
+
"kind": "file-read",
|
|
44
|
+
"label": "Find files",
|
|
45
|
+
"pathKeys": [
|
|
46
|
+
"path"
|
|
47
|
+
],
|
|
48
|
+
"queryKeys": [
|
|
49
|
+
"pattern"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"ops_stat": {
|
|
53
|
+
"kind": "file-read",
|
|
54
|
+
"label": "Inspect metadata",
|
|
55
|
+
"pathKeys": [
|
|
56
|
+
"path"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"ops_diff": {
|
|
60
|
+
"kind": "file-read",
|
|
61
|
+
"label": "Preview diff",
|
|
62
|
+
"pathKeys": [
|
|
63
|
+
"path"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"ops_read_files": {
|
|
67
|
+
"kind": "file-read",
|
|
68
|
+
"label": "Read files",
|
|
69
|
+
"pathKeys": [
|
|
70
|
+
"path",
|
|
71
|
+
"files"
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"ops_read_table": {
|
|
75
|
+
"kind": "file-read",
|
|
76
|
+
"label": "Read table",
|
|
77
|
+
"pathKeys": [
|
|
78
|
+
"path",
|
|
79
|
+
"filePath"
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"ops_read_docx": {
|
|
83
|
+
"kind": "file-read",
|
|
84
|
+
"label": "Read document",
|
|
85
|
+
"pathKeys": [
|
|
86
|
+
"path",
|
|
87
|
+
"filePath"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"ops_read_pdf": {
|
|
91
|
+
"kind": "file-read",
|
|
92
|
+
"label": "Read PDF",
|
|
93
|
+
"pathKeys": [
|
|
94
|
+
"path",
|
|
95
|
+
"filePath"
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
"ops_replace": {
|
|
99
|
+
"kind": "file-write",
|
|
100
|
+
"label": "Replace text",
|
|
101
|
+
"pathKeys": [
|
|
102
|
+
"path",
|
|
103
|
+
"filePath"
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
"ops_write_file": {
|
|
107
|
+
"kind": "file-write",
|
|
108
|
+
"label": "Write file",
|
|
109
|
+
"pathKeys": [
|
|
110
|
+
"path",
|
|
111
|
+
"filePath"
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
"ops_edit_file": {
|
|
115
|
+
"kind": "file-write",
|
|
116
|
+
"label": "Edit file",
|
|
117
|
+
"pathKeys": [
|
|
118
|
+
"path",
|
|
119
|
+
"filePath"
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
"ops_copy": {
|
|
123
|
+
"kind": "file-write",
|
|
124
|
+
"label": "Copy file",
|
|
125
|
+
"pathKeys": [
|
|
126
|
+
"source",
|
|
127
|
+
"destination"
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"ops_move": {
|
|
131
|
+
"kind": "file-write",
|
|
132
|
+
"label": "Move file",
|
|
133
|
+
"pathKeys": [
|
|
134
|
+
"source",
|
|
135
|
+
"destination"
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
"ops_remove": {
|
|
139
|
+
"kind": "file-write",
|
|
140
|
+
"label": "Remove file",
|
|
141
|
+
"pathKeys": [
|
|
142
|
+
"path",
|
|
143
|
+
"filePath"
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
"mcp__jumpserver__execute_command": {
|
|
147
|
+
"kind": "mcp-shell",
|
|
148
|
+
"label": "JumpServer",
|
|
149
|
+
"commandKeys": [
|
|
150
|
+
"command",
|
|
151
|
+
"cmd",
|
|
152
|
+
"script"
|
|
153
|
+
],
|
|
154
|
+
"targetKeys": [
|
|
155
|
+
"ips",
|
|
156
|
+
"hosts",
|
|
157
|
+
"targets"
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
"mcp__jumpserver-prod__execute_command": {
|
|
161
|
+
"kind": "mcp-shell",
|
|
162
|
+
"label": "JumpServer Prod",
|
|
163
|
+
"commandKeys": [
|
|
164
|
+
"command",
|
|
165
|
+
"cmd",
|
|
166
|
+
"script"
|
|
167
|
+
],
|
|
168
|
+
"targetKeys": [
|
|
169
|
+
"ips",
|
|
170
|
+
"hosts",
|
|
171
|
+
"targets"
|
|
172
|
+
]
|
|
173
|
+
},
|
|
174
|
+
"mcp__jumpserver__submit_command": {
|
|
175
|
+
"kind": "mcp-shell",
|
|
176
|
+
"label": "JumpServer (async)",
|
|
177
|
+
"commandKeys": [
|
|
178
|
+
"command",
|
|
179
|
+
"cmd",
|
|
180
|
+
"script"
|
|
181
|
+
],
|
|
182
|
+
"targetKeys": [
|
|
183
|
+
"ips",
|
|
184
|
+
"hosts",
|
|
185
|
+
"targets"
|
|
186
|
+
]
|
|
187
|
+
},
|
|
188
|
+
"mcp__jumpserver-prod__submit_command": {
|
|
189
|
+
"kind": "mcp-shell",
|
|
190
|
+
"label": "JumpServer Prod (async)",
|
|
191
|
+
"commandKeys": [
|
|
192
|
+
"command",
|
|
193
|
+
"cmd",
|
|
194
|
+
"script"
|
|
195
|
+
],
|
|
196
|
+
"targetKeys": [
|
|
197
|
+
"ips",
|
|
198
|
+
"hosts",
|
|
199
|
+
"targets"
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const h = React.createElement;
|
|
204
|
+
const TOOLVIEW_NAME = 'tool.call.toolview';
|
|
205
|
+
const MODULE_NAME = 'dsh-toolview-kit';
|
|
206
|
+
const MAX_OUTPUT_CHARS = 24000;
|
|
207
|
+
const MAX_SUMMARY_CHARS = 180;
|
|
208
|
+
const EXIT_CODE_RE = /\[exit code:\s*(-?\d+)\]\s*$/i;
|
|
209
|
+
const RECEIPT_HEADER_RE = /^\s*(\S+)\s*\|\s*([A-Z_]+)\s*\|\s*rc=(-?\d+)\s*>>\s*$/;
|
|
210
|
+
const JSON_OBJECT_RE = /^\s*[{[]/;
|
|
211
|
+
|
|
212
|
+
/*
|
|
213
|
+
* Host theme tokens, read straight off `dsh-client-ui-theme`
|
|
214
|
+
* (design-platform.css defines them on `body` for light and on
|
|
215
|
+
* `body[data-ds-dark-theme]` for dark). Skin plugins such as
|
|
216
|
+
* dsh-bloom-theme override these very names, so a card built on them
|
|
217
|
+
* follows the active skin with no per-theme code here.
|
|
218
|
+
*
|
|
219
|
+
* Fallbacks are deliberately neutral — `inherit` / `transparent` — so
|
|
220
|
+
* a host that defines none of them still yields text and surfaces that
|
|
221
|
+
* belong to the page instead of a light card on a dark conversation.
|
|
222
|
+
*/
|
|
223
|
+
const T = {
|
|
224
|
+
text: 'var(--dsw-alias-label-primary, inherit)',
|
|
225
|
+
secondary: 'var(--dsw-alias-label-secondary, inherit)',
|
|
226
|
+
tertiary: 'var(--dsw-alias-label-tertiary, inherit)',
|
|
227
|
+
caption: 'var(--dsw-alias-label-caption, var(--dsw-alias-label-tertiary, inherit))',
|
|
228
|
+
border: 'var(--dsw-alias-border-l1, rgba(128, 138, 155, 0.22))',
|
|
229
|
+
borderStrong: 'var(--dsw-alias-border-l2, rgba(128, 138, 155, 0.28))',
|
|
230
|
+
hairline: 'var(--dsw-alias-border-l4, rgba(128, 138, 155, 0.42))',
|
|
231
|
+
surface: 'var(--dsw-alias-bg-layer-2, var(--dsw-alias-markdown-code-block, rgba(127, 139, 158, 0.10)))',
|
|
232
|
+
codeSurface: 'var(--dsw-alias-markdown-code-block, transparent)',
|
|
233
|
+
surfaceStrong: 'var(--dsw-alias-markdown-code-block-banner, rgba(127, 139, 158, 0.16))',
|
|
234
|
+
success: 'var(--dsw-alias-state-success-primary, #3f9f6f)',
|
|
235
|
+
danger: 'var(--dsw-alias-state-error-primary, #d1524d)',
|
|
236
|
+
warn: 'var(--dsw-alias-state-warn-label, #b7791f)',
|
|
237
|
+
accent: 'var(--dsw-alias-state-business-primary, #4f7cf5)',
|
|
238
|
+
mono: "var(--ds-font-family-code, ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace)",
|
|
239
|
+
radius: 'var(--dsw-radius-lg, 12px)',
|
|
240
|
+
radiusSm: 'var(--dsw-radius-sm, 8px)'
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
function safeText(value) {
|
|
244
|
+
if (value === null || value === undefined) return '';
|
|
245
|
+
if (typeof value === 'string') return value;
|
|
246
|
+
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
247
|
+
try {
|
|
248
|
+
return JSON.stringify(value, null, 2);
|
|
249
|
+
} catch {
|
|
250
|
+
return String(value);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function compactText(value, limit) {
|
|
255
|
+
const text = safeText(value);
|
|
256
|
+
if (text.length <= limit) return text;
|
|
257
|
+
return text.slice(0, Math.max(0, limit - 1)) + '…';
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function pretty(value) {
|
|
261
|
+
if (typeof value === 'string') return value;
|
|
262
|
+
return safeText(value);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function firstValue(args, keys) {
|
|
266
|
+
for (const key of keys || []) {
|
|
267
|
+
if (args && args[key] !== undefined && args[key] !== null && args[key] !== '') {
|
|
268
|
+
return args[key];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function parseRaw(raw) {
|
|
275
|
+
if (raw && typeof raw === 'object') return raw;
|
|
276
|
+
if (typeof raw !== 'string' || raw.trim() === '') return {};
|
|
277
|
+
try {
|
|
278
|
+
const parsed = JSON.parse(raw);
|
|
279
|
+
return parsed && typeof parsed === 'object' ? parsed : { value: parsed };
|
|
280
|
+
} catch {
|
|
281
|
+
return { raw };
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function getArgs(block, phase) {
|
|
286
|
+
const raw = phase === 'result' ? block && block.call && block.call.argsRaw : block && block.argsRaw;
|
|
287
|
+
if (raw !== undefined) return parseRaw(raw);
|
|
288
|
+
if (block && block.call && block.call.args && typeof block.call.args === 'object') return block.call.args;
|
|
289
|
+
return {};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Turns any content payload (content blocks, strings, objects) into text. */
|
|
293
|
+
function contentText(value, depth) {
|
|
294
|
+
if (value === null || value === undefined) return '';
|
|
295
|
+
if (depth > 6) return compactText(value, 4000);
|
|
296
|
+
if (typeof value === 'string') return value;
|
|
297
|
+
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
298
|
+
if (Array.isArray(value)) {
|
|
299
|
+
return value.map((item) => contentText(item, depth + 1)).filter(Boolean).join('\n');
|
|
300
|
+
}
|
|
301
|
+
if (typeof value === 'object') {
|
|
302
|
+
if (value.type === 'text' && value.text !== undefined) return safeText(value.text);
|
|
303
|
+
if (typeof value.text === 'string') return value.text;
|
|
304
|
+
if (value.output !== undefined) return contentText(value.output, depth + 1);
|
|
305
|
+
if (value.content !== undefined) return contentText(value.content, depth + 1);
|
|
306
|
+
if (value.result !== undefined) return contentText(value.result, depth + 1);
|
|
307
|
+
if (value.json !== undefined) return pretty(value.json);
|
|
308
|
+
return pretty(value);
|
|
309
|
+
}
|
|
310
|
+
return safeText(value);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function rawResultText(block) {
|
|
314
|
+
if (!block) return '';
|
|
315
|
+
const primary = block.output !== undefined ? block.output
|
|
316
|
+
: block.content !== undefined ? block.content
|
|
317
|
+
: block.result !== undefined ? block.result
|
|
318
|
+
: undefined;
|
|
319
|
+
let text = contentText(primary, 0);
|
|
320
|
+
if (!text && block.error) text = contentText(block.error, 0);
|
|
321
|
+
return text;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function maybeJsonObject(text) {
|
|
325
|
+
if (typeof text !== 'string' || !JSON_OBJECT_RE.test(text)) return undefined;
|
|
326
|
+
try {
|
|
327
|
+
const parsed = JSON.parse(text);
|
|
328
|
+
return parsed && typeof parsed === 'object' ? parsed : undefined;
|
|
329
|
+
} catch {
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* JumpServer runs commands over Ansible, so every host chunk starts with
|
|
336
|
+
* `host | CHANGED | rc=0 >>`. That line is metadata, not output: keep the
|
|
337
|
+
* host and return code, drop the banner.
|
|
338
|
+
*/
|
|
339
|
+
function splitChunk(text) {
|
|
340
|
+
const lines = String(text === undefined || text === null ? '' : text).split(/\r?\n/);
|
|
341
|
+
let host = '';
|
|
342
|
+
let code;
|
|
343
|
+
const body = [];
|
|
344
|
+
for (const line of lines) {
|
|
345
|
+
const match = RECEIPT_HEADER_RE.exec(line);
|
|
346
|
+
if (match) {
|
|
347
|
+
if (!host) host = match[1];
|
|
348
|
+
if (code === undefined) code = Number(match[3]);
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
body.push(line);
|
|
352
|
+
}
|
|
353
|
+
return { host, code, text: body.join('\n').replace(/^\s*\n+|\n+\s*$/g, '').trim() };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* JumpServer MCP tools answer with a JSON receipt
|
|
358
|
+
* (`{ok, state, job_id, out, results: [{ip, ok, out}]}`) rather than a
|
|
359
|
+
* shell stream. Rendering that object verbatim is what made the card
|
|
360
|
+
* unreadable, so unwrap it into host sections plus a status line.
|
|
361
|
+
*/
|
|
362
|
+
function receiptFrom(text) {
|
|
363
|
+
const value = maybeJsonObject(text);
|
|
364
|
+
if (!value || Array.isArray(value)) return null;
|
|
365
|
+
const shaped = ['out', 'results', 'state', 'job_id', 'task_id', 'ok'].some((key) => key in value);
|
|
366
|
+
if (!shaped) return null;
|
|
367
|
+
|
|
368
|
+
const hosts = [];
|
|
369
|
+
if (Array.isArray(value.results)) {
|
|
370
|
+
for (const item of value.results) {
|
|
371
|
+
if (!item || typeof item !== 'object') continue;
|
|
372
|
+
const chunk = splitChunk(safeText(item.out !== undefined ? item.out : item.output));
|
|
373
|
+
hosts.push({
|
|
374
|
+
host: safeText(item.ip || item.host || chunk.host || ''),
|
|
375
|
+
code: chunk.code !== undefined ? chunk.code : (item.ok === false ? 1 : undefined),
|
|
376
|
+
text: chunk.text
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (hosts.length === 0) {
|
|
381
|
+
const chunk = splitChunk(safeText(value.out !== undefined ? value.out : value.output));
|
|
382
|
+
hosts.push({ host: chunk.host, code: chunk.code, text: chunk.text });
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const codes = hosts.map((entry) => entry.code).filter((code) => typeof code === 'number');
|
|
386
|
+
const exitCode = codes.length > 0 ? Math.max.apply(null, codes) : undefined;
|
|
387
|
+
const state = safeText(value.state || '');
|
|
388
|
+
const failed = value.ok === false || state === 'failed' || (exitCode !== undefined && exitCode !== 0);
|
|
389
|
+
|
|
390
|
+
return {
|
|
391
|
+
receipt: true,
|
|
392
|
+
output: hosts.map((entry) => entry.text).filter(Boolean).join('\n\n'),
|
|
393
|
+
exitCode,
|
|
394
|
+
hosts: hosts.filter((entry) => entry.text || entry.host),
|
|
395
|
+
job: safeText(value.job_id || value.task_id || ''),
|
|
396
|
+
state,
|
|
397
|
+
failed
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function parseExit(text, block) {
|
|
402
|
+
const direct = block && (block.exitCode !== undefined ? block.exitCode : (block.result && block.result.exitCode));
|
|
403
|
+
let exitCode = direct === undefined || direct === null || direct === '' ? undefined : Number(direct);
|
|
404
|
+
let output = text || '';
|
|
405
|
+
const match = output.match(EXIT_CODE_RE);
|
|
406
|
+
if (match) {
|
|
407
|
+
if (exitCode === undefined || Number.isNaN(exitCode)) exitCode = Number(match[1]);
|
|
408
|
+
output = output.slice(0, match.index).replace(/\s+$/, '');
|
|
409
|
+
}
|
|
410
|
+
if (Number.isNaN(exitCode)) exitCode = undefined;
|
|
411
|
+
return { output, exitCode };
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function normalizeResult(block, config) {
|
|
415
|
+
const text = rawResultText(block);
|
|
416
|
+
const kind = config && config.kind;
|
|
417
|
+
// Only MCP tools answer with job receipts; a shell or file tool that
|
|
418
|
+
// happens to print an object with an `ok` key must stay verbatim.
|
|
419
|
+
const receipt = kind === 'mcp-shell' || kind === 'mcp' ? receiptFrom(text) : null;
|
|
420
|
+
if (receipt) return receipt;
|
|
421
|
+
const parsed = parseExit(text, block);
|
|
422
|
+
return { receipt: false, output: parsed.output, exitCode: parsed.exitCode, hosts: [], job: '', state: '', failed: false };
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function toolNameOf(props, block) {
|
|
426
|
+
return props.toolName || (block && block.call && block.call.name) || (block && block.name) || 'tool';
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function statusOf(props, block, result) {
|
|
430
|
+
if (block && block.error && block.error.code === 'interrupted') return { key: 'cancelled', label: 'Cancelled', color: T.warn };
|
|
431
|
+
if (props.phase === 'preparing') return { key: 'queued', label: 'Queued', color: T.warn };
|
|
432
|
+
if (props.phase !== 'result') return { key: 'running', label: 'Running', color: T.accent };
|
|
433
|
+
const failed = Boolean(block && (block.isError || block.error))
|
|
434
|
+
|| Boolean(result && result.failed)
|
|
435
|
+
|| Boolean(result && result.exitCode !== undefined && result.exitCode !== 0);
|
|
436
|
+
return failed
|
|
437
|
+
? { key: 'error', label: 'Failed', color: T.danger }
|
|
438
|
+
: { key: 'done', label: 'Done', color: T.success };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function labelOf(name, config) {
|
|
442
|
+
if (config && config.label) return config.label;
|
|
443
|
+
if (name.indexOf('mcp__') === 0) {
|
|
444
|
+
const parts = name.split('__');
|
|
445
|
+
return parts.slice(1, -1).join(' · ') + ' · ' + parts[parts.length - 1];
|
|
446
|
+
}
|
|
447
|
+
return name.replace(/^ops_/, '').replace(/_/g, ' ');
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function targetText(value) {
|
|
451
|
+
if (value === undefined || value === null || value === '') return '';
|
|
452
|
+
if (Array.isArray(value)) return value.map(safeText).join(', ');
|
|
453
|
+
return compactText(value, 140);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function commandText(args, config) {
|
|
457
|
+
const value = firstValue(args, config && config.commandKeys);
|
|
458
|
+
return value === undefined ? '' : pretty(value);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function pathText(args, config) {
|
|
462
|
+
const value = firstValue(args, config && config.pathKeys);
|
|
463
|
+
return value === undefined ? '' : pretty(value);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function queryText(args, config) {
|
|
467
|
+
const value = firstValue(args, config && config.queryKeys);
|
|
468
|
+
return value === undefined ? '' : pretty(value);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function targetKeysText(args, config) {
|
|
472
|
+
const value = firstValue(args, config && config.targetKeys);
|
|
473
|
+
return targetText(value);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function payloadText(args) {
|
|
477
|
+
const value = firstValue(args, ['newText', 'content', 'text', 'oldText', 'body']);
|
|
478
|
+
return value === undefined ? '' : pretty(value);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function presentValue(object, keys) {
|
|
482
|
+
for (const key of keys || []) {
|
|
483
|
+
if (object && Object.prototype.hasOwnProperty.call(object, key)
|
|
484
|
+
&& object[key] !== undefined && object[key] !== null) {
|
|
485
|
+
return object[key];
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return undefined;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function diffText(args) {
|
|
492
|
+
const edits = Array.isArray(args && args.edits) ? args.edits : [];
|
|
493
|
+
const pairs = edits.length > 0 ? edits : [args || {}];
|
|
494
|
+
const chunks = [];
|
|
495
|
+
for (let index = 0; index < pairs.length; index += 1) {
|
|
496
|
+
const pair = pairs[index] || {};
|
|
497
|
+
const oldValue = presentValue(pair, ['oldText', 'old_string', 'old']);
|
|
498
|
+
const newValue = presentValue(pair, ['newText', 'new_string', 'new']);
|
|
499
|
+
if (oldValue === undefined && newValue === undefined) continue;
|
|
500
|
+
const oldLines = (oldValue === undefined ? '' : pretty(oldValue)).split(/\r?\n/);
|
|
501
|
+
const newLines = (newValue === undefined ? '' : pretty(newValue)).split(/\r?\n/);
|
|
502
|
+
const removed = oldLines.map((line) => '- ' + line).join('\n');
|
|
503
|
+
const added = newLines.map((line) => '+ ' + line).join('\n');
|
|
504
|
+
chunks.push('@@ edit ' + (index + 1) + ' @@\n' + removed + '\n' + added);
|
|
505
|
+
}
|
|
506
|
+
return chunks.join('\n\n');
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function CopyButton({ value, label }) {
|
|
510
|
+
const [copied, setCopied] = React.useState(false);
|
|
511
|
+
const copy = async (event) => {
|
|
512
|
+
event.stopPropagation();
|
|
513
|
+
try {
|
|
514
|
+
if (navigator && navigator.clipboard && navigator.clipboard.writeText) {
|
|
515
|
+
await navigator.clipboard.writeText(value || '');
|
|
516
|
+
} else {
|
|
517
|
+
const area = document.createElement('textarea');
|
|
518
|
+
area.value = value || '';
|
|
519
|
+
area.style.position = 'fixed';
|
|
520
|
+
area.style.opacity = '0';
|
|
521
|
+
document.body.appendChild(area);
|
|
522
|
+
area.select();
|
|
523
|
+
document.execCommand('copy');
|
|
524
|
+
area.remove();
|
|
525
|
+
}
|
|
526
|
+
setCopied(true);
|
|
527
|
+
setTimeout(() => setCopied(false), 1200);
|
|
528
|
+
} catch {
|
|
529
|
+
setCopied(false);
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
return h('button', {
|
|
533
|
+
type: 'button',
|
|
534
|
+
onClick: copy,
|
|
535
|
+
title: 'Copy ' + (label || 'text'),
|
|
536
|
+
style: {
|
|
537
|
+
flex: 'none',
|
|
538
|
+
border: '0.5px solid ' + T.hairline,
|
|
539
|
+
borderRadius: 999,
|
|
540
|
+
background: 'transparent',
|
|
541
|
+
color: T.caption,
|
|
542
|
+
fontSize: 11,
|
|
543
|
+
lineHeight: '16px',
|
|
544
|
+
padding: '0 7px',
|
|
545
|
+
cursor: 'pointer'
|
|
546
|
+
}
|
|
547
|
+
}, copied ? 'Copied' : 'Copy');
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function Section({ title, value, maxHeight, copyable }) {
|
|
551
|
+
if (!value) return null;
|
|
552
|
+
return h('section', { style: { borderTop: '0.5px solid ' + T.borderStrong } },
|
|
553
|
+
h('div', {
|
|
554
|
+
style: {
|
|
555
|
+
display: 'flex',
|
|
556
|
+
alignItems: 'center',
|
|
557
|
+
justifyContent: 'space-between',
|
|
558
|
+
gap: 8,
|
|
559
|
+
padding: '7px 12px 0'
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
h('span', { style: { color: T.caption, fontSize: 11.5, letterSpacing: 0.1 } }, title),
|
|
563
|
+
copyable === false ? null : h(CopyButton, { value, label: title })
|
|
564
|
+
),
|
|
565
|
+
h('pre', {
|
|
566
|
+
style: {
|
|
567
|
+
margin: 0,
|
|
568
|
+
padding: '5px 12px 10px',
|
|
569
|
+
background: T.codeSurface,
|
|
570
|
+
color: T.secondary,
|
|
571
|
+
fontFamily: T.mono,
|
|
572
|
+
fontSize: 12,
|
|
573
|
+
lineHeight: 1.55,
|
|
574
|
+
whiteSpace: 'pre-wrap',
|
|
575
|
+
overflowWrap: 'anywhere',
|
|
576
|
+
overflow: 'auto',
|
|
577
|
+
maxHeight: maxHeight || 260
|
|
578
|
+
}
|
|
579
|
+
}, value)
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function DiffSection({ value }) {
|
|
584
|
+
if (!value) return null;
|
|
585
|
+
const lines = String(value).split(String.fromCharCode(10));
|
|
586
|
+
return h('section', { style: { borderTop: '0.5px solid ' + T.borderStrong } },
|
|
587
|
+
h('div', {
|
|
588
|
+
style: {
|
|
589
|
+
display: 'flex',
|
|
590
|
+
alignItems: 'center',
|
|
591
|
+
justifyContent: 'space-between',
|
|
592
|
+
gap: 8,
|
|
593
|
+
padding: '7px 12px 0'
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
h('span', { style: { color: T.caption, fontSize: 11.5, letterSpacing: 0.1 } }, 'Diff'),
|
|
597
|
+
h(CopyButton, { value, label: 'diff' })
|
|
598
|
+
),
|
|
599
|
+
h('div', {
|
|
600
|
+
style: {
|
|
601
|
+
padding: '5px 12px 10px',
|
|
602
|
+
background: T.codeSurface,
|
|
603
|
+
color: T.secondary,
|
|
604
|
+
fontFamily: T.mono,
|
|
605
|
+
fontSize: 12,
|
|
606
|
+
lineHeight: 1.55,
|
|
607
|
+
whiteSpace: 'pre-wrap',
|
|
608
|
+
overflowWrap: 'anywhere',
|
|
609
|
+
overflow: 'auto',
|
|
610
|
+
maxHeight: 360
|
|
611
|
+
}
|
|
612
|
+
}, lines.map((line, index) => {
|
|
613
|
+
const removed = line.indexOf('- ') === 0;
|
|
614
|
+
const added = line.indexOf('+ ') === 0;
|
|
615
|
+
const header = line.indexOf('@@') === 0;
|
|
616
|
+
const color = removed ? T.danger : added ? T.success : header ? T.caption : T.secondary;
|
|
617
|
+
const background = removed
|
|
618
|
+
? 'color-mix(in srgb, ' + T.danger + ' 14%, transparent)'
|
|
619
|
+
: added
|
|
620
|
+
? 'color-mix(in srgb, ' + T.success + ' 14%, transparent)'
|
|
621
|
+
: 'transparent';
|
|
622
|
+
return h('div', {
|
|
623
|
+
key: index,
|
|
624
|
+
style: { color, background, minHeight: 18, padding: '0 4px', borderRadius: 2 }
|
|
625
|
+
}, line || ' ');
|
|
626
|
+
}))
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function Meta({ label, value }) {
|
|
631
|
+
if (!value) return null;
|
|
632
|
+
return h('span', { style: { color: T.caption, fontSize: 11.5, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } },
|
|
633
|
+
label ? label + ': ' + compactText(value, 120) : compactText(value, 120));
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
const ROW_STYLE = {
|
|
637
|
+
display: 'flex',
|
|
638
|
+
alignItems: 'center',
|
|
639
|
+
gap: 8,
|
|
640
|
+
width: '100%',
|
|
641
|
+
minHeight: 26,
|
|
642
|
+
margin: 0,
|
|
643
|
+
padding: '2px 4px',
|
|
644
|
+
border: 0,
|
|
645
|
+
borderRadius: T.radiusSm,
|
|
646
|
+
background: 'transparent',
|
|
647
|
+
color: T.tertiary,
|
|
648
|
+
font: 'inherit',
|
|
649
|
+
fontSize: 13,
|
|
650
|
+
lineHeight: '20px',
|
|
651
|
+
textAlign: 'left',
|
|
652
|
+
cursor: 'pointer',
|
|
653
|
+
transition: 'color 100ms ease'
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
function ToolCard(props) {
|
|
657
|
+
const block = props.block || {};
|
|
658
|
+
const phase = props.phase || 'start';
|
|
659
|
+
const name = toolNameOf(props, block);
|
|
660
|
+
const config = TOOL_MAP[name] || { kind: name.indexOf('mcp__') === 0 ? 'mcp' : 'generic', label: name };
|
|
661
|
+
const args = getArgs(block, phase);
|
|
662
|
+
const [fallbackExpanded, setFallbackExpanded] = React.useState(false);
|
|
663
|
+
const [hovered, setHovered] = React.useState(false);
|
|
664
|
+
const disclosure = typeof props.useDisclosure === 'function'
|
|
665
|
+
? props.useDisclosure()
|
|
666
|
+
: { expanded: fallbackExpanded, toggle: () => setFallbackExpanded((value) => !value) };
|
|
667
|
+
const expanded = Boolean(disclosure && disclosure.expanded);
|
|
668
|
+
const toggle = disclosure && disclosure.toggle ? disclosure.toggle : () => setFallbackExpanded((value) => !value);
|
|
669
|
+
|
|
670
|
+
const result = normalizeResult(block, config);
|
|
671
|
+
const status = statusOf(props, block, result);
|
|
672
|
+
const command = commandText(args, config);
|
|
673
|
+
const path = pathText(args, config);
|
|
674
|
+
const query = queryText(args, config);
|
|
675
|
+
const targets = targetKeysText(args, config);
|
|
676
|
+
const payload = payloadText(args);
|
|
677
|
+
const diff = config.kind === 'file-write' ? diffText(args) : '';
|
|
678
|
+
const expectedRevision = config.kind === 'file-write'
|
|
679
|
+
? firstValue(args, ['expectedRevision', 'revision'])
|
|
680
|
+
: undefined;
|
|
681
|
+
const isShell = config.kind === 'shell' || config.kind === 'mcp-shell';
|
|
682
|
+
const primary = isShell ? command : path;
|
|
683
|
+
const summary = compactText(primary || query || payload || 'Tool call', MAX_SUMMARY_CHARS);
|
|
684
|
+
const output = compactText(result.output || (phase === 'result' ? 'No output' : ''), MAX_OUTPUT_CHARS);
|
|
685
|
+
const cardLabel = labelOf(name, config);
|
|
686
|
+
const title = name.indexOf('mcp__') === 0 ? 'MCP · ' + cardLabel : cardLabel;
|
|
687
|
+
const exitLabel = result.exitCode === undefined ? '' : 'exit ' + result.exitCode;
|
|
688
|
+
const failedExit = result.exitCode !== undefined && result.exitCode !== 0;
|
|
689
|
+
const hosts = result.hosts || [];
|
|
690
|
+
const multiHost = hosts.length > 1;
|
|
691
|
+
|
|
692
|
+
const metaItems = [
|
|
693
|
+
h(Meta, { key: 'status', label: 'Status', value: status.label }),
|
|
694
|
+
h(Meta, { key: 'tool', label: 'Tool', value: name }),
|
|
695
|
+
h(Meta, { key: 'cwd', label: 'CWD', value: props.cwd }),
|
|
696
|
+
h(Meta, { key: 'target', label: 'Target', value: targets }),
|
|
697
|
+
h(Meta, { key: 'job', label: 'Job', value: result.job }),
|
|
698
|
+
h(Meta, { key: 'state', label: 'State', value: result.state }),
|
|
699
|
+
h(Meta, { key: 'revision', label: 'Expected revision', value: expectedRevision }),
|
|
700
|
+
exitLabel ? h(Meta, { key: 'exit', label: 'Result', value: exitLabel }) : null
|
|
701
|
+
];
|
|
702
|
+
|
|
703
|
+
const sections = [];
|
|
704
|
+
if (command) sections.push(h(Section, { key: 'command', title: 'Command', value: '$ ' + command, maxHeight: 180 }));
|
|
705
|
+
if (path && !isShell) sections.push(h(Section, { key: 'path', title: 'Path', value: path, maxHeight: 140 }));
|
|
706
|
+
if (query) sections.push(h(Section, { key: 'query', title: 'Query', value: query, maxHeight: 140 }));
|
|
707
|
+
if (diff) {
|
|
708
|
+
sections.push(h(DiffSection, { key: 'diff', value: diff }));
|
|
709
|
+
} else if (payload) {
|
|
710
|
+
sections.push(h(Section, { key: 'payload', title: config.kind === 'file-write' ? 'Change' : 'Arguments', value: payload, maxHeight: 220 }));
|
|
711
|
+
}
|
|
712
|
+
if (multiHost) {
|
|
713
|
+
for (let index = 0; index < hosts.length; index += 1) {
|
|
714
|
+
const entry = hosts[index];
|
|
715
|
+
if (!entry.text) continue;
|
|
716
|
+
sections.push(h(Section, {
|
|
717
|
+
key: 'host-' + index,
|
|
718
|
+
title: entry.host || 'Output',
|
|
719
|
+
value: entry.text,
|
|
720
|
+
maxHeight: 240
|
|
721
|
+
}));
|
|
722
|
+
}
|
|
723
|
+
} else if (output) {
|
|
724
|
+
sections.push(h(Section, { key: 'output', title: 'Output', value: output, maxHeight: 300 }));
|
|
725
|
+
}
|
|
726
|
+
if (sections.length === 0) {
|
|
727
|
+
sections.push(h(Section, { key: 'args', title: 'Arguments', value: pretty(args), maxHeight: 220 }));
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
return h('div', {
|
|
731
|
+
style: { display: 'flex', flexDirection: 'column', margin: '2px 0' },
|
|
732
|
+
onMouseEnter: () => setHovered(true),
|
|
733
|
+
onMouseLeave: () => setHovered(false)
|
|
734
|
+
},
|
|
735
|
+
h('button', {
|
|
736
|
+
type: 'button',
|
|
737
|
+
onClick: toggle,
|
|
738
|
+
'aria-expanded': expanded,
|
|
739
|
+
style: Object.assign({}, ROW_STYLE, { color: hovered || expanded ? T.secondary : T.tertiary })
|
|
740
|
+
},
|
|
741
|
+
status.key === 'running' || status.key === 'queued'
|
|
742
|
+
? h('span', {
|
|
743
|
+
style: {
|
|
744
|
+
flex: '0 0 auto',
|
|
745
|
+
width: 7,
|
|
746
|
+
height: 7,
|
|
747
|
+
borderRadius: '50%',
|
|
748
|
+
border: '1px solid ' + status.color,
|
|
749
|
+
boxSizing: 'border-box'
|
|
750
|
+
}
|
|
751
|
+
})
|
|
752
|
+
: h('span', {
|
|
753
|
+
style: {
|
|
754
|
+
flex: '0 0 auto',
|
|
755
|
+
width: 7,
|
|
756
|
+
height: 7,
|
|
757
|
+
borderRadius: '50%',
|
|
758
|
+
background: status.color
|
|
759
|
+
}
|
|
760
|
+
}),
|
|
761
|
+
h('span', { style: { flex: 'none', fontSize: 13 } }, title),
|
|
762
|
+
summary ? h('span', { style: { flex: 'none', color: T.caption } }, '·') : null,
|
|
763
|
+
h('span', {
|
|
764
|
+
style: { minWidth: 0, flex: 1, color: T.caption, fontSize: 13, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }
|
|
765
|
+
}, summary),
|
|
766
|
+
targets ? h(Meta, { label: '', value: targets }) : null,
|
|
767
|
+
failedExit ? h('span', {
|
|
768
|
+
style: { display: 'inline-flex', alignItems: 'center', gap: 4, flex: 'none', color: T.danger, fontSize: 11.5 }
|
|
769
|
+
},
|
|
770
|
+
h('span', { style: { width: 4, height: 4, borderRadius: '50%', background: 'currentColor' } }),
|
|
771
|
+
exitLabel
|
|
772
|
+
) : null,
|
|
773
|
+
h('span', {
|
|
774
|
+
style: {
|
|
775
|
+
flex: 'none',
|
|
776
|
+
color: T.caption,
|
|
777
|
+
fontSize: 13,
|
|
778
|
+
transform: expanded ? 'rotate(90deg)' : 'none',
|
|
779
|
+
transition: 'transform 120ms ease'
|
|
780
|
+
}
|
|
781
|
+
}, '›')
|
|
782
|
+
),
|
|
783
|
+
expanded ? h('div', {
|
|
784
|
+
style: {
|
|
785
|
+
margin: '4px 0 6px 4px',
|
|
786
|
+
border: '0.5px solid ' + T.border,
|
|
787
|
+
borderRadius: T.radius,
|
|
788
|
+
background: T.surface,
|
|
789
|
+
overflow: 'hidden'
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '4px 14px', padding: '8px 12px' } }, metaItems),
|
|
793
|
+
sections
|
|
794
|
+
) : null
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function register(ctx, key) {
|
|
799
|
+
// Same call shape the in-tree genui plugin uses on this DSH version:
|
|
800
|
+
// inject() runs the factory when the keyed slot is declared, and the
|
|
801
|
+
// factory returns the registration disposer.
|
|
802
|
+
ctx.slots.inject(TOOLVIEW_NAME, () => ctx.slots.register({ name: TOOLVIEW_NAME, key }, ToolCard));
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const plugin = {
|
|
806
|
+
name: MODULE_NAME,
|
|
807
|
+
inject: ['slots'],
|
|
808
|
+
apply(ctx) {
|
|
809
|
+
for (const key of Object.keys(TOOL_MAP)) register(ctx, key);
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
const module = { exports: plugin };
|
|
814
|
+
const exports = module.exports;
|
|
815
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
816
|
+
return module.exports;
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
} catch (error) {
|
|
820
|
+
// A client plugin must not prevent the rest of the DSH profile from loading.
|
|
821
|
+
console.error('[dsh-toolview-kit] failed to register', error);
|
|
822
|
+
}
|
|
823
|
+
})();
|