Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 52 additions & 11 deletions src/renderer/components/WorkbenchControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,50 @@ export function Composer({
);
}

export const TOOL_TEXT_PREVIEW_LIMIT = 2000;

function ToolTextSection({ title, text }: { title: string; text: string }) {
const [showAll, setShowAll] = useState(false);
const [copied, setCopied] = useState(false);
const isLong = text.length > TOOL_TEXT_PREVIEW_LIMIT;
const visible =
isLong && !showAll ? text.slice(0, TOOL_TEXT_PREVIEW_LIMIT) : text;
const copy = async () => {
try {
await navigator.clipboard.writeText(text);
setCopied(true);
window.setTimeout(() => setCopied(false), 1500);
} catch {
setCopied(false);
}
};
return (
<div className="wb-tool-section">
<div className="wb-tool-section-head">
<h3>{title}</h3>
<button
type="button"
className="wb-tool-copy"
aria-label={`Copy ${title.toLowerCase()}`}
onClick={() => void copy()}
>
{copied ? 'Copied' : 'Copy'}
</button>
</div>
<pre>{visible}</pre>
{isLong && (
<button
type="button"
className="wb-tool-toggle"
onClick={() => setShowAll((value) => !value)}
>
{showAll ? 'Show less' : 'Show more'}
</button>
)}
</div>
);
}

export const TranscriptRow = memo(function TranscriptRow({
entry,
expanded,
Expand Down Expand Up @@ -310,17 +354,14 @@ export const TranscriptRow = memo(function TranscriptRow({
{entry.running ? 'Running' : entry.ok ? 'Done' : 'Failed'}
</small>
</summary>
<div className="wb-tool-section">
<h3>Input</h3>
<pre>{entry.input || 'No input.'}</pre>
</div>
<div className="wb-tool-section">
<h3>Output</h3>
<pre>
{entry.output ||
(entry.running ? 'Waiting for output…' : 'No output.')}
</pre>
</div>
<ToolTextSection title="Input" text={entry.input || 'No input.'} />
<ToolTextSection
title="Output"
text={
entry.output ||
(entry.running ? 'Waiting for output…' : 'No output.')
}
/>
</details>
);
return (
Expand Down
20 changes: 20 additions & 0 deletions src/renderer/workbench.css
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,26 @@ html[data-reduced-motion='true'] .wb-shell *::after {
text-transform: uppercase;
color: var(--muted);
}
.wb-tool-section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-right: 12px;
}
.wb-tool-copy,
.wb-tool-toggle {
border: 1px solid var(--line-soft);
background: transparent;
color: var(--copy);
font-size: 11px;
line-height: 16px;
padding: 2px 8px;
cursor: pointer;
}
.wb-tool-toggle {
margin: 0 12px 12px;
}
.wb-tool-section + .wb-tool-section {
border-top: 1px solid var(--line-soft);
}
Expand Down
41 changes: 39 additions & 2 deletions tests/integration/ToolCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it, beforeEach } from 'vitest';
import { render, cleanup } from '@testing-library/react';
import { describe, expect, it, beforeEach, vi } from 'vitest';
import { render, cleanup, fireEvent } from '@testing-library/react';
import { TranscriptRow } from '../../src/renderer/components/WorkbenchControls';
import type { Entry } from '../../src/renderer/timeline';

Expand Down Expand Up @@ -33,6 +33,43 @@ describe('<TranscriptRow> tool card', () => {
expect(container.textContent).toContain('Done');
});

it('copies the exact output text and shows Copied', async () => {
const writeText = vi.fn().mockResolvedValue(undefined);
Object.defineProperty(navigator, 'clipboard', {
value: { writeText },
configurable: true,
});
const expanded = new Map<string, boolean>([[toolEntry.key, true]]);
const { getByRole } = render(
<TranscriptRow entry={toolEntry} expanded={expanded} />,
);
fireEvent.click(getByRole('button', { name: 'Copy output' }));
expect(writeText).toHaveBeenCalledWith('Edited /repo/src/app.ts');
await vi.waitFor(() =>
expect(getByRole('button', { name: 'Copy output' }).textContent).toBe(
'Copied',
),
);
});

it('truncates long output and expands on Show more', () => {
const longOutput = `start-${'x'.repeat(2500)}-end-marker`;
const longEntry: Extract<Entry, { kind: 'tool' }> = {
...toolEntry,
key: 'tool-3',
output: longOutput,
};
const expanded = new Map<string, boolean>([[longEntry.key, true]]);
const { container, getByRole } = render(
<TranscriptRow entry={longEntry} expanded={expanded} />,
);
expect(container.textContent).not.toContain('end-marker');
fireEvent.click(getByRole('button', { name: 'Show more' }));
expect(container.textContent).toContain('end-marker');
fireEvent.click(getByRole('button', { name: 'Show less' }));
expect(container.textContent).not.toContain('end-marker');
});

it('shows running state and waiting output while a tool runs', () => {
const running: Extract<Entry, { kind: 'tool' }> = {
...toolEntry,
Expand Down
Loading