feat(walkthrough): open the change walkthrough from an agent tool call

This commit is contained in:
Chris Scott committed 2026-10-09 11:03:21 -04:00
1 parent 3eb0b02203
commit aa1da8d608
26 files changed
+1367 -175

No files matched your search

@@ -4,6 +4,7 @@ import type { SessionMessageAssistantTool } from '@opencode-manager/shared/openc
import { useSettings } from '@/hooks/useSettings'
import { useToolCallPermission } from '@/contexts/EventContext'
import { explorationLabel, isExplorationComplete } from '@/lib/explorationGroups'
import type { WalkthroughSource } from '@opencode-manager/shared/schemas'
import { MessagePart } from './MessagePart'
interface ExplorationGroupProps {
@@ -12,6 +13,7 @@ interface ExplorationGroupProps {
directory?: string
onFileClick?: (filePath: string, lineNumber?: number) => void
onChildSessionClick?: (sessionId: string) => void
onOpenWalkthrough?: (source?: WalkthroughSource) => void
}
type MemberProps = Omit<ExplorationGroupProps, 'parts'> & { part: SessionMessageAssistantTool }
@@ -4,6 +4,7 @@ import { TextPart } from './TextPart'
import { ToolCallPart } from './ToolCallPart'
import { useSettings } from '@/hooks/useSettings'
import type { ShellNoticeOutcome } from '@/lib/backgroundWork'
import type { WalkthroughSource } from '@opencode-manager/shared/schemas'
type AssistantContentPart = SessionMessageAssistant['content'][number]
@@ -14,9 +15,10 @@ interface MessagePartProps {
shellOutcome?: ShellNoticeOutcome
onFileClick?: (filePath: string, lineNumber?: number) => void
onChildSessionClick?: (sessionId: string) => void
onOpenWalkthrough?: (source?: WalkthroughSource) => void
}
export const MessagePart = memo(function MessagePart({ part, messageID, directory, shellOutcome, onFileClick, onChildSessionClick }: MessagePartProps) {
export const MessagePart = memo(function MessagePart({ part, messageID, directory, shellOutcome, onFileClick, onChildSessionClick, onOpenWalkthrough }: MessagePartProps) {
const { preferences } = useSettings()
const simpleChatMode = preferences?.simpleChatMode ?? false
const showReasoning = preferences?.showReasoning ?? false
@@ -47,6 +49,7 @@ export const MessagePart = memo(function MessagePart({ part, messageID, director
shellOutcome={shellOutcome}
onFileClick={onFileClick}
onChildSessionClick={onChildSessionClick}
onOpenWalkthrough={onOpenWalkthrough}
/>
)
default:
@@ -24,6 +24,7 @@ import { CopyButton } from '@/components/ui/copy-button'
import { TTSButton } from '@/components/ui/tts-button'
import { backgroundShellID, collectBackgroundParts, type ShellNoticeOutcome } from '@/lib/backgroundWork'
import { groupExplorationParts, type AssistantContentItem } from '@/lib/explorationGroups'
import type { WalkthroughSource } from '@opencode-manager/shared/schemas'
import { ExplorationGroup } from './ExplorationGroup'
function getMessageText(message: SessionMessageInfo): string {
@@ -324,6 +325,7 @@ interface MessageRowProps {
directory?: string
onFileClick?: (filePath: string, lineNumber?: number) => void
onChildSessionClick?: (sessionId: string) => void
onOpenWalkthrough?: (source?: WalkthroughSource) => void
model?: string
simpleChatMode: boolean
showReasoning: boolean
@@ -344,6 +346,7 @@ const MessageRow = memo(function MessageRow({
directory,
onFileClick,
onChildSessionClick,
onOpenWalkthrough,
model,
simpleChatMode,
showReasoning,
@@ -452,6 +455,7 @@ const MessageRow = memo(function MessageRow({
shellOutcome={shellOutcomeFor(part)}
onFileClick={onFileClick}
onChildSessionClick={onChildSessionClick}
onOpenWalkthrough={onOpenWalkthrough}
/>
</div>
))}
@@ -494,6 +498,7 @@ const MessageRow = memo(function MessageRow({
directory={directory}
onFileClick={onFileClick}
onChildSessionClick={onChildSessionClick}
onOpenWalkthrough={onOpenWalkthrough}
/>
) : (
<MessagePart
@@ -503,6 +508,7 @@ const MessageRow = memo(function MessageRow({
shellOutcome={shellOutcomeFor(item.part)}
onFileClick={onFileClick}
onChildSessionClick={onChildSessionClick}
onOpenWalkthrough={onOpenWalkthrough}
/>
)}
</div>
@@ -570,6 +576,7 @@ interface MessageThreadProps {
pending: SessionInboxInfo[]
onFileClick?: (filePath: string, lineNumber?: number) => void
onChildSessionClick?: (sessionId: string) => void
onOpenWalkthrough?: (source?: WalkthroughSource) => void
onUndoMessage?: (restoredPrompt: string) => void
model?: string
isSessionBusy?: boolean
@@ -582,6 +589,7 @@ export const MessageThread = memo(function MessageThread({
pending,
onFileClick,
onChildSessionClick,
onOpenWalkthrough,
onUndoMessage,
model,
isSessionBusy = false,
@@ -649,6 +657,7 @@ export const MessageThread = memo(function MessageThread({
directory={directory}
onFileClick={onFileClick}
onChildSessionClick={onChildSessionClick}
onOpenWalkthrough={onOpenWalkthrough}
model={model}
simpleChatMode={simpleChatMode}
showReasoning={showReasoning}
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { act, render, screen, waitFor } from '@testing-library/react'
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { MemoryRouter } from 'react-router-dom'
import type { PermissionRequest, SessionMessageAssistantTool } from '@opencode-manager/shared/opencode'
@@ -265,3 +265,119 @@ describe('ToolCallPart background indicator', () => {
expect(screen.queryByText('background')).not.toBeInTheDocument()
})
})
describe('ToolCallPart open walkthrough action', () => {
beforeEach(() => {
vi.clearAllMocks()
mocks.useSettings.mockReturnValue({
preferences: { expandToolCalls: false },
isLoading: false,
updateSettings: vi.fn(),
isUpdating: false,
})
mocks.useToolCallPermission.mockReturnValue(null)
})
const openWalkthrough = (status: 'running' | 'completed'): SessionMessageAssistantTool => ({
type: 'tool',
id: 'call_ocm',
name: 'ocm',
time: status === 'completed' ? { created: 1, ran: 2, completed: 3 } : { created: 1, ran: 2 },
state:
status === 'completed'
? {
status: 'completed',
input: { action: 'open_walkthrough', params: {} },
content: [{ type: 'text', text: 'Walkthrough opened' }],
}
: {
status: 'running',
input: { action: 'open_walkthrough', params: {} },
metadata: {},
},
})
it('renders an Open walkthrough button and calls the opener', () => {
const onOpenWalkthrough = vi.fn()
renderWithProviders(
<ToolCallPart part={openWalkthrough('completed')} messageID="msg_1" onOpenWalkthrough={onOpenWalkthrough} />,
)
fireEvent.click(screen.getByRole('button', { name: 'Open walkthrough' }))
expect(onOpenWalkthrough).toHaveBeenCalledTimes(1)
})
it('passes the requested source to the opener', () => {
const onOpenWalkthrough = vi.fn()
const part: SessionMessageAssistantTool = {
type: 'tool',
id: 'call_ocm',
name: 'ocm',
time: { created: 1, ran: 2, completed: 3 },
state: {
status: 'completed',
input: { action: 'open_walkthrough', params: { source: { kind: 'staged' } } },
content: [{ type: 'text', text: 'Walkthrough opened' }],
},
}
renderWithProviders(
<ToolCallPart part={part} messageID="msg_1" onOpenWalkthrough={onOpenWalkthrough} />,
)
fireEvent.click(screen.getByRole('button', { name: 'Open walkthrough' }))
expect(onOpenWalkthrough).toHaveBeenCalledWith({ kind: 'staged' })
})
it('passes no source when the call invalidates one', () => {
const onOpenWalkthrough = vi.fn()
const part: SessionMessageAssistantTool = {
type: 'tool',
id: 'call_ocm',
name: 'ocm',
time: { created: 1, ran: 2, completed: 3 },
state: {
status: 'completed',
input: { action: 'open_walkthrough', params: { source: { kind: 'nonsense' } } },
content: [{ type: 'text', text: 'Walkthrough opened' }],
},
}
renderWithProviders(
<ToolCallPart part={part} messageID="msg_1" onOpenWalkthrough={onOpenWalkthrough} />,
)
fireEvent.click(screen.getByRole('button', { name: 'Open walkthrough' }))
expect(onOpenWalkthrough).toHaveBeenCalledWith(undefined)
})
it('does not render the button while the call is still running', () => {
renderWithProviders(
<ToolCallPart part={openWalkthrough('running')} messageID="msg_1" onOpenWalkthrough={vi.fn()} />,
)
expect(screen.queryByRole('button', { name: 'Open walkthrough' })).not.toBeInTheDocument()
})
it('does not render the button for another ocm action', () => {
const otherAction: SessionMessageAssistantTool = {
type: 'tool',
id: 'call_ocm',
name: 'ocm',
time: { created: 1, ran: 2, completed: 3 },
state: {
status: 'completed',
input: { action: 'something_else' },
content: [{ type: 'text', text: 'ok' }],
},
}
renderWithProviders(<ToolCallPart part={otherAction} messageID="msg_1" onOpenWalkthrough={vi.fn()} />)
expect(screen.queryByRole('button', { name: 'Open walkthrough' })).not.toBeInTheDocument()
})
})
@@ -10,6 +10,7 @@ import { useShell } from '@/hooks/useSessionShells'
import { detectFileReferences } from '@/lib/fileReferences'
import { ExternalLink, Loader2, Shield } from 'lucide-react'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { CopyButton } from '@/components/ui/copy-button'
import { BackgroundTaskStatusIcon } from '@/components/session/BackgroundTaskStatusIcon'
import {
@@ -26,6 +27,8 @@ import {
type ShellNoticeOutcome,
} from '@/lib/backgroundWork'
import { getToolInputPath, getToolSpecificRender } from './FileToolRender'
import { readOpenWalkthroughCall } from '@/lib/walkthroughTool'
import type { WalkthroughSource } from '@opencode-manager/shared/schemas'
const DISPLAY_LIMIT = 30_000
const DISPLAY_HEAD_LENGTH = 20_000
@@ -61,6 +64,7 @@ interface ToolCallPartProps {
shellOutcome?: ShellNoticeOutcome
onFileClick?: (filePath: string, lineNumber?: number) => void
onChildSessionClick?: (sessionId: string) => void
onOpenWalkthrough?: (source?: WalkthroughSource) => void
}
function toolInput(part: SessionMessageAssistantTool): Record<string, unknown> | undefined {
@@ -113,7 +117,7 @@ function ClickableJson({ json, onFileClick }: { json: unknown; onFileClick?: (fi
return <pre className="bg-accent p-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-words">{parts}</pre>
}
export const ToolCallPart = memo(function ToolCallPart({ part, messageID, directory, shellOutcome, onFileClick, onChildSessionClick }: ToolCallPartProps) {
export const ToolCallPart = memo(function ToolCallPart({ part, messageID, directory, shellOutcome, onFileClick, onChildSessionClick, onOpenWalkthrough }: ToolCallPartProps) {
const { preferences } = useSettings()
const { userBashCommands } = useUserBash()
const isSubagent = part.name === 'subagent'
@@ -139,6 +143,7 @@ export const ToolCallPart = memo(function ToolCallPart({ part, messageID, direct
const isWaitingPermission = part.state.status === 'running' && pendingPermission !== null
const outputRef = useRef<HTMLDivElement>(null)
const input = toolInput(part)
const openWalkthrough = readOpenWalkthroughCall(part)
const rawCommand = part.name === 'shell' && typeof input?.command === 'string'
? input.command
: undefined
@@ -349,36 +354,49 @@ export const ToolCallPart = memo(function ToolCallPart({ part, messageID, direct
return (
<div ref={outputRef} className={`border rounded-lg overflow-hidden my-2 transition-all ${getBorderStyle()}`}>
<button
onClick={() => setExpanded(!expanded)}
className="w-full px-4 py-2 bg-card hover:bg-card-hover text-left flex items-center gap-2 text-sm min-w-0"
>
<span className={getStatusColor()}>{getStatusIcon()}</span>
<span className="font-medium">{part.name}</span>
{sandboxIndicator}
{backgroundIndicator}
<div className="flex items-center bg-card">
<button
onClick={() => setExpanded(!expanded)}
className="min-w-0 flex-1 px-4 py-2 hover:bg-card-hover text-left flex items-center gap-2 text-sm"
>
<span className={getStatusColor()}>{getStatusIcon()}</span>
<span className="font-medium">{part.name}</span>
{sandboxIndicator}
{backgroundIndicator}
{previewText && isFileTool ? (
<span
onClick={(e) => {
e.stopPropagation()
if (onFileClick && previewText) {
onFileClick(previewText)
}
}}
className="text-primary text-xs truncate hover:text-primary-hover cursor-pointer underline decoration-dotted"
title={`Click to open ${previewText}`}
>
{previewText}
{previewText && isFileTool ? (
<span
onClick={(e) => {
e.stopPropagation()
if (onFileClick && previewText) {
onFileClick(previewText)
}
}}
className="text-primary text-xs truncate hover:text-primary-hover cursor-pointer underline decoration-dotted"
title={`Click to open ${previewText}`}
>
{previewText}
</span>
) : previewText ? (
<span className="text-muted-foreground text-xs truncate">{previewText}</span>
) : null}
<span className="text-muted-foreground text-xs ml-auto">
{isWaitingPermission ? 'awaiting permission' : isBackgroundShell ? lifecycleLabel(shellStatus) : part.state.status}
</span>
) : previewText ? (
<span className="text-muted-foreground text-xs truncate">{previewText}</span>
) : null}
</button>
<span className="text-muted-foreground text-xs ml-auto">
{isWaitingPermission ? 'awaiting permission' : isBackgroundShell ? lifecycleLabel(shellStatus) : part.state.status}
</span>
</button>
{openWalkthrough ? (
<Button
variant="outline"
size="sm"
className="mr-2 h-7 shrink-0"
onClick={() => onOpenWalkthrough?.(openWalkthrough.source)}
>
Open walkthrough
</Button>
) : null}
</div>
{expanded && (
<div className="bg-card space-y-2 p-3">