fix: complete subagent output and file workspace interactions

OpenCode child cards now show ordered text, reasoning and tool progress,
with the final result displayed separately. Local SDK and remote ACP paths
share child tracking, including progress retained across recovery and cancellation.
Remote live progress requires an Agent package containing the event plugin;
older Agent packages still expose final results without inventing missing history.

Knowledge-library rows remain clickable when native label activation changes
focus. File workspace changes use colored Git status letters and per-file
staged/unstaged diffs, including deleted, renamed and untracked files.
Refreshing reloads the selected diff and expanded directories, and more than
50 changes remain accessible through incremental loading.

Validated with 3552 passing tests, typecheck, lint, desktop build, current-source
Linux Host scenarios and isolated Windows desktop UI interactions.

Release note: 展开 OpenCode 子代理卡片可查看执行过程、工具详情与独立最终结果;知识库支持整行勾选。工作区支持单文件暂存与未暂存差异,刷新会更新当前差异,更多变更可继续加载。远端实时过程需要更新 GoodBuddy Agent。
This commit is contained in:
mesalogo
2026-09-06 22:13:45 +08:00
parent b03c25685c
commit d08ba33c3e
43 changed files with 1118 additions and 141 deletions
+19 -3
View File
@@ -523,6 +523,7 @@ const api: DesktopApi = {
})
},
workspace: {
getFileDiff: vi.fn(),
getChanges: vi.fn(async () => ({
rootPath: 'C:\\Workspace',
available: true,
@@ -4775,7 +4776,14 @@ describe('App', () => {
name: /产品知识/u
})
await waitFor(() => expect(scopeCheckbox).toHaveFocus())
fireEvent.click(scopeCheckbox)
fireEvent.focusOut(scopeCheckbox, { relatedTarget: null })
expect(knowledgeScopeTrigger).toHaveAttribute('aria-expanded', 'true')
fireEvent.click(screen.getByText('产品知识', { selector: 'span' }))
expect(scopeCheckbox).toBeChecked()
fireEvent.click(scopeCheckbox.closest('label')!)
expect(scopeCheckbox).not.toBeChecked()
fireEvent.click(scopeCheckbox.closest('label')!.querySelector('small')!)
expect(scopeCheckbox).toBeChecked()
const composerInput = screen.getByLabelText('向 GoodBuddy 提问')
fireEvent.focusOut(scopeCheckbox, {
relatedTarget: composerInput
@@ -5815,6 +5823,13 @@ describe('App', () => {
})
it('refreshes generated workspace files when a run completes', async () => {
vi.mocked(api.workspace.listDirectory).mockImplementation(async (_projectId, path) => ({
path,
entries: vi.mocked(api.workspace.getChanges).mock.calls.length >= 2
? [{ name: 'tree-only.txt', path: 'tree-only.txt', type: 'file' as const }]
: [],
truncated: false
}))
vi.mocked(api.workspace.getChanges)
.mockResolvedValueOnce({
rootPath: project.rootPath,
@@ -5852,6 +5867,7 @@ describe('App', () => {
})
expect(await screen.findByText('generated.md')).toBeInTheDocument()
expect(await screen.findByText('tree-only.txt')).toBeInTheDocument()
})
it('ignores stale Git changes after switching projects', async () => {
@@ -10246,8 +10262,8 @@ describe('App', () => {
screen.getByRole('tab', { name: '工作区' })
).toHaveAttribute('title', '浏览项目文件、Git 变更与文件内容')
expect(
screen.getByRole('heading', { name: '项目工作区' })
).toBeInTheDocument()
screen.queryByRole('heading', { name: '项目工作区' })
).not.toBeInTheDocument()
expect(
screen.getByRole('button', { name: '刷新工作区文件' })
).toBeInTheDocument()
+7 -1
View File
@@ -4740,6 +4740,7 @@ function App(): React.JSX.Element {
workMode: event.workMode,
state: event.state,
reason: event.reason,
progress: event.progress,
output: event.output,
error: event.error
}
@@ -5886,6 +5887,10 @@ function App(): React.JSX.Element {
},
[activeProjectId]
)
const loadWorkspaceDiff = useCallback(async (path: string) => {
if (!activeProjectId) throw new Error(tRef.current('notices.selectProject'))
return window.goodbuddy.workspace.getFileDiff(activeProjectId, path)
}, [activeProjectId])
const openWorkspaceEntry = useCallback(
async (
path: string,
@@ -9787,7 +9792,7 @@ function App(): React.JSX.Element {
className="knowledge-scope"
onBlurCapture={(event) => {
if (
!(event.relatedTarget instanceof Node) ||
event.relatedTarget instanceof Node &&
!event.currentTarget.contains(event.relatedTarget)
) {
setKnowledgeScopeOpen(false)
@@ -11228,6 +11233,7 @@ function App(): React.JSX.Element {
onListWorkspaceDirectory={listWorkspaceDirectory}
onLoadWorkspaceFile={loadWorkspaceFile}
onOpenWorkspaceEntry={openWorkspaceEntry}
onLoadWorkspaceDiff={loadWorkspaceDiff}
onRefreshChanges={refreshWorkspaceChanges}
onTabChange={setAssistantSidebarTab}
open={assistantSidebarOpen}
+40
View File
@@ -408,6 +408,46 @@ describe('ChatTimeline', () => {
}
})
it('renders live child progress in order and keeps the final result separate', () => {
const child = {
childTaskId: '00000000-0000-4000-8000-000000000111',
expertId: '00000000-0000-4000-8000-000000000211',
expertName: 'general', routingMode: 'native' as const,
state: 'running' as const,
progress: [
{ id: 'text', type: 'text' as const, content: 'Inspecting seed' },
{ id: 'tool', type: 'tool' as const, tool: {
callId: 'read', name: 'read', state: 'completed' as const,
summary: 'Read seed', output: 'seed contents'
} },
{ id: 'reasoning', type: 'reasoning' as const, content: 'Check the result' }
]
}
const props = {
artifactById: new Map(), conversationId: 'conversation-1',
hiddenMessageCount: 0, isUnusedConversation: false, locale: 'zh-CN' as const,
messageStartIndex: 0, ...callbacks, retryContent: '', totalMessageCount: 1
}
const message: Message = {
id: 'assistant', role: 'assistant', content: '', createdAt: 0,
state: 'streaming', subagents: [child]
}
const view = render(<ChatTimeline {...props} messages={[message]} />)
expect(screen.queryByText('Inspecting seed')).not.toBeInTheDocument()
fireEvent.click(screen.getByText('general', { selector: 'strong' }))
fireEvent(screen.getByText('general', { selector: 'strong' }).closest('details')!, new Event('toggle'))
const progress = screen.getByRole('region', { name: '执行过程' })
expect(within(progress).getByText('Inspecting seed')).toBeInTheDocument()
expect(within(progress).getByText('Check the result').closest('details')).not.toHaveAttribute('open')
expect(screen.queryByRole('region', { name: '最终结果' })).not.toBeInTheDocument()
view.rerender(<ChatTimeline {...props} messages={[{
...message, state: 'complete',
subagents: [{ ...child, state: 'completed', output: 'Final seed' }]
}]} />)
expect(screen.getByRole('region', { name: '最终结果' })).toHaveTextContent('Final seed')
expect(screen.getByRole('region', { name: '执行过程' })).not.toHaveTextContent('Final seed')
})
it('labels native OpenCode subagents and shows their task description', () => {
const messages: Message[] = [
{
+40 -4
View File
@@ -292,6 +292,14 @@ const SubagentStatusCard = memo(function SubagentStatusCard({
actor.kind === 'direct-model' && subagent.workMode
? `${source} · ${subagent.workMode === 'execute' ? 'Execute' : 'Ask'}`
: source
const progress = subagent.progress?.filter((block, index, blocks) =>
!(
subagent.state === 'completed' &&
index === blocks.length - 1 &&
block.type === 'text' &&
block.content.trim() === subagent.output?.trim()
)
)
return (
<details
@@ -332,9 +340,37 @@ const SubagentStatusCard = memo(function SubagentStatusCard({
</summary>
{expanded && (
<div className="subagent-status-card__details">
{progress && progress.length > 0 && (
<section aria-label={t('chat.subagents.progress')}>
<strong>{t('chat.subagents.progress')}</strong>
<div className="subagent-status-card__progress">
{groupMessageBlocks(progress).map((item) =>
item.kind === 'tools' ? (
<ToolExecutionList key={item.id} tools={item.tools.map((tool) =>
(tool.state === 'pending' || tool.state === 'running') &&
subagent.state !== 'queued' && subagent.state !== 'running'
? { ...tool, state: subagent.state === 'cancelled' ? 'cancelled' : 'interrupted' }
: tool
)} />
) : item.kind === 'subagents' ? null
: item.block.type === 'reasoning' ? (
<MessageReasoning
key={item.block.id}
content={item.block.content}
streaming={false}
/>
) : item.block.type === 'text' ? (
<div key={item.block.id} className="markdown-content">
<MarkdownRenderer>{item.block.content}</MarkdownRenderer>
</div>
) : null
)}
</div>
</section>
)}
{subagent.output ? (
<section>
<strong>{t('chat.subagents.output')}</strong>
<section aria-label={t('chat.subagents.finalOutput')}>
<strong>{t('chat.subagents.finalOutput')}</strong>
<div className="markdown-content">
<MarkdownRenderer
renderHtml={
@@ -345,9 +381,9 @@ const SubagentStatusCard = memo(function SubagentStatusCard({
</MarkdownRenderer>
</div>
</section>
) : (
) : !subagent.progress?.length ? (
<p>{t('chat.subagents.noOutput')}</p>
)}
) : null}
{subagent.error &&
(subagent.state === 'failed' ||
subagent.state === 'cancelled') && (
@@ -76,6 +76,7 @@ function renderSidebar({
onListWorkspaceDirectory={onListWorkspaceDirectory}
onLoadArtifact={onLoadArtifact}
onLoadWorkspaceFile={onLoadWorkspaceFile}
onLoadWorkspaceDiff={vi.fn()}
onOpenWorkspaceEntry={vi.fn(async () => undefined)}
onInteractBrowser={vi.fn(async () => undefined)}
onRefreshChanges={vi.fn(async () => undefined)}
+8 -20
View File
@@ -6,7 +6,6 @@ import {
CircleAlert,
ExternalLink,
FileText,
FolderTree,
ClockFading,
Monitor,
Plus,
@@ -117,6 +116,7 @@ type RightAssistantSidebarProps = {
onImportArtifacts: () => Promise<void>
onLoadArtifact: (artifactId: string) => Promise<void>
onRefreshChanges: () => Promise<void>
onLoadWorkspaceDiff: (path: string) => Promise<WorkspaceChanges>
onListWorkspaceDirectory: (
path: string
) => Promise<WorkspaceDirectoryListing>
@@ -500,6 +500,7 @@ export function RightAssistantSidebar({
onImportArtifacts,
onLoadArtifact,
onRefreshChanges,
onLoadWorkspaceDiff,
onListWorkspaceDirectory,
onLoadWorkspaceFile,
onOpenWorkspaceEntry,
@@ -629,7 +630,6 @@ export function RightAssistantSidebar({
useState(false)
const [workspacePreviewLoadMoreError, setWorkspacePreviewLoadMoreError] =
useState('')
const [workspaceRefreshVersion, setWorkspaceRefreshVersion] = useState(0)
const [taskFilter, setTaskFilter] = useState<
'attention' | 'active' | 'paused' | 'finished'
>('active')
@@ -1583,15 +1583,12 @@ export function RightAssistantSidebar({
</section>
) : (
<section className="assistant-sidebar__section">
<h3>
<FolderTree size={15} />
{t('sidebar.workspace.projectTitle')}
<div className="workspace-files__toolbar">
<button
aria-label={t('sidebar.workspace.refreshAriaLabel')}
className="icon-button"
disabled={!workspaceProjectId}
onClick={() => {
setWorkspaceRefreshVersion((current) => current + 1)
void runAction(
onRefreshChanges,
t('sidebar.errors.refreshWorkspace')
@@ -1602,12 +1599,14 @@ export function RightAssistantSidebar({
>
<RefreshCw size={14} />
</button>
</h3>
</div>
<WorkspaceFilesPanel
changedFiles={workspaceChanges?.files ?? emptyChangedFiles}
key={`${workspaceProjectId ?? 'none'}:${workspaceRefreshVersion}`}
key={workspaceProjectId ?? 'none'}
refreshToken={workspaceChanges}
onLoadDiff={onLoadWorkspaceDiff}
onListDirectory={onListWorkspaceDirectory}
onOpenEntry={onOpenWorkspaceEntry}
onOpenEntry={currentProject?.executionSpace?.kind === 'ssh' ? undefined : onOpenWorkspaceEntry}
onOpenFile={openWorkspaceFile}
projectId={workspaceProjectId}
/>
@@ -1618,17 +1617,6 @@ export function RightAssistantSidebar({
})}
</p>
)}
{workspaceChanges?.patch && (
<details className="assistant-sidebar__diff-details">
<summary>{t('sidebar.workspace.fullDiff')}</summary>
<pre className="assistant-sidebar__diff">
{workspaceChanges.patch}
{workspaceChanges.truncated
? t('sidebar.workspace.truncatedDiff')
: ''}
</pre>
</details>
)}
</section>
)
)}
+89 -4
View File
@@ -1,7 +1,7 @@
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { changeUiLocale } from './i18n'
import { WorkspaceFilesPanel } from './WorkspaceFilesPanel'
import { gitStatusLetter, WorkspaceFilesPanel } from './WorkspaceFilesPanel'
afterEach(async () => {
cleanup()
@@ -9,6 +9,9 @@ afterEach(async () => {
})
describe('WorkspaceFilesPanel', () => {
it.each([['??', 'U'], [' M', 'M'], ['A ', 'A'], [' D', 'D'], ['R ', 'R'], ['C ', 'C'], ['UU', 'U'], ['AM', 'AM'], [' T', 'T']])('maps %s to %s without calling every new file added', (status, letter) => {
expect(gitStatusLetter(status)).toBe(letter)
})
it('lists the project tree, expands directories, and opens files', async () => {
const onListDirectory = vi.fn(async (path: string) =>
path
@@ -45,6 +48,7 @@ describe('WorkspaceFilesPanel', () => {
render(
<WorkspaceFilesPanel
onLoadDiff={vi.fn()}
changedFiles={[{ path: 'notes.txt', status: ' M' }]}
onListDirectory={onListDirectory}
onOpenEntry={onOpenEntry}
@@ -74,7 +78,7 @@ describe('WorkspaceFilesPanel', () => {
})
)
expect(onOpenEntry).toHaveBeenCalledWith('docs', 'directory')
expect(screen.getAllByText('修改')).not.toHaveLength(0)
expect(screen.getAllByText('M')).not.toHaveLength(0)
})
it('ignores stale directory results after the active project changes', async () => {
@@ -100,6 +104,7 @@ describe('WorkspaceFilesPanel', () => {
})
const { rerender } = render(
<WorkspaceFilesPanel
onLoadDiff={vi.fn()}
changedFiles={[]}
onListDirectory={onListDirectory}
onOpenEntry={vi.fn(async () => undefined)}
@@ -111,6 +116,7 @@ describe('WorkspaceFilesPanel', () => {
await waitFor(() => expect(onListDirectory).toHaveBeenCalledOnce())
rerender(
<WorkspaceFilesPanel
onLoadDiff={vi.fn()}
changedFiles={[]}
onListDirectory={onListDirectory}
onOpenEntry={vi.fn(async () => undefined)}
@@ -133,6 +139,7 @@ describe('WorkspaceFilesPanel', () => {
render(
<WorkspaceFilesPanel
onLoadDiff={vi.fn()}
changedFiles={[{ path: 'notes.txt', status: ' M' }]}
onListDirectory={onListDirectory}
onOpenEntry={vi.fn(async () => undefined)}
@@ -149,7 +156,85 @@ describe('WorkspaceFilesPanel', () => {
await screen.findByText('Current workspace')
).toBeInTheDocument()
expect(screen.getByText('Uncommitted changes')).toBeInTheDocument()
expect(screen.getByText('Modified')).toBeInTheDocument()
expect(screen.getByText('M')).toBeInTheDocument()
expect(onListDirectory).toHaveBeenCalledOnce()
})
it('refreshes expanded directories and drops collapsed caches without remounting', async () => {
let version = 0
const onListDirectory = vi.fn(async (path: string) => ({
path,
entries: path ? [{ name: `file-${version}.txt`, path: `${path}/file-${version}.txt`, type: 'file' as const }]
: [{ name: 'docs', path: 'docs', type: 'directory' as const }],
truncated: false
}))
const props = { projectId: 'project', changedFiles: [], onListDirectory, onLoadDiff: vi.fn(), onOpenFile: vi.fn() }
const { rerender } = render(<WorkspaceFilesPanel {...props} refreshToken={version} />)
fireEvent.click(await screen.findByRole('button', { name: 'docs' }))
await screen.findByText('file-0.txt')
version += 1
rerender(<WorkspaceFilesPanel {...props} refreshToken={version} />)
await screen.findByText('file-1.txt')
expect(screen.queryByText('file-0.txt')).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'docs' })).toHaveAttribute('aria-expanded', 'true')
fireEvent.click(screen.getByRole('button', { name: 'docs' }))
version += 1
rerender(<WorkspaceFilesPanel {...props} refreshToken={version} />)
await waitFor(() => expect(onListDirectory).toHaveBeenCalledTimes(5))
fireEvent.click(screen.getByRole('button', { name: 'docs' }))
await screen.findByText('file-2.txt')
expect(screen.queryByRole('button', { name: /默认应用|资源管理器/ })).not.toBeInTheDocument()
})
it('opens a deleted file diff rather than reading the missing file', async () => {
const onLoadDiff = vi.fn(async () => ({ rootPath: '/project', available: true, files: [], status: '', patch: '-deleted content', stagedPatch: '-staged content', truncated: true }))
const onOpenFile = vi.fn()
render(<WorkspaceFilesPanel projectId="project" changedFiles={[{ path: 'deleted.txt', status: ' D' }]}
onListDirectory={vi.fn(async () => ({ path: '', entries: [], truncated: false }))}
onLoadDiff={onLoadDiff} onOpenFile={onOpenFile} />)
fireEvent.click(screen.getByRole('button', { name: /deleted.txt/ }))
await screen.findByText('-deleted content')
expect(screen.getByText('-staged content')).toBeInTheDocument()
expect(screen.getByText('差异内容已截断。')).toBeInTheDocument()
expect(onLoadDiff).toHaveBeenCalledWith('deleted.txt')
expect(onOpenFile).not.toHaveBeenCalled()
})
it('reloads the selected diff on refresh and ignores an older pending response', async () => {
let resolveOld!: (value: Awaited<ReturnType<typeof onLoadDiff>>) => void
const value = { rootPath: '/project', available: true, files: [], status: '', patch: '+fresh', stagedPatch: '', truncated: false }
const onLoadDiff = vi.fn<() => Promise<typeof value>>()
.mockImplementationOnce(() => new Promise(resolve => { resolveOld = resolve }))
.mockResolvedValue(value)
const props = {
projectId: 'project', changedFiles: [{ path: 'seed.txt', status: ' M' }],
onListDirectory: vi.fn(async () => ({ path: '', entries: [], truncated: false })),
onLoadDiff, onOpenFile: vi.fn()
}
const view = render(<WorkspaceFilesPanel {...props} refreshToken={0} />)
await waitFor(() => expect(props.onListDirectory).toHaveBeenCalledOnce())
fireEvent.click(screen.getByRole('button', { name: /seed.txt/ }))
view.rerender(<WorkspaceFilesPanel {...props} refreshToken={1} />)
await screen.findByText('+fresh')
await act(async () => resolveOld({ ...value, patch: '+stale' }))
expect(screen.queryByText('+stale')).not.toBeInTheDocument()
expect(onLoadDiff).toHaveBeenCalledTimes(2)
})
it('loads more changed files so deleted files after the first batch have a diff entry', async () => {
const onLoadDiff = vi.fn(async () => ({
rootPath: '/project', available: true, files: [], status: '',
patch: '-last deleted', stagedPatch: '', truncated: false
}))
render(<WorkspaceFilesPanel
projectId="project"
changedFiles={Array.from({ length: 51 }, (_, index) => ({ path: `deleted-${index}.txt`, status: ' D' }))}
onListDirectory={vi.fn(async () => ({ path: '', entries: [], truncated: false }))}
onLoadDiff={onLoadDiff} onOpenFile={vi.fn()}
/>)
expect(screen.queryByRole('button', { name: /deleted-50.txt/ })).not.toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: '加载更多变更(剩余 1 个)' }))
fireEvent.click(screen.getByRole('button', { name: /deleted-50.txt/ }))
await screen.findByText('-last deleted')
expect(onLoadDiff).toHaveBeenCalledWith('deleted-50.txt')
})
})
+92 -40
View File
@@ -1,6 +1,7 @@
import {
ChevronDown,
ChevronRight,
ChevronLeft,
FileSearch,
FileText,
Folder,
@@ -9,6 +10,7 @@ import {
import {
useCallback,
useEffect,
useEffectEvent,
useMemo,
useRef,
useState
@@ -16,6 +18,7 @@ import {
import { useTranslation } from 'react-i18next'
import type {
WorkspaceChangedFile,
WorkspaceChanges,
WorkspaceDirectoryEntry,
WorkspaceDirectoryListing
} from '../../shared/assistant-contracts'
@@ -23,36 +26,27 @@ import type {
type WorkspaceFilesPanelProps = {
projectId?: string
changedFiles: WorkspaceChangedFile[]
refreshToken?: unknown
onLoadDiff: (path: string) => Promise<WorkspaceChanges>
onListDirectory: (path: string) => Promise<WorkspaceDirectoryListing>
onOpenFile: (path: string) => void
onOpenEntry: (
onOpenEntry?: (
path: string,
type: WorkspaceDirectoryEntry['type']
) => Promise<void>
}
function statusKey(
status: string
): 'added' | 'deleted' | 'renamed' | 'modified' {
const value = status.trim()
if (value === '??') {
return 'added'
}
if (value.includes('D')) {
return 'deleted'
}
if (value.includes('R')) {
return 'renamed'
}
if (value.includes('A')) {
return 'added'
}
return 'modified'
export function gitStatusLetter(status: string): string {
if (status === '??') return 'U'
if (['DD', 'AU', 'UD', 'UA', 'DU', 'AA', 'UU'].includes(status)) return 'U'
return status.trim().replaceAll('.', '').split('').filter((value, index, values) => values.indexOf(value) === index).join('')
}
export function WorkspaceFilesPanel({
projectId,
changedFiles,
refreshToken,
onLoadDiff,
onListDirectory,
onOpenFile,
onOpenEntry
@@ -80,6 +74,18 @@ export function WorkspaceFilesPanel({
}>({})
const requestGeneration = useRef(0)
const inFlightPaths = useRef(new Set<string>())
const [diff, setDiff] = useState<{ path: string; value?: WorkspaceChanges; error?: string }>()
const diffRequest = useRef(0)
const [visibleChangeCount, setVisibleChangeCount] = useState(50)
const openDiff = (path: string): void => {
const request = ++diffRequest.current
setDiff({ path })
void onLoadDiff(path).then((value) => {
if (request === diffRequest.current) setDiff({ path, value, error: value.error })
}).catch((reason: unknown) => {
if (request === diffRequest.current) setDiff({ path, error: reason instanceof Error ? reason.message : t('files.errors.read') })
})
}
const loadDirectory = useCallback(
async (path: string, generation: number): Promise<void> => {
@@ -118,8 +124,8 @@ export function WorkspaceFilesPanel({
})
}
} finally {
inFlightPaths.current.delete(path)
if (requestGeneration.current === generation) {
inFlightPaths.current.delete(path)
setLoadingState((current) => {
const next = new Set(
current.projectId === projectId ? current.value : []
@@ -133,6 +139,14 @@ export function WorkspaceFilesPanel({
[onListDirectory, projectId]
)
const refreshDirectories = useEffectEvent((generation: number) => {
const paths = expandedState.projectId === projectId ? [...expandedState.value] : []
setListingState({ projectId, value: {} })
setLoadingState({ projectId, value: new Set() })
void loadDirectory('', generation)
for (const path of paths) void loadDirectory(path, generation)
if (diff) openDiff(diff.path)
})
useEffect(() => {
requestGeneration.current += 1
const generation = requestGeneration.current
@@ -141,10 +155,14 @@ export function WorkspaceFilesPanel({
return
}
const timeout = setTimeout(() => {
void loadDirectory('', generation)
refreshDirectories(generation)
}, 0)
return () => clearTimeout(timeout)
}, [loadDirectory, projectId])
return () => {
clearTimeout(timeout)
requestGeneration.current += 1
diffRequest.current += 1
}
}, [loadDirectory, projectId, refreshToken])
const changedByPath = useMemo(
() =>
@@ -190,7 +208,7 @@ export function WorkspaceFilesPanel({
const openEntry = (entry: WorkspaceDirectoryEntry): void => {
setErrorState({ projectId })
void onOpenEntry(entry.path, entry.type).catch((reason: unknown) => {
void onOpenEntry?.(entry.path, entry.type).catch((reason: unknown) => {
setErrorState({
projectId,
value:
@@ -227,7 +245,7 @@ export function WorkspaceFilesPanel({
{expanded ? <FolderOpen size={15} /> : <Folder size={15} />}
<span title={entry.path}>{entry.name}</span>
</button>
<button
{onOpenEntry && <button
aria-label={t('files.openFolderAriaLabel', {
name: entry.name
})}
@@ -237,7 +255,7 @@ export function WorkspaceFilesPanel({
type="button"
>
<FolderOpen size={14} />
</button>
</button>}
</div>
{expanded && (
<div className="workspace-files__children">
@@ -271,12 +289,12 @@ export function WorkspaceFilesPanel({
<FileText size={15} />
<span>{entry.name}</span>
{changed && (
<small className="workspace-files__change">
{t(`files.statuses.${statusKey(changed.status)}`)}
<small className="workspace-files__change" data-status={gitStatusLetter(changed.status)} title={changed.status}>
{gitStatusLetter(changed.status)}
</small>
)}
</button>
<button
{onOpenEntry && <button
aria-label={t('files.openFileAriaLabel', {
name: entry.name
})}
@@ -286,7 +304,7 @@ export function WorkspaceFilesPanel({
type="button"
>
<FileSearch size={14} />
</button>
</button>}
</div>
)
}
@@ -300,34 +318,68 @@ export function WorkspaceFilesPanel({
}
const root = listings['']
const renderPatch = (patch: string): React.JSX.Element => (
<pre className="assistant-sidebar__diff workspace-files__diff">
{patch.split('\n').map((line, index) => (
<span key={index} data-line={
line.startsWith('+++') || line.startsWith('---') ? 'header'
: line.startsWith('+') ? 'added'
: line.startsWith('-') ? 'deleted'
: line.startsWith('@@') ? 'hunk' : undefined
}>{line}{'\n'}</span>
))}
</pre>
)
if (diff) {
return <section className="assistant-sidebar__preview" aria-busy={!diff.value && !diff.error}>
<header>
<button className="assistant-sidebar__back" type="button" onClick={() => {
diffRequest.current += 1
setDiff(undefined)
}}><ChevronLeft size={14} />{t('files.currentWorkspace')}</button>
<strong>{diff.path}</strong>
</header>
{diff.error ? <p role="alert">{diff.error}<button type="button" onClick={() => openDiff(diff.path)}>{t('files.retry')}</button></p>
: !diff.value ? <p>{t('files.reading')}</p> : <>
{diff.value.stagedPatch && <><h4>{t('files.staged')}</h4>{renderPatch(diff.value.stagedPatch)}</>}
{diff.value.patch && <><h4>{t('files.unstaged')}</h4>{renderPatch(diff.value.patch)}</>}
{!diff.value.patch && !diff.value.stagedPatch && <p>{t('files.noDiff')}</p>}
{diff.value.truncated && <p>{t('files.diffTruncated')}</p>}
</>}
</section>
}
return (
<div className="workspace-files">
{changedFiles.length > 0 && (
<div className="workspace-files__changed">
<strong>{t('files.changedTitle')}</strong>
{changedFiles.slice(0, 50).map((file) => {
const deleted = file.status.includes('D')
{changedFiles.slice(0, visibleChangeCount).map((file) => {
return (
<button
className="workspace-files__changed-row"
disabled={deleted}
key={`${file.status}:${file.path}`}
onClick={() => onOpenFile(file.path)}
title={file.path}
onClick={() => openDiff(file.path)}
title={`${file.previousPath ? `${file.previousPath} -> ` : ''}${file.path} (${file.status})`}
type="button"
>
<FileText size={14} />
<span>{file.path}</span>
<small>
{t(`files.statuses.${statusKey(file.status)}`)}
<small data-status={gitStatusLetter(file.status)} data-conflict={['DD', 'AU', 'UD', 'UA', 'DU', 'AA', 'UU'].includes(file.status)} aria-label={file.status}>
{gitStatusLetter(file.status)}
</small>
</button>
)
})}
{changedFiles.length > 50 && (
<p className="workspace-files__status">
{t('files.changesTruncated')}
</p>
{changedFiles.length > visibleChangeCount && (
<button
className="secondary-button"
type="button"
onClick={() => setVisibleChangeCount((count) => count + 50)}
>
{t('files.loadMoreChanges', {
count: changedFiles.length - visibleChangeCount
})}
</button>
)}
</div>
)}
@@ -376,6 +376,8 @@ export const app = {
fallbackTask: '{{name}} subagent task',
task: 'Task',
output: 'Subagent output',
progress: 'Execution progress',
finalOutput: 'Final result',
error: 'Execution details',
noOutput: 'This subagent has no output to display yet.',
incomplete:
@@ -432,6 +432,11 @@ export const workspace = {
taskList: 'Task list'
},
files: {
staged: 'Staged changes',
unstaged: 'Working tree changes',
noDiff: 'No textual differences (the file may be empty or only its status changed).',
diffTruncated: 'Diff output truncated.',
retry: 'Retry',
statuses: {
added: 'Added',
deleted: 'Deleted',
@@ -452,7 +457,7 @@ export const workspace = {
'This folder has more than 500 items. Only the first 500 are shown.',
selectProject: 'Select a project to browse its workspace.',
changedTitle: 'Uncommitted changes',
changesTruncated: 'Only the first 50 uncommitted changes are shown.',
loadMoreChanges: 'Load more changes ({{count}} remaining)',
currentWorkspace: 'Current workspace',
readingWorkspace: 'Reading workspace…',
rootTruncated:
@@ -358,6 +358,8 @@ export const app = {
fallbackTask: '{{name}} 子专家任务',
task: '任务',
output: '子代理输出',
progress: '执行过程',
finalOutput: '最终结果',
error: '执行说明',
noOutput: '子代理暂时没有可显示的输出。',
incomplete: '父请求已结束,但子 Agent 未报告完成状态。',
@@ -422,6 +422,11 @@ export const workspace = {
taskList: '任务列表'
},
files: {
staged: '已暂存更改',
unstaged: '工作树更改',
noDiff: '没有文本差异(文件可能为空,或仅状态发生变化)。',
diffTruncated: '差异内容已截断。',
retry: '重试',
statuses: {
added: '新增',
deleted: '删除',
@@ -441,7 +446,7 @@ export const workspace = {
directoryTruncated: '目录项目超过 500 项,仅显示前 500 项。',
selectProject: '选择项目后可浏览项目工作区。',
changedTitle: '未提交更改',
changesTruncated: '仅显示前 50 个未提交更改。',
loadMoreChanges: '加载更多变更(剩余 {{count}} 个)',
currentWorkspace: '当前工作区',
readingWorkspace: '正在读取工作区…',
rootTruncated: '根目录项目超过 500 项,仅显示前 500 项。',
+58 -10
View File
@@ -4283,16 +4283,6 @@ button > svg {
word-break: break-word;
}
.assistant-sidebar__diff-details {
color: var(--text-secondary);
font-size: var(--font-caption);
}
.assistant-sidebar__diff-details summary {
padding: var(--space-2) 0;
cursor: pointer;
}
.workspace-files {
display: flex;
min-width: 0;
@@ -4300,6 +4290,46 @@ button > svg {
gap: var(--space-2);
}
.workspace-files__toolbar {
display: flex;
justify-content: flex-end;
}
.workspace-files__diff [data-line="added"] {
color: var(--success);
background: var(--success-subtle);
}
.workspace-files__diff [data-line="deleted"] {
color: var(--danger);
background: var(--danger-subtle);
}
.workspace-files__diff [data-line="hunk"] {
color: var(--accent);
}
.workspace-files [data-status] {
color: var(--warning);
font-weight: 600;
flex-shrink: 0;
}
.workspace-files [data-status="A"],
.workspace-files [data-status="U"] {
color: var(--success);
}
.workspace-files [data-status="D"],
.workspace-files [data-conflict="true"] {
color: var(--danger);
}
.workspace-files [data-status="R"],
.workspace-files [data-status="C"] {
color: var(--accent);
}
.workspace-files__heading,
.workspace-files__changed > strong {
color: var(--text-secondary);
@@ -6226,6 +6256,14 @@ button > svg {
gap: var(--space-3);
}
.subagent-status-card__progress {
display: grid;
min-width: 0;
gap: var(--space-3);
padding-left: var(--space-3);
border-left: 1px solid var(--border-default);
}
.subagent-status-card__details section {
display: grid;
gap: var(--space-2);
@@ -11960,6 +11998,16 @@ details.settings-section > :not(summary) + :not(summary) {
color: var(--accent);
}
.knowledge-scope__popover label:has(input:checked) {
background: var(--accent-subtle);
color: var(--accent);
}
.knowledge-scope__popover label:focus-within {
outline: 2px solid var(--accent);
outline-offset: -2px;
}
.knowledge-scope__popover label input {
accent-color: var(--accent-solid);
}