-
Notifications
You must be signed in to change notification settings - Fork 147
feat: add BashToolViewer, collapsible output, and expanded syntax highlighting #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/renderer/components/chat/items/linkedTool/BashToolViewer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /** | ||
| * BashToolViewer | ||
| * | ||
| * Renders Bash tool calls with a clean command display with copy button, | ||
| * and collapsible output section. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import { CopyButton } from '@renderer/components/common/CopyButton'; | ||
| import { COLOR_TEXT, COLOR_TEXT_MUTED } from '@renderer/constants/cssVariables'; | ||
|
|
||
| import { type ItemStatus } from '../BaseItem'; | ||
|
|
||
| import { CollapsibleOutputSection } from './CollapsibleOutputSection'; | ||
| import { extractOutputText, renderOutput } from './renderHelpers'; | ||
|
|
||
| import type { LinkedToolItem } from '@renderer/types/groups'; | ||
|
|
||
| interface BashToolViewerProps { | ||
| linkedTool: LinkedToolItem; | ||
| status: ItemStatus; | ||
| } | ||
|
|
||
| export const BashToolViewer: React.FC<BashToolViewerProps> = ({ linkedTool, status }) => { | ||
| const command = (linkedTool.input.command as string) || ''; | ||
| const description = linkedTool.input.description as string | undefined; | ||
|
|
||
| // Extract output text for copy button | ||
| const outputText = | ||
| !linkedTool.isOrphaned && linkedTool.result | ||
| ? extractOutputText(linkedTool.result.content) | ||
| : ''; | ||
|
|
||
| return ( | ||
| <> | ||
| {/* Input Section — Command with copy button */} | ||
| <div> | ||
| <div className="mb-1 text-xs" style={{ color: 'var(--tool-item-muted)' }}> | ||
| Input | ||
| </div> | ||
| <div | ||
| className="group relative max-h-96 overflow-auto rounded p-3 font-mono text-xs" | ||
| style={{ | ||
| backgroundColor: 'var(--code-bg)', | ||
| border: '1px solid var(--code-border)', | ||
| }} | ||
| > | ||
| {description && ( | ||
| <div className="mb-2 text-xs" style={{ color: COLOR_TEXT_MUTED }}> | ||
| {description} | ||
| </div> | ||
| )} | ||
| <code className="whitespace-pre-wrap break-all" style={{ color: COLOR_TEXT }}> | ||
| {command} | ||
| </code> | ||
| <CopyButton text={command} /> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Output Section — Collapsible with copy button */} | ||
| {!linkedTool.isOrphaned && linkedTool.result && ( | ||
| <CollapsibleOutputSection status={status} copyText={outputText}> | ||
| {renderOutput(linkedTool.result.content)} | ||
| </CollapsibleOutputSection> | ||
| )} | ||
| </> | ||
| ); | ||
| }; |
68 changes: 68 additions & 0 deletions
68
src/renderer/components/chat/items/linkedTool/CollapsibleOutputSection.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /** | ||
| * CollapsibleOutputSection | ||
| * | ||
| * Reusable component that wraps tool output in a collapsed-by-default section. | ||
| * Shows a clickable header with label, StatusDot, and chevron toggle. | ||
| */ | ||
|
|
||
| import React, { useState } from 'react'; | ||
|
|
||
| import { CopyButton } from '@renderer/components/common/CopyButton'; | ||
| import { ChevronDown, ChevronRight } from 'lucide-react'; | ||
|
|
||
| import { type ItemStatus, StatusDot } from '../BaseItem'; | ||
|
|
||
| interface CollapsibleOutputSectionProps { | ||
| status: ItemStatus; | ||
| children: React.ReactNode; | ||
| /** Label shown in the header (default: "Output") */ | ||
| label?: string; | ||
| /** Text content for the copy button (when provided, shows a copy button) */ | ||
| copyText?: string; | ||
| } | ||
|
|
||
| export const CollapsibleOutputSection: React.FC<CollapsibleOutputSectionProps> = ({ | ||
| status, | ||
| children, | ||
| label = 'Output', | ||
| copyText, | ||
| }) => { | ||
| const [isExpanded, setIsExpanded] = useState(false); | ||
|
|
||
| return ( | ||
| <div> | ||
| <button | ||
| type="button" | ||
| className="mb-1 flex items-center gap-2 text-xs" | ||
| style={{ | ||
| color: 'var(--tool-item-muted)', | ||
| background: 'none', | ||
| border: 'none', | ||
| padding: 0, | ||
| cursor: 'pointer', | ||
| }} | ||
| onClick={() => setIsExpanded((prev) => !prev)} | ||
| > | ||
| {isExpanded ? <ChevronDown className="size-3" /> : <ChevronRight className="size-3" />} | ||
| {label} | ||
| <StatusDot status={status} /> | ||
| </button> | ||
| {isExpanded && ( | ||
| <div | ||
| className="group relative max-h-96 overflow-auto rounded p-3 font-mono text-xs" | ||
| style={{ | ||
| backgroundColor: 'var(--code-bg)', | ||
| border: '1px solid var(--code-border)', | ||
| color: | ||
| status === 'error' | ||
| ? 'var(--tool-result-error-text)' | ||
| : 'var(--color-text-secondary)', | ||
| }} | ||
| > | ||
| {children} | ||
| {copyText && <CopyButton text={copyText} />} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
|
|
||
| import React from 'react'; | ||
|
|
||
| import { CodeBlockViewer } from '@renderer/components/chat/viewers'; | ||
| import { CodeBlockViewer, MarkdownViewer } from '@renderer/components/chat/viewers'; | ||
|
|
||
| import type { LinkedToolItem } from '@renderer/types/groups'; | ||
|
|
||
|
|
@@ -54,12 +54,55 @@ export const ReadToolViewer: React.FC<ReadToolViewerProps> = ({ linkedTool }) => | |
| ? startLine + limit - 1 | ||
| : undefined; | ||
|
|
||
| const isMarkdownFile = /\.mdx?$/i.test(filePath); | ||
| const [viewMode, setViewMode] = React.useState<'code' | 'preview'>('code'); | ||
|
|
||
| React.useEffect(() => { | ||
| setViewMode(isMarkdownFile ? 'preview' : 'code'); | ||
| }, [isMarkdownFile]); | ||
|
|
||
| return ( | ||
| <CodeBlockViewer | ||
| fileName={filePath} | ||
| content={content} | ||
| startLine={startLine} | ||
| endLine={endLine} | ||
| /> | ||
| <div className="space-y-2"> | ||
| {isMarkdownFile && ( | ||
| <div className="flex items-center justify-end gap-1"> | ||
| <button | ||
| type="button" | ||
| onClick={() => setViewMode('code')} | ||
| aria-pressed={viewMode === 'code'} | ||
| className="rounded px-2 py-1 text-xs transition-colors" | ||
| style={{ | ||
| backgroundColor: viewMode === 'code' ? 'var(--tag-bg)' : 'transparent', | ||
| color: viewMode === 'code' ? 'var(--tag-text)' : 'var(--color-text-muted)', | ||
| border: '1px solid var(--tag-border)', | ||
|
Comment on lines
+73
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }} | ||
| > | ||
| Code | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => setViewMode('preview')} | ||
| aria-pressed={viewMode === 'preview'} | ||
| className="rounded px-2 py-1 text-xs transition-colors" | ||
| style={{ | ||
| backgroundColor: viewMode === 'preview' ? 'var(--tag-bg)' : 'transparent', | ||
| color: viewMode === 'preview' ? 'var(--tag-text)' : 'var(--color-text-muted)', | ||
| border: '1px solid var(--tag-border)', | ||
| }} | ||
|
Comment on lines
+87
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| > | ||
| Preview | ||
| </button> | ||
| </div> | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| )} | ||
| {isMarkdownFile && viewMode === 'preview' ? ( | ||
| <MarkdownViewer content={content} label="Markdown Preview" copyable /> | ||
| ) : ( | ||
| <CodeBlockViewer | ||
| fileName={filePath} | ||
| content={content} | ||
| startLine={startLine} | ||
| endLine={endLine} | ||
| /> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline styles for the button (e.g.,
color,background,border,padding,cursor) are static and could be moved to a CSS class. This would improve maintainability, promote consistency across components, and separate concerns between structure and styling. Consider defining these styles in a dedicated CSS module or using a utility-first CSS framework if available.