@renxqoo/renx-code 0.0.3 → 0.0.4
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/README.md +58 -223
- package/bin/renx.cjs +34 -0
- package/package.json +27 -83
- package/src/App.tsx +297 -0
- package/src/agent/runtime/event-format.ts +258 -0
- package/src/agent/runtime/model-types.ts +13 -0
- package/src/agent/runtime/runtime.context-usage.test.ts +193 -0
- package/src/agent/runtime/runtime.error-handling.test.ts +236 -0
- package/src/agent/runtime/runtime.simple.test.ts +16 -0
- package/src/agent/runtime/runtime.test.ts +293 -0
- package/src/agent/runtime/runtime.ts +881 -0
- package/src/agent/runtime/runtime.usage-forwarding.test.ts +229 -0
- package/src/agent/runtime/source-modules.test.ts +57 -0
- package/src/agent/runtime/source-modules.ts +353 -0
- package/src/agent/runtime/tool-call-buffer.test.ts +65 -0
- package/src/agent/runtime/tool-call-buffer.ts +60 -0
- package/src/agent/runtime/tool-confirmation.test.ts +56 -0
- package/src/agent/runtime/tool-confirmation.ts +15 -0
- package/src/agent/runtime/types.ts +99 -0
- package/src/commands/slash-commands.test.ts +216 -0
- package/src/commands/slash-commands.ts +64 -0
- package/src/components/chat/assistant-reply.test.tsx +47 -0
- package/src/components/chat/assistant-reply.tsx +136 -0
- package/src/components/chat/assistant-segment.test.ts +99 -0
- package/src/components/chat/assistant-segment.tsx +125 -0
- package/src/components/chat/assistant-tool-group.tsx +900 -0
- package/src/components/chat/code-block.test.tsx +206 -0
- package/src/components/chat/code-block.tsx +313 -0
- package/src/components/chat/prompt-card.tsx +81 -0
- package/src/components/chat/segment-groups.test.ts +52 -0
- package/src/components/chat/segment-groups.ts +106 -0
- package/src/components/chat/turn-item.tsx +39 -0
- package/src/components/conversation-panel.tsx +43 -0
- package/src/components/file-mention-menu.tsx +77 -0
- package/src/components/file-picker-dialog.tsx +206 -0
- package/src/components/footer-hints.tsx +75 -0
- package/src/components/model-picker-dialog.tsx +248 -0
- package/src/components/prompt.tsx +233 -0
- package/src/components/slash-command-menu.tsx +65 -0
- package/src/components/tool-confirm-dialog-content.test.ts +103 -0
- package/src/components/tool-confirm-dialog-content.ts +186 -0
- package/src/components/tool-confirm-dialog.tsx +187 -0
- package/src/components/tool-display-config.ts +119 -0
- package/src/context-usage-regressions.test.ts +26 -0
- package/src/files/attachment-capabilities.test.ts +30 -0
- package/src/files/attachment-capabilities.ts +50 -0
- package/src/files/attachment-content.ts +153 -0
- package/src/files/file-mention-query.test.ts +34 -0
- package/src/files/file-mention-query.ts +32 -0
- package/src/files/prompt-display.ts +13 -0
- package/src/files/types.ts +5 -0
- package/src/files/workspace-files.ts +63 -0
- package/src/hooks/agent-event-handlers.test.ts +207 -0
- package/src/hooks/agent-event-handlers.ts +196 -0
- package/src/hooks/chat-local-replies.fixed.test.ts +119 -0
- package/src/hooks/chat-local-replies.test.ts +153 -0
- package/src/hooks/chat-local-replies.ts +63 -0
- package/src/hooks/turn-updater.test.ts +70 -0
- package/src/hooks/turn-updater.ts +166 -0
- package/src/hooks/use-agent-chat.context.test.ts +10 -0
- package/src/hooks/use-agent-chat.status.test.ts +14 -0
- package/src/hooks/use-agent-chat.test.ts +80 -0
- package/src/hooks/use-agent-chat.ts +621 -0
- package/src/hooks/use-file-mention-menu.ts +196 -0
- package/src/hooks/use-file-picker.ts +185 -0
- package/src/hooks/use-model-picker.ts +196 -0
- package/src/hooks/use-slash-command-menu.ts +154 -0
- package/src/index.tsx +55 -0
- package/src/runtime/clipboard.test.ts +43 -0
- package/src/runtime/clipboard.ts +89 -0
- package/src/runtime/exit.test.ts +177 -0
- package/src/runtime/exit.ts +98 -0
- package/src/runtime/runtime-support.test.ts +31 -0
- package/src/runtime/terminal-theme.test.ts +55 -0
- package/src/runtime/terminal-theme.ts +196 -0
- package/src/types/chat.ts +32 -0
- package/src/types/message-content.ts +48 -0
- package/src/ui/open-code-theme.ts +176 -0
- package/src/ui/opencode-markdown.ts +211 -0
- package/src/ui/theme.simple.test.ts +52 -0
- package/src/ui/theme.test.ts +151 -0
- package/src/ui/theme.ts +152 -0
- package/src/utils/time.test.ts +144 -0
- package/src/utils/time.ts +7 -0
- package/tsconfig.json +30 -0
- package/LICENSE +0 -21
- package/dist/App.d.ts +0 -2
- package/dist/App.d.ts.map +0 -1
- package/dist/App.js +0 -170
- package/dist/App.js.map +0 -1
- package/dist/agent/prompts/system.d.ts +0 -24
- package/dist/agent/prompts/system.d.ts.map +0 -1
- package/dist/agent/prompts/system.js +0 -222
- package/dist/agent/prompts/system.js.map +0 -1
- package/dist/agent/runtime/event-format.d.ts +0 -17
- package/dist/agent/runtime/event-format.d.ts.map +0 -1
- package/dist/agent/runtime/event-format.js +0 -194
- package/dist/agent/runtime/event-format.js.map +0 -1
- package/dist/agent/runtime/model-types.d.ts +0 -13
- package/dist/agent/runtime/model-types.d.ts.map +0 -1
- package/dist/agent/runtime/model-types.js +0 -1
- package/dist/agent/runtime/model-types.js.map +0 -1
- package/dist/agent/runtime/runtime.d.ts +0 -16
- package/dist/agent/runtime/runtime.d.ts.map +0 -1
- package/dist/agent/runtime/runtime.js +0 -691
- package/dist/agent/runtime/runtime.js.map +0 -1
- package/dist/agent/runtime/source-modules.d.ts +0 -176
- package/dist/agent/runtime/source-modules.d.ts.map +0 -1
- package/dist/agent/runtime/source-modules.js +0 -110
- package/dist/agent/runtime/source-modules.js.map +0 -1
- package/dist/agent/runtime/tool-call-buffer.d.ts +0 -12
- package/dist/agent/runtime/tool-call-buffer.d.ts.map +0 -1
- package/dist/agent/runtime/tool-call-buffer.js +0 -48
- package/dist/agent/runtime/tool-call-buffer.js.map +0 -1
- package/dist/agent/runtime/tool-confirmation.d.ts +0 -3
- package/dist/agent/runtime/tool-confirmation.d.ts.map +0 -1
- package/dist/agent/runtime/tool-confirmation.js +0 -9
- package/dist/agent/runtime/tool-confirmation.js.map +0 -1
- package/dist/agent/runtime/types.d.ts +0 -86
- package/dist/agent/runtime/types.d.ts.map +0 -1
- package/dist/agent/runtime/types.js +0 -1
- package/dist/agent/runtime/types.js.map +0 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -12
- package/dist/cli.js.map +0 -1
- package/dist/commands/slash-commands.d.ts +0 -11
- package/dist/commands/slash-commands.d.ts.map +0 -1
- package/dist/commands/slash-commands.js +0 -48
- package/dist/commands/slash-commands.js.map +0 -1
- package/dist/components/chat/assistant-reply.d.ts +0 -13
- package/dist/components/chat/assistant-reply.d.ts.map +0 -1
- package/dist/components/chat/assistant-reply.js +0 -78
- package/dist/components/chat/assistant-reply.js.map +0 -1
- package/dist/components/chat/assistant-segment.d.ts +0 -8
- package/dist/components/chat/assistant-segment.d.ts.map +0 -1
- package/dist/components/chat/assistant-segment.js +0 -54
- package/dist/components/chat/assistant-segment.js.map +0 -1
- package/dist/components/chat/assistant-tool-group.d.ts +0 -7
- package/dist/components/chat/assistant-tool-group.d.ts.map +0 -1
- package/dist/components/chat/assistant-tool-group.js +0 -695
- package/dist/components/chat/assistant-tool-group.js.map +0 -1
- package/dist/components/chat/code-block.d.ts +0 -16
- package/dist/components/chat/code-block.d.ts.map +0 -1
- package/dist/components/chat/code-block.js +0 -194
- package/dist/components/chat/code-block.js.map +0 -1
- package/dist/components/chat/prompt-card.d.ts +0 -9
- package/dist/components/chat/prompt-card.d.ts.map +0 -1
- package/dist/components/chat/prompt-card.js +0 -18
- package/dist/components/chat/prompt-card.js.map +0 -1
- package/dist/components/chat/segment-groups.d.ts +0 -24
- package/dist/components/chat/segment-groups.d.ts.map +0 -1
- package/dist/components/chat/segment-groups.js +0 -69
- package/dist/components/chat/segment-groups.js.map +0 -1
- package/dist/components/chat/turn-item.d.ts +0 -9
- package/dist/components/chat/turn-item.d.ts.map +0 -1
- package/dist/components/chat/turn-item.js +0 -11
- package/dist/components/chat/turn-item.js.map +0 -1
- package/dist/components/conversation-panel.d.ts +0 -8
- package/dist/components/conversation-panel.d.ts.map +0 -1
- package/dist/components/conversation-panel.js +0 -8
- package/dist/components/conversation-panel.js.map +0 -1
- package/dist/components/file-mention-menu.d.ts +0 -11
- package/dist/components/file-mention-menu.d.ts.map +0 -1
- package/dist/components/file-mention-menu.js +0 -15
- package/dist/components/file-mention-menu.js.map +0 -1
- package/dist/components/file-picker-dialog.d.ts +0 -21
- package/dist/components/file-picker-dialog.d.ts.map +0 -1
- package/dist/components/file-picker-dialog.js +0 -48
- package/dist/components/file-picker-dialog.js.map +0 -1
- package/dist/components/footer-hints.d.ts +0 -7
- package/dist/components/footer-hints.d.ts.map +0 -1
- package/dist/components/footer-hints.js +0 -29
- package/dist/components/footer-hints.js.map +0 -1
- package/dist/components/model-picker-dialog.d.ts +0 -20
- package/dist/components/model-picker-dialog.d.ts.map +0 -1
- package/dist/components/model-picker-dialog.js +0 -72
- package/dist/components/model-picker-dialog.js.map +0 -1
- package/dist/components/prompt.d.ts +0 -18
- package/dist/components/prompt.d.ts.map +0 -1
- package/dist/components/prompt.js +0 -96
- package/dist/components/prompt.js.map +0 -1
- package/dist/components/slash-command-menu.d.ts +0 -9
- package/dist/components/slash-command-menu.d.ts.map +0 -1
- package/dist/components/slash-command-menu.js +0 -20
- package/dist/components/slash-command-menu.js.map +0 -1
- package/dist/components/tool-confirm-dialog-content.d.ts +0 -15
- package/dist/components/tool-confirm-dialog-content.d.ts.map +0 -1
- package/dist/components/tool-confirm-dialog-content.js +0 -143
- package/dist/components/tool-confirm-dialog-content.js.map +0 -1
- package/dist/components/tool-confirm-dialog.d.ts +0 -12
- package/dist/components/tool-confirm-dialog.d.ts.map +0 -1
- package/dist/components/tool-confirm-dialog.js +0 -21
- package/dist/components/tool-confirm-dialog.js.map +0 -1
- package/dist/components/tool-display-config.d.ts +0 -11
- package/dist/components/tool-display-config.d.ts.map +0 -1
- package/dist/components/tool-display-config.js +0 -94
- package/dist/components/tool-display-config.js.map +0 -1
- package/dist/config/paths.d.ts +0 -7
- package/dist/config/paths.d.ts.map +0 -1
- package/dist/config/paths.js +0 -24
- package/dist/config/paths.js.map +0 -1
- package/dist/files/attachment-capabilities.d.ts +0 -19
- package/dist/files/attachment-capabilities.d.ts.map +0 -1
- package/dist/files/attachment-capabilities.js +0 -26
- package/dist/files/attachment-capabilities.js.map +0 -1
- package/dist/files/attachment-content.d.ts +0 -5
- package/dist/files/attachment-content.d.ts.map +0 -1
- package/dist/files/attachment-content.js +0 -117
- package/dist/files/attachment-content.js.map +0 -1
- package/dist/files/file-mention-query.d.ts +0 -9
- package/dist/files/file-mention-query.d.ts.map +0 -1
- package/dist/files/file-mention-query.js +0 -23
- package/dist/files/file-mention-query.js.map +0 -1
- package/dist/files/prompt-display.d.ts +0 -3
- package/dist/files/prompt-display.d.ts.map +0 -1
- package/dist/files/prompt-display.js +0 -11
- package/dist/files/prompt-display.js.map +0 -1
- package/dist/files/types.d.ts +0 -6
- package/dist/files/types.d.ts.map +0 -1
- package/dist/files/types.js +0 -1
- package/dist/files/types.js.map +0 -1
- package/dist/files/workspace-files.d.ts +0 -3
- package/dist/files/workspace-files.d.ts.map +0 -1
- package/dist/files/workspace-files.js +0 -48
- package/dist/files/workspace-files.js.map +0 -1
- package/dist/hooks/agent-event-handlers.d.ts +0 -11
- package/dist/hooks/agent-event-handlers.d.ts.map +0 -1
- package/dist/hooks/agent-event-handlers.js +0 -137
- package/dist/hooks/agent-event-handlers.js.map +0 -1
- package/dist/hooks/chat-local-replies.d.ts +0 -9
- package/dist/hooks/chat-local-replies.d.ts.map +0 -1
- package/dist/hooks/chat-local-replies.js +0 -54
- package/dist/hooks/chat-local-replies.js.map +0 -1
- package/dist/hooks/turn-updater.d.ts +0 -9
- package/dist/hooks/turn-updater.d.ts.map +0 -1
- package/dist/hooks/turn-updater.js +0 -103
- package/dist/hooks/turn-updater.js.map +0 -1
- package/dist/hooks/use-agent-chat.d.ts +0 -29
- package/dist/hooks/use-agent-chat.d.ts.map +0 -1
- package/dist/hooks/use-agent-chat.js +0 -455
- package/dist/hooks/use-agent-chat.js.map +0 -1
- package/dist/hooks/use-file-mention-menu.d.ts +0 -22
- package/dist/hooks/use-file-mention-menu.d.ts.map +0 -1
- package/dist/hooks/use-file-mention-menu.js +0 -137
- package/dist/hooks/use-file-mention-menu.js.map +0 -1
- package/dist/hooks/use-file-picker.d.ts +0 -21
- package/dist/hooks/use-file-picker.d.ts.map +0 -1
- package/dist/hooks/use-file-picker.js +0 -145
- package/dist/hooks/use-file-picker.js.map +0 -1
- package/dist/hooks/use-model-picker.d.ts +0 -23
- package/dist/hooks/use-model-picker.d.ts.map +0 -1
- package/dist/hooks/use-model-picker.js +0 -151
- package/dist/hooks/use-model-picker.js.map +0 -1
- package/dist/hooks/use-slash-command-menu.d.ts +0 -19
- package/dist/hooks/use-slash-command-menu.d.ts.map +0 -1
- package/dist/hooks/use-slash-command-menu.js +0 -101
- package/dist/hooks/use-slash-command-menu.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- package/dist/run-cli-app.d.ts +0 -2
- package/dist/run-cli-app.d.ts.map +0 -1
- package/dist/run-cli-app.js +0 -41
- package/dist/run-cli-app.js.map +0 -1
- package/dist/runtime/clipboard.d.ts +0 -10
- package/dist/runtime/clipboard.d.ts.map +0 -1
- package/dist/runtime/clipboard.js +0 -64
- package/dist/runtime/clipboard.js.map +0 -1
- package/dist/runtime/exit.d.ts +0 -7
- package/dist/runtime/exit.d.ts.map +0 -1
- package/dist/runtime/exit.js +0 -85
- package/dist/runtime/exit.js.map +0 -1
- package/dist/runtime/runtime-support.d.ts +0 -4
- package/dist/runtime/runtime-support.d.ts.map +0 -1
- package/dist/runtime/runtime-support.js +0 -19
- package/dist/runtime/runtime-support.js.map +0 -1
- package/dist/runtime/terminal-theme.d.ts +0 -25
- package/dist/runtime/terminal-theme.d.ts.map +0 -1
- package/dist/runtime/terminal-theme.js +0 -148
- package/dist/runtime/terminal-theme.js.map +0 -1
- package/dist/types/chat.d.ts +0 -29
- package/dist/types/chat.d.ts.map +0 -1
- package/dist/types/chat.js +0 -1
- package/dist/types/chat.js.map +0 -1
- package/dist/types/message-content.d.ts +0 -38
- package/dist/types/message-content.d.ts.map +0 -1
- package/dist/types/message-content.js +0 -1
- package/dist/types/message-content.js.map +0 -1
- package/dist/ui/open-code-theme.d.ts +0 -58
- package/dist/ui/open-code-theme.d.ts.map +0 -1
- package/dist/ui/open-code-theme.js +0 -113
- package/dist/ui/open-code-theme.js.map +0 -1
- package/dist/ui/opencode-markdown.d.ts +0 -7
- package/dist/ui/opencode-markdown.d.ts.map +0 -1
- package/dist/ui/opencode-markdown.js +0 -169
- package/dist/ui/opencode-markdown.js.map +0 -1
- package/dist/ui/theme.d.ts +0 -68
- package/dist/ui/theme.d.ts.map +0 -1
- package/dist/ui/theme.js +0 -80
- package/dist/ui/theme.js.map +0 -1
- package/dist/utils/time.d.ts +0 -2
- package/dist/utils/time.d.ts.map +0 -1
- package/dist/utils/time.js +0 -7
- package/dist/utils/time.js.map +0 -1
|
@@ -1,695 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { uiTheme } from '../../ui/theme.js';
|
|
4
|
-
import { getToolDisplayIcon, getToolDisplayName } from '../tool-display-config.js';
|
|
5
|
-
import { CodeBlock } from './code-block.js';
|
|
6
|
-
const COLLAPSIBLE_OUTPUT_LINES = 16;
|
|
7
|
-
const COLLAPSIBLE_OUTPUT_LABELS = new Set(['output', 'error', 'result', 'details']);
|
|
8
|
-
const asObjectLike = (value) => {
|
|
9
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
return value;
|
|
13
|
-
};
|
|
14
|
-
const parseToolArgumentsObject = (raw) => {
|
|
15
|
-
if (!raw) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
return asObjectLike(JSON.parse(raw));
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const parseToolUseFromData = (value) => {
|
|
26
|
-
const toolCall = asObjectLike(value);
|
|
27
|
-
const toolFunction = asObjectLike(toolCall?.function);
|
|
28
|
-
if (!toolFunction) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const name = typeof toolFunction.name === 'string' ? toolFunction.name : undefined;
|
|
32
|
-
const callId = typeof toolCall?.id === 'string' ? toolCall.id : undefined;
|
|
33
|
-
if (!name || !callId) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
const rawArguments = typeof toolFunction.arguments === 'string' ? toolFunction.arguments : undefined;
|
|
37
|
-
const args = parseToolArgumentsObject(rawArguments);
|
|
38
|
-
const command = name === 'bash' && typeof args?.command === 'string' ? args.command : undefined;
|
|
39
|
-
return {
|
|
40
|
-
name,
|
|
41
|
-
callId,
|
|
42
|
-
command,
|
|
43
|
-
details: rawArguments,
|
|
44
|
-
args,
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
const parseToolUse = (content, data) => {
|
|
48
|
-
const structured = parseToolUseFromData(data);
|
|
49
|
-
if (structured) {
|
|
50
|
-
return structured;
|
|
51
|
-
}
|
|
52
|
-
if (!content) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
const lines = content.split('\n');
|
|
56
|
-
const header = lines[0]?.trim();
|
|
57
|
-
if (!header) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const match = header.match(/^# Tool:\s+(.+?)\s+\(([^)]+)\)$/);
|
|
61
|
-
if (!match || !match[1] || !match[2]) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const [_, name, callId] = match;
|
|
65
|
-
const bodyLines = lines.slice(1);
|
|
66
|
-
const commandLine = bodyLines.find(line => line.trim().startsWith('$ '));
|
|
67
|
-
const command = commandLine ? commandLine.trim().slice(2).trim() : undefined;
|
|
68
|
-
const details = bodyLines
|
|
69
|
-
.filter(line => !line.trim().startsWith('$ '))
|
|
70
|
-
.join('\n')
|
|
71
|
-
.trim();
|
|
72
|
-
return {
|
|
73
|
-
name,
|
|
74
|
-
callId,
|
|
75
|
-
command: command || undefined,
|
|
76
|
-
details: details || undefined,
|
|
77
|
-
args: parseJsonObject(details),
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
const parseToolResultFromData = (value) => {
|
|
81
|
-
const event = asObjectLike(value);
|
|
82
|
-
const toolCall = asObjectLike(event?.toolCall);
|
|
83
|
-
const toolFunction = asObjectLike(toolCall?.function);
|
|
84
|
-
const result = asObjectLike(event?.result);
|
|
85
|
-
const data = asObjectLike(result?.data);
|
|
86
|
-
const name = typeof toolFunction?.name === 'string' ? toolFunction.name : undefined;
|
|
87
|
-
const callId = typeof toolCall?.id === 'string' ? toolCall.id : undefined;
|
|
88
|
-
if (!name || !callId) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
const successValue = result?.success;
|
|
92
|
-
const status = successValue === true ? 'success' : successValue === false ? 'error' : 'unknown';
|
|
93
|
-
const summary = typeof data?.summary === 'string' ? data.summary : undefined;
|
|
94
|
-
const output = typeof data?.output === 'string' ? data.output : undefined;
|
|
95
|
-
const error = typeof result?.error === 'string' ? result.error : undefined;
|
|
96
|
-
return {
|
|
97
|
-
name,
|
|
98
|
-
callId,
|
|
99
|
-
status,
|
|
100
|
-
details: output || summary || error,
|
|
101
|
-
summary,
|
|
102
|
-
output,
|
|
103
|
-
payload: data?.payload,
|
|
104
|
-
metadata: data?.metadata,
|
|
105
|
-
error,
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
const parseToolResult = (content, data) => {
|
|
109
|
-
const structured = parseToolResultFromData(data);
|
|
110
|
-
if (structured) {
|
|
111
|
-
return structured;
|
|
112
|
-
}
|
|
113
|
-
if (!content) {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
const lines = content.split('\n');
|
|
117
|
-
const header = lines[0]?.trim();
|
|
118
|
-
if (!header) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const match = header.match(/^# Result:\s+(.+?)\s+\(([^)]+)\)\s+(success|error)$/);
|
|
122
|
-
if (!match || !match[1] || !match[2] || !match[3]) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
const [_, name, callId, status] = match;
|
|
126
|
-
const details = lines.slice(1).join('\n').trim();
|
|
127
|
-
return {
|
|
128
|
-
name,
|
|
129
|
-
callId,
|
|
130
|
-
status: status === 'success' || status === 'error' ? status : 'unknown',
|
|
131
|
-
details: details || undefined,
|
|
132
|
-
...(status === 'error' ? { error: details || undefined } : {}),
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
const resolveToolIcon = (toolName) => {
|
|
136
|
-
return getToolDisplayIcon(toolName);
|
|
137
|
-
};
|
|
138
|
-
const mergeOutputLines = (group, parsedResult) => {
|
|
139
|
-
const streamText = group.streams
|
|
140
|
-
.map(segment => segment.content)
|
|
141
|
-
.join('')
|
|
142
|
-
.trim();
|
|
143
|
-
const resultText = parsedResult?.output?.trim() || parsedResult?.details?.trim();
|
|
144
|
-
if (streamText && resultText && streamText === resultText) {
|
|
145
|
-
return streamText;
|
|
146
|
-
}
|
|
147
|
-
if (streamText && resultText) {
|
|
148
|
-
return `${streamText}\n${resultText}`;
|
|
149
|
-
}
|
|
150
|
-
return streamText || resultText || parsedResult?.summary?.trim() || '';
|
|
151
|
-
};
|
|
152
|
-
const readObject = (value) => {
|
|
153
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
return value;
|
|
157
|
-
};
|
|
158
|
-
const readArray = (value) => {
|
|
159
|
-
return Array.isArray(value) ? value : [];
|
|
160
|
-
};
|
|
161
|
-
const readString = (value) => {
|
|
162
|
-
return typeof value === 'string' ? value : undefined;
|
|
163
|
-
};
|
|
164
|
-
const readNumber = (value) => {
|
|
165
|
-
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
166
|
-
};
|
|
167
|
-
const readBoolean = (value) => {
|
|
168
|
-
return typeof value === 'boolean' ? value : undefined;
|
|
169
|
-
};
|
|
170
|
-
const parseJsonObject = (content) => {
|
|
171
|
-
if (!content) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
try {
|
|
175
|
-
return readObject(JSON.parse(content));
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
const parseJsonValue = (content) => {
|
|
182
|
-
if (!content) {
|
|
183
|
-
return undefined;
|
|
184
|
-
}
|
|
185
|
-
try {
|
|
186
|
-
return JSON.parse(content);
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
return undefined;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
const countEscapeMarkers = (value) => {
|
|
193
|
-
return (value.match(/\\r\\n|\\n|\\t|\\"|\\\\/g) ?? []).length;
|
|
194
|
-
};
|
|
195
|
-
const decodeEscapeSequencesOnce = (value) => {
|
|
196
|
-
return value
|
|
197
|
-
.replace(/\\r\\n/g, '\n')
|
|
198
|
-
.replace(/\\n/g, '\n')
|
|
199
|
-
.replace(/\\t/g, '\t')
|
|
200
|
-
.replace(/\\"/g, '"')
|
|
201
|
-
.replace(/\\\\/g, '\\');
|
|
202
|
-
};
|
|
203
|
-
const normalizeToolDisplayText = (value) => {
|
|
204
|
-
let current = value.replace(/\r\n/g, '\n').trimEnd();
|
|
205
|
-
for (let index = 0; index < 2; index += 1) {
|
|
206
|
-
const next = decodeEscapeSequencesOnce(current);
|
|
207
|
-
if (countEscapeMarkers(next) >= countEscapeMarkers(current)) {
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
current = next;
|
|
211
|
-
}
|
|
212
|
-
const parsed = parseJsonValue(current);
|
|
213
|
-
if (parsed !== undefined && typeof parsed !== 'string') {
|
|
214
|
-
try {
|
|
215
|
-
return JSON.stringify(parsed, null, 2);
|
|
216
|
-
}
|
|
217
|
-
catch {
|
|
218
|
-
return current;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return current;
|
|
222
|
-
};
|
|
223
|
-
const resolveSectionLanguageHint = (toolName, section) => {
|
|
224
|
-
if (section.tone !== 'code') {
|
|
225
|
-
return undefined;
|
|
226
|
-
}
|
|
227
|
-
if (section.label === 'command') {
|
|
228
|
-
return toolName === 'bash' ? 'bash' : undefined;
|
|
229
|
-
}
|
|
230
|
-
if (section.label === 'arguments') {
|
|
231
|
-
return 'json';
|
|
232
|
-
}
|
|
233
|
-
return undefined;
|
|
234
|
-
};
|
|
235
|
-
const isCollapsibleResultSection = (section) => {
|
|
236
|
-
if (section.tone !== 'code') {
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
if (!section.label) {
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
return COLLAPSIBLE_OUTPUT_LABELS.has(section.label.toLowerCase());
|
|
243
|
-
};
|
|
244
|
-
const resolveStructuredResultObject = (result) => {
|
|
245
|
-
return (readObject(result?.payload) ?? readObject(result?.metadata) ?? parseJsonObject(result?.details));
|
|
246
|
-
};
|
|
247
|
-
const formatToolName = (toolName) => {
|
|
248
|
-
return getToolDisplayName(toolName);
|
|
249
|
-
};
|
|
250
|
-
const truncate = (value, maxLength = 88) => {
|
|
251
|
-
const normalized = value.trim().replace(/\s+/g, ' ');
|
|
252
|
-
if (normalized.length <= maxLength) {
|
|
253
|
-
return normalized;
|
|
254
|
-
}
|
|
255
|
-
return `${normalized.slice(0, maxLength - 1)}…`;
|
|
256
|
-
};
|
|
257
|
-
const compactDetail = (value, maxLength = 72) => {
|
|
258
|
-
if (!value) {
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
const normalized = value.trim().replace(/\s+/g, ' ');
|
|
262
|
-
if (!normalized) {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
return truncate(normalized, maxLength);
|
|
266
|
-
};
|
|
267
|
-
const formatStatusLabel = (status) => {
|
|
268
|
-
if (!status) {
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
return status.replace(/_/g, ' ');
|
|
272
|
-
};
|
|
273
|
-
const formatTaskStatusIcon = (status) => {
|
|
274
|
-
switch (status) {
|
|
275
|
-
case 'completed':
|
|
276
|
-
return '●';
|
|
277
|
-
case 'in_progress':
|
|
278
|
-
case 'running':
|
|
279
|
-
return '◐';
|
|
280
|
-
case 'pending':
|
|
281
|
-
case 'queued':
|
|
282
|
-
return '○';
|
|
283
|
-
case 'cancelled':
|
|
284
|
-
return '⊘';
|
|
285
|
-
case 'failed':
|
|
286
|
-
case 'timed_out':
|
|
287
|
-
return '×';
|
|
288
|
-
case 'paused':
|
|
289
|
-
return '⏸';
|
|
290
|
-
default:
|
|
291
|
-
return '•';
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
const formatSummaryMeta = (parts) => {
|
|
295
|
-
const filtered = parts.map(part => part?.trim()).filter((part) => Boolean(part));
|
|
296
|
-
return filtered.length > 0 ? filtered.join(' · ') : null;
|
|
297
|
-
};
|
|
298
|
-
const summarizeTaskRecord = (task, options) => {
|
|
299
|
-
const subject = readString(task.subject) ?? readString(task.activeForm) ?? readString(task.id) ?? 'task';
|
|
300
|
-
const id = readString(task.id);
|
|
301
|
-
const status = readString(task.status);
|
|
302
|
-
const priority = readString(task.priority);
|
|
303
|
-
const progress = readNumber(task.effective_progress) ?? readNumber(task.progress);
|
|
304
|
-
const owner = readString(task.owner);
|
|
305
|
-
const blockers = readArray(task.blockers).length || readArray(task.blocked_by).length;
|
|
306
|
-
const blocks = readArray(task.blocked_tasks).length || readArray(task.blocks).length;
|
|
307
|
-
const lines = [`${formatTaskStatusIcon(status)} ${truncate(subject)}`];
|
|
308
|
-
const meta = formatSummaryMeta([
|
|
309
|
-
id,
|
|
310
|
-
formatStatusLabel(status),
|
|
311
|
-
priority,
|
|
312
|
-
progress !== undefined ? `${Math.round(progress)}%` : null,
|
|
313
|
-
owner ? `owner ${owner}` : null,
|
|
314
|
-
blockers > 0 ? `${blockers} blocker${blockers === 1 ? '' : 's'}` : null,
|
|
315
|
-
blocks > 0 ? `blocks ${blocks}` : null,
|
|
316
|
-
]);
|
|
317
|
-
if (meta) {
|
|
318
|
-
lines.push(meta);
|
|
319
|
-
}
|
|
320
|
-
const canStart = options?.canStart;
|
|
321
|
-
if (canStart && readBoolean(canStart.canStart) === false) {
|
|
322
|
-
const reason = readString(canStart.reason);
|
|
323
|
-
if (reason) {
|
|
324
|
-
lines.push(`blocked: ${truncate(reason, 96)}`);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return lines;
|
|
328
|
-
};
|
|
329
|
-
const summarizeAgentRun = (run, extras) => {
|
|
330
|
-
const agentId = readString(run.agentId);
|
|
331
|
-
const status = readString(run.status);
|
|
332
|
-
const subagentType = readString(run.subagentType);
|
|
333
|
-
const description = readString(run.description);
|
|
334
|
-
const linkedTaskId = readString(run.linkedTaskId);
|
|
335
|
-
const progress = readNumber(run.progress);
|
|
336
|
-
const error = readString(run.error);
|
|
337
|
-
const output = readString(run.output);
|
|
338
|
-
const headline = description ?? agentId ?? 'agent run';
|
|
339
|
-
const lines = [`${formatTaskStatusIcon(status)} ${truncate(headline)}`];
|
|
340
|
-
const meta = formatSummaryMeta([
|
|
341
|
-
agentId,
|
|
342
|
-
formatStatusLabel(status),
|
|
343
|
-
subagentType,
|
|
344
|
-
progress !== undefined ? `${Math.round(progress)}%` : null,
|
|
345
|
-
linkedTaskId ? `task ${linkedTaskId}` : null,
|
|
346
|
-
readBoolean(extras?.completed) === false ? 'still running' : null,
|
|
347
|
-
readBoolean(extras?.timeout_hit) === true ? 'timeout hit' : null,
|
|
348
|
-
readNumber(extras?.waited_ms) !== undefined
|
|
349
|
-
? `${Math.round((readNumber(extras?.waited_ms) ?? 0) / 1000)}s waited`
|
|
350
|
-
: null,
|
|
351
|
-
]);
|
|
352
|
-
if (meta) {
|
|
353
|
-
lines.push(meta);
|
|
354
|
-
}
|
|
355
|
-
if (error && !output) {
|
|
356
|
-
lines.push(`error: ${truncate(error, 96)}`);
|
|
357
|
-
}
|
|
358
|
-
return {
|
|
359
|
-
lines,
|
|
360
|
-
output: output?.trim() ? output : undefined,
|
|
361
|
-
};
|
|
362
|
-
};
|
|
363
|
-
const buildTaskHeaderDetail = (toolName, args) => {
|
|
364
|
-
if (!args) {
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
if (toolName === 'task_create') {
|
|
368
|
-
const subject = readString(args.subject);
|
|
369
|
-
return formatSummaryMeta([
|
|
370
|
-
subject ? `create ${truncate(subject, 56)}` : null,
|
|
371
|
-
readString(args.namespace),
|
|
372
|
-
readString(args.priority),
|
|
373
|
-
readArray(args.checkpoints).length > 0
|
|
374
|
-
? `${readArray(args.checkpoints).length} checkpoints`
|
|
375
|
-
: null,
|
|
376
|
-
]);
|
|
377
|
-
}
|
|
378
|
-
if (toolName === 'task_get') {
|
|
379
|
-
return formatSummaryMeta([
|
|
380
|
-
`inspect ${readString(args.task_id) ?? 'task'}`,
|
|
381
|
-
readBoolean(args.include_history) ? 'include history' : null,
|
|
382
|
-
]);
|
|
383
|
-
}
|
|
384
|
-
if (toolName === 'task_list') {
|
|
385
|
-
const statuses = readArray(args.statuses)
|
|
386
|
-
.map(value => readString(value))
|
|
387
|
-
.filter(Boolean)
|
|
388
|
-
.join(', ');
|
|
389
|
-
return formatSummaryMeta([
|
|
390
|
-
`list${readString(args.namespace) ? ` in ${readString(args.namespace)}` : ''}`,
|
|
391
|
-
statuses ? `status ${statuses}` : null,
|
|
392
|
-
readString(args.owner) ? `owner ${readString(args.owner)}` : null,
|
|
393
|
-
readString(args.tag) ? `tag ${readString(args.tag)}` : null,
|
|
394
|
-
]);
|
|
395
|
-
}
|
|
396
|
-
if (toolName === 'task_update') {
|
|
397
|
-
const changes = [`update ${readString(args.task_id) ?? 'task'}`];
|
|
398
|
-
if (readString(args.status))
|
|
399
|
-
changes.push(`status -> ${readString(args.status)?.replace(/_/g, ' ')}`);
|
|
400
|
-
if (readNumber(args.progress) !== undefined)
|
|
401
|
-
changes.push(`progress ${Math.round(readNumber(args.progress) ?? 0)}%`);
|
|
402
|
-
if (readString(args.owner))
|
|
403
|
-
changes.push(`owner ${readString(args.owner)}`);
|
|
404
|
-
if (readArray(args.add_blocked_by).length > 0)
|
|
405
|
-
changes.push(`+${readArray(args.add_blocked_by).length} blockers`);
|
|
406
|
-
if (readArray(args.remove_blocked_by).length > 0)
|
|
407
|
-
changes.push(`-${readArray(args.remove_blocked_by).length} blockers`);
|
|
408
|
-
return changes.join(' · ');
|
|
409
|
-
}
|
|
410
|
-
if (toolName === 'task_stop') {
|
|
411
|
-
return formatSummaryMeta([
|
|
412
|
-
`stop ${readString(args.task_id) ?? readString(args.agent_id) ?? 'agent run'}`,
|
|
413
|
-
readBoolean(args.cancel_linked_task) !== false ? 'cancel linked tasks' : null,
|
|
414
|
-
]);
|
|
415
|
-
}
|
|
416
|
-
if (toolName === 'task_output') {
|
|
417
|
-
return formatSummaryMeta([
|
|
418
|
-
`watch ${readString(args.task_id) ?? readString(args.agent_id) ?? 'agent run'}`,
|
|
419
|
-
readBoolean(args.block) === false ? 'non-blocking poll' : 'wait for completion',
|
|
420
|
-
]);
|
|
421
|
-
}
|
|
422
|
-
if (toolName === 'agent' || toolName === 'task') {
|
|
423
|
-
const prompt = readString(args.prompt);
|
|
424
|
-
const description = readString(args.description);
|
|
425
|
-
return formatSummaryMeta([
|
|
426
|
-
description ? truncate(description, 56) : prompt ? truncate(prompt, 56) : null,
|
|
427
|
-
readString(args.subagent_type),
|
|
428
|
-
readBoolean(args.run_in_background) ? 'background' : 'foreground',
|
|
429
|
-
readString(args.linked_task_id) ? `task ${readString(args.linked_task_id)}` : null,
|
|
430
|
-
]);
|
|
431
|
-
}
|
|
432
|
-
return null;
|
|
433
|
-
};
|
|
434
|
-
const buildTaskResultSections = (toolName, result) => {
|
|
435
|
-
const resultDetails = result?.details?.trim();
|
|
436
|
-
const summary = result?.summary?.trim();
|
|
437
|
-
if (!resultDetails && !summary && !result?.payload && !result?.metadata) {
|
|
438
|
-
return [];
|
|
439
|
-
}
|
|
440
|
-
if (result?.status === 'error') {
|
|
441
|
-
return [
|
|
442
|
-
{
|
|
443
|
-
label: 'result',
|
|
444
|
-
content: result?.error?.trim() || resultDetails || summary || 'task failed',
|
|
445
|
-
tone: 'body',
|
|
446
|
-
},
|
|
447
|
-
];
|
|
448
|
-
}
|
|
449
|
-
const payload = resolveStructuredResultObject(result);
|
|
450
|
-
if (!payload) {
|
|
451
|
-
return [
|
|
452
|
-
{
|
|
453
|
-
label: 'result',
|
|
454
|
-
content: resultDetails || summary || '',
|
|
455
|
-
tone: 'body',
|
|
456
|
-
},
|
|
457
|
-
];
|
|
458
|
-
}
|
|
459
|
-
if (toolName === 'task_list') {
|
|
460
|
-
const namespace = readString(payload.namespace) ?? 'default';
|
|
461
|
-
const tasks = readArray(payload.tasks)
|
|
462
|
-
.map(item => readObject(item))
|
|
463
|
-
.filter((item) => Boolean(item));
|
|
464
|
-
const total = readNumber(payload.total) ?? tasks.length;
|
|
465
|
-
const lines = [`${total} task${total === 1 ? '' : 's'} in ${namespace}`];
|
|
466
|
-
tasks.slice(0, 5).forEach(task => {
|
|
467
|
-
const summary = summarizeTaskRecord(task);
|
|
468
|
-
if (summary[0]) {
|
|
469
|
-
lines.push(summary[0]);
|
|
470
|
-
}
|
|
471
|
-
if (summary[1]) {
|
|
472
|
-
lines.push(` ${summary[1]}`);
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
if (tasks.length > 5) {
|
|
476
|
-
lines.push(`+${tasks.length - 5} more`);
|
|
477
|
-
}
|
|
478
|
-
return [{ label: 'result', content: lines.join('\n'), tone: 'body' }];
|
|
479
|
-
}
|
|
480
|
-
if (toolName === 'task_stop') {
|
|
481
|
-
const run = readObject(payload.agent_run);
|
|
482
|
-
const cancelledTaskIds = readArray(payload.cancelled_task_ids)
|
|
483
|
-
.map(item => readString(item))
|
|
484
|
-
.filter(Boolean);
|
|
485
|
-
const sections = [];
|
|
486
|
-
if (run) {
|
|
487
|
-
sections.push({
|
|
488
|
-
label: 'result',
|
|
489
|
-
content: summarizeAgentRun(run).lines.join('\n'),
|
|
490
|
-
tone: 'body',
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
if (cancelledTaskIds.length > 0) {
|
|
494
|
-
sections.push({
|
|
495
|
-
label: 'cancelled',
|
|
496
|
-
content: cancelledTaskIds.join(', '),
|
|
497
|
-
tone: 'body',
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
return sections;
|
|
501
|
-
}
|
|
502
|
-
if (toolName === 'task_output' || toolName === 'task' || toolName === 'agent') {
|
|
503
|
-
const run = readObject(payload.agent_run);
|
|
504
|
-
if (run) {
|
|
505
|
-
const summary = summarizeAgentRun(run, payload);
|
|
506
|
-
const sections = [
|
|
507
|
-
{
|
|
508
|
-
label: 'result',
|
|
509
|
-
content: summary.lines.join('\n'),
|
|
510
|
-
tone: 'body',
|
|
511
|
-
},
|
|
512
|
-
];
|
|
513
|
-
if (summary.output) {
|
|
514
|
-
sections.push({
|
|
515
|
-
label: 'output',
|
|
516
|
-
content: summary.output,
|
|
517
|
-
tone: 'body',
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
return sections;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
const task = readObject(payload.task);
|
|
524
|
-
if (task) {
|
|
525
|
-
const canStart = readObject(payload.can_start) ?? readObject(task.can_start);
|
|
526
|
-
return [
|
|
527
|
-
{
|
|
528
|
-
label: 'result',
|
|
529
|
-
content: summarizeTaskRecord(task, { canStart }).join('\n'),
|
|
530
|
-
tone: 'body',
|
|
531
|
-
},
|
|
532
|
-
];
|
|
533
|
-
}
|
|
534
|
-
return [
|
|
535
|
-
{
|
|
536
|
-
label: 'result',
|
|
537
|
-
content: resultDetails || summary || '',
|
|
538
|
-
tone: 'body',
|
|
539
|
-
},
|
|
540
|
-
];
|
|
541
|
-
};
|
|
542
|
-
const buildSearchHeaderDetail = (toolName, args) => {
|
|
543
|
-
if (!args) {
|
|
544
|
-
return null;
|
|
545
|
-
}
|
|
546
|
-
if (toolName === 'grep') {
|
|
547
|
-
const pattern = readString(args.pattern);
|
|
548
|
-
if (!pattern) {
|
|
549
|
-
return null;
|
|
550
|
-
}
|
|
551
|
-
return formatSummaryMeta([
|
|
552
|
-
JSON.stringify(pattern),
|
|
553
|
-
readString(args.path) ? `in ${readString(args.path)}` : null,
|
|
554
|
-
readString(args.glob) ? `glob ${readString(args.glob)}` : null,
|
|
555
|
-
readNumber(args.max_results) !== undefined
|
|
556
|
-
? `limit ${Math.round(readNumber(args.max_results) ?? 0)}`
|
|
557
|
-
: null,
|
|
558
|
-
readNumber(args.timeout_ms) !== undefined
|
|
559
|
-
? `${Math.round((readNumber(args.timeout_ms) ?? 0) / 1000)}s timeout`
|
|
560
|
-
: null,
|
|
561
|
-
]);
|
|
562
|
-
}
|
|
563
|
-
if (toolName === 'glob') {
|
|
564
|
-
const pattern = readString(args.pattern);
|
|
565
|
-
if (!pattern) {
|
|
566
|
-
return null;
|
|
567
|
-
}
|
|
568
|
-
return formatSummaryMeta([
|
|
569
|
-
pattern,
|
|
570
|
-
readString(args.path) ? `in ${readString(args.path)}` : null,
|
|
571
|
-
readBoolean(args.include_hidden) ? 'include hidden' : null,
|
|
572
|
-
readNumber(args.max_results) !== undefined
|
|
573
|
-
? `limit ${Math.round(readNumber(args.max_results) ?? 0)}`
|
|
574
|
-
: null,
|
|
575
|
-
]);
|
|
576
|
-
}
|
|
577
|
-
return null;
|
|
578
|
-
};
|
|
579
|
-
const buildSearchResultSections = (result) => {
|
|
580
|
-
const summary = result?.summary?.trim();
|
|
581
|
-
const output = result?.output?.trim() || result?.details?.trim();
|
|
582
|
-
const metadata = readObject(result?.metadata) ?? readObject(result?.payload);
|
|
583
|
-
if (!summary && !output && !metadata) {
|
|
584
|
-
return [];
|
|
585
|
-
}
|
|
586
|
-
if (metadata) {
|
|
587
|
-
const matchCount = readNumber(metadata.countMatches);
|
|
588
|
-
const fileCount = readNumber(metadata.countFiles);
|
|
589
|
-
const path = readString(metadata.path);
|
|
590
|
-
const flags = formatSummaryMeta([
|
|
591
|
-
matchCount !== undefined ? `${matchCount} matches` : null,
|
|
592
|
-
fileCount !== undefined ? `${fileCount} files` : null,
|
|
593
|
-
path ? `in ${path}` : null,
|
|
594
|
-
readBoolean(metadata.truncated) ? 'truncated' : null,
|
|
595
|
-
readBoolean(metadata.timed_out) ? 'timed out' : null,
|
|
596
|
-
]);
|
|
597
|
-
if (summary && output && summary !== output && flags) {
|
|
598
|
-
return [
|
|
599
|
-
{ label: 'result', content: summary, tone: 'body' },
|
|
600
|
-
{ label: 'details', content: `${flags}\n${output}`, tone: 'body' },
|
|
601
|
-
];
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
return [
|
|
605
|
-
{
|
|
606
|
-
label: 'result',
|
|
607
|
-
content: output || summary || '',
|
|
608
|
-
tone: 'body',
|
|
609
|
-
},
|
|
610
|
-
];
|
|
611
|
-
};
|
|
612
|
-
const buildSpecialToolPresentation = (toolName, parsedUse, parsedResult) => {
|
|
613
|
-
const args = parsedUse?.args ?? parseJsonObject(parsedUse?.details);
|
|
614
|
-
if (toolName === 'agent' || toolName === 'task' || toolName.startsWith('task_')) {
|
|
615
|
-
const sections = buildTaskResultSections(toolName, parsedResult);
|
|
616
|
-
return {
|
|
617
|
-
toolLabel: formatToolName(toolName),
|
|
618
|
-
headerDetail: buildTaskHeaderDetail(toolName, args) ?? undefined,
|
|
619
|
-
sections,
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
if (toolName === 'grep' || toolName === 'glob') {
|
|
623
|
-
const sections = buildSearchResultSections(parsedResult);
|
|
624
|
-
return {
|
|
625
|
-
toolLabel: formatToolName(toolName),
|
|
626
|
-
headerDetail: buildSearchHeaderDetail(toolName, args) ?? undefined,
|
|
627
|
-
sections,
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
return null;
|
|
631
|
-
};
|
|
632
|
-
export const AssistantToolGroup = ({ group }) => {
|
|
633
|
-
const [expandedSections, setExpandedSections] = useState({});
|
|
634
|
-
const parsedUse = parseToolUse(group.use?.content, group.use?.data);
|
|
635
|
-
const parsedResult = parseToolResult(group.result?.content, group.result?.data);
|
|
636
|
-
const toolName = parsedUse?.name ?? parsedResult?.name ?? 'tool';
|
|
637
|
-
const commandText = parsedUse?.command;
|
|
638
|
-
const invocationDetails = parsedUse?.details;
|
|
639
|
-
const icon = resolveToolIcon(toolName);
|
|
640
|
-
const outputText = mergeOutputLines(group, parsedResult);
|
|
641
|
-
const _hasInvocationDetails = Boolean(invocationDetails);
|
|
642
|
-
const hasOutput = outputText.length > 0;
|
|
643
|
-
const specialPresentation = buildSpecialToolPresentation(toolName, parsedUse, parsedResult);
|
|
644
|
-
const titleDetail = specialPresentation?.headerDetail ??
|
|
645
|
-
compactDetail(commandText, 64) ??
|
|
646
|
-
compactDetail(invocationDetails, 64);
|
|
647
|
-
const defaultSections = [];
|
|
648
|
-
if (commandText && !titleDetail) {
|
|
649
|
-
defaultSections.push({
|
|
650
|
-
label: 'command',
|
|
651
|
-
content: `$ ${commandText}`,
|
|
652
|
-
tone: 'code',
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
if (invocationDetails && !titleDetail) {
|
|
656
|
-
defaultSections.push({
|
|
657
|
-
label: 'arguments',
|
|
658
|
-
content: invocationDetails,
|
|
659
|
-
tone: 'code',
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
if (hasOutput) {
|
|
663
|
-
defaultSections.push({
|
|
664
|
-
label: parsedResult?.status === 'error' ? 'error' : 'output',
|
|
665
|
-
content: outputText,
|
|
666
|
-
tone: 'code',
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
const sections = specialPresentation?.sections ?? defaultSections;
|
|
670
|
-
const hasBody = sections.length > 0;
|
|
671
|
-
const statusText = parsedResult?.status === 'success'
|
|
672
|
-
? 'completed'
|
|
673
|
-
: parsedResult?.status === 'error'
|
|
674
|
-
? 'error'
|
|
675
|
-
: group.result
|
|
676
|
-
? 'finished'
|
|
677
|
-
: 'running';
|
|
678
|
-
return (_jsxs("box", { flexDirection: "column", children: [_jsx("box", { paddingLeft: 3, children: _jsxs("text", { fg: uiTheme.text, attributes: uiTheme.typography.note, wrapMode: "word", children: [_jsx("span", { fg: uiTheme.accent, children: icon }), ' ', specialPresentation?.toolLabel ?? formatToolName(toolName), titleDetail ? _jsxs("span", { fg: uiTheme.muted, children: ["(", titleDetail, ")"] }) : null, _jsxs("span", { fg: uiTheme.subtle, children: [" (", statusText, ")"] })] }) }), hasBody ? (_jsxs("box", { flexDirection: "row", marginTop: 1, children: [_jsx("box", { width: 1, backgroundColor: uiTheme.divider }), _jsx("box", { flexGrow: 1, backgroundColor: uiTheme.panel, paddingLeft: 2, paddingRight: 1, paddingTop: 1, paddingBottom: 1, children: sections.map((section, index) => {
|
|
679
|
-
const content = normalizeToolDisplayText(section.content);
|
|
680
|
-
const isCode = section.tone === 'code';
|
|
681
|
-
const sectionId = `${toolName}:section:${index}`;
|
|
682
|
-
const collapsible = isCollapsibleResultSection(section);
|
|
683
|
-
const expanded = Boolean(expandedSections[sectionId]);
|
|
684
|
-
return (_jsxs("box", { flexDirection: "column", paddingBottom: index < sections.length - 1 ? 1 : 0, children: [section.label ? (isCode ? null : (_jsx("text", { fg: uiTheme.muted, attributes: uiTheme.typography.note, children: section.label }))) : null, isCode ? (_jsx("box", { children: _jsx(CodeBlock, { content: content, label: section.label, languageHint: resolveSectionLanguageHint(toolName, section), collapsible: collapsible, collapsedLines: COLLAPSIBLE_OUTPUT_LINES, expanded: expanded, onToggleExpanded: () => {
|
|
685
|
-
if (!collapsible) {
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
setExpandedSections(previous => ({
|
|
689
|
-
...previous,
|
|
690
|
-
[sectionId]: !previous[sectionId],
|
|
691
|
-
}));
|
|
692
|
-
} }) })) : (_jsx("box", { marginTop: section.label ? 1 : 0, children: _jsx("text", { fg: uiTheme.text, attributes: uiTheme.typography.body, wrapMode: "word", children: content }) }))] }, sectionId));
|
|
693
|
-
}) })] })) : null] }));
|
|
694
|
-
};
|
|
695
|
-
//# sourceMappingURL=assistant-tool-group.js.map
|