Skip to content
Merged
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
8 changes: 4 additions & 4 deletions desktop/src/__tests__/skillsSettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('Settings > Skills tab', () => {
selectedSkill: {
meta: useSkillStore.getState().skills[0]!,
tree: [{ name: 'SKILL.md', path: 'SKILL.md', type: 'file' }],
files: [{ path: 'SKILL.md', kind: 'text', content: '# Alpha', body: '# Alpha', language: 'markdown', isEntry: true }],
files: [{ path: 'SKILL.md', state: 'text', content: '# Alpha', body: '# Alpha', language: 'markdown', isEntry: true }],
skillRoot: '/tmp/alpha',
},
})
Expand Down Expand Up @@ -278,7 +278,7 @@ describe('Settings > Skills tab', () => {
files: [
{
path: 'SKILL.md',
kind: 'text',
state: 'text',
content: '# Hello\n\nBody content',
body: '# Hello\n\nBody content',
language: 'markdown',
Expand All @@ -291,7 +291,7 @@ describe('Settings > Skills tab', () => {
},
{
path: 'run.ts',
kind: 'text',
state: 'text',
content: 'console.log("hello")',
language: 'typescript',
isEntry: false,
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('Settings > Skills tab', () => {
files: [
{
path: 'SKILL.md',
kind: 'text',
state: 'text',
content: '# Access',
body: '# Access',
language: 'markdown',
Expand Down
5 changes: 3 additions & 2 deletions desktop/src/api/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,11 @@ export type WorkspaceStatusResult = {
error?: string
}

export type FilePreviewState = 'text' | 'image' | 'binary' | 'too_large' | 'missing' | 'error'

export type WorkspaceReadFileResult = {
state: 'ok' | 'binary' | 'too_large' | 'missing' | 'error'
state: FilePreviewState
path: string
previewType?: 'text' | 'image'
content?: string
dataUrl?: string
mimeType?: string
Expand Down
8 changes: 4 additions & 4 deletions desktop/src/components/skills/SkillDetail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const SKILL: SkillDetailData = {
files: [
{
path: 'SKILL.md',
kind: 'text',
state: 'text',
content: '---\nname: skill-test\n---\n# Skill Body',
body: '# Skill Body',
language: 'markdown',
Expand All @@ -71,7 +71,7 @@ const SKILL: SkillDetailData = {
model: 'sonnet',
},
},
{ path: 'run.ts', kind: 'text', content: 'console.log("run")', language: 'typescript' },
{ path: 'run.ts', state: 'text', content: 'console.log("run")', language: 'typescript' },
],
skillRoot: '/tmp/skill-test',
}
Expand Down Expand Up @@ -145,8 +145,8 @@ describe('SkillDetail', () => {
],
files: [
...SKILL.files,
{ path: 'assets/logo.png', kind: 'image', content: '', language: 'image' },
{ path: 'tool.bin', kind: 'binary', content: '', language: 'binary' },
{ path: 'assets/logo.png', state: 'image', content: '', language: 'image' },
{ path: 'tool.bin', state: 'binary', content: '', language: 'binary' },
],
},
})
Expand Down
8 changes: 4 additions & 4 deletions desktop/src/components/skills/SkillDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function SkillFileView({
onViewModeChange: (mode: ViewMode) => void
}) {
const t = useTranslation()
const isMarkdown = file.kind === 'text' && file.language === 'markdown'
const isMarkdown = file.state === 'text' && file.language === 'markdown'
const showPreview = isMarkdown && viewMode === 'preview'

return (
Expand Down Expand Up @@ -182,17 +182,17 @@ function SkillFileView({

function SkillFileBody({ file, skillRoot, showPreview }: { file: SkillFile; skillRoot: string; showPreview: boolean }) {
const t = useTranslation()
if (file.kind === 'image') {
if (file.state === 'image') {
return (
<div className="flex min-h-0 flex-1 items-center justify-center overflow-auto p-6">
<img src={filesystemApi.fileUrl(`${skillRoot}/${file.path}`)} alt={file.path} className="max-h-full max-w-full object-contain" />
</div>
)
}
if (file.kind !== 'text') {
if (file.state !== 'text') {
return (
<div className="flex min-h-0 flex-1 items-center justify-center">
<PanelMessage icon={FileWarningIcon} message={t(file.kind === 'too_large' ? 'workspace.previewState.tooLarge' : 'workspace.previewState.binary')} />
<PanelMessage icon={FileWarningIcon} message={t(file.state === 'too_large' ? 'workspace.previewState.tooLarge' : 'workspace.previewState.binary')} />
</div>
)
}
Expand Down
36 changes: 17 additions & 19 deletions desktop/src/components/workspace/WorkspacePanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ describe('WorkspacePanel', () => {
entries: Array<{ name: string; path: string; isDirectory: boolean }>
}>()
const fileRequest = deferred<{
state: 'ok'
state: 'text'
path: string
content: string
language: string
Expand Down Expand Up @@ -782,7 +782,7 @@ describe('WorkspacePanel', () => {
})
await act(async () => {
fileRequest.resolve({
state: 'ok',
state: 'text',
path: 'src/index.ts',
content: 'export const ready = true',
language: 'typescript',
Expand Down Expand Up @@ -979,7 +979,7 @@ describe('WorkspacePanel', () => {
},
}))

getMocks().getWorkspaceFileMock.mockResolvedValue({ state: 'ok', path: 'src/App.tsx', content: 'export {}', language: 'tsx', size: 9 })
getMocks().getWorkspaceFileMock.mockResolvedValue({ state: 'text', path: 'src/App.tsx', content: 'export {}', language: 'tsx', size: 9 })
const view = await renderPanel('session-narrow')

await clickElement(view.getByRole('treeitem', { name: 'src/App.tsx' }))
Expand All @@ -1002,7 +1002,7 @@ describe('WorkspacePanel', () => {
'session-tree-tab': { '': { state: 'ok', path: '', entries: [{ name: 'App.tsx', path: 'App.tsx', isDirectory: false }] } },
},
}))
getMocks().getWorkspaceFileMock.mockResolvedValue({ state: 'ok', path: 'App.tsx', content: 'export {}', language: 'typescript', size: 9 })
getMocks().getWorkspaceFileMock.mockResolvedValue({ state: 'text', path: 'App.tsx', content: 'export {}', language: 'typescript', size: 9 })

const view = await renderPanel('session-tree-tab')
await act(() => {
Expand Down Expand Up @@ -1045,7 +1045,7 @@ describe('WorkspacePanel', () => {
title: 'theme.ts',
language: 'typescript',
content: 'export const theme = "dark"',
state: 'ok',
state: 'text',
size: 27,
}]),
}))
Expand Down Expand Up @@ -1124,8 +1124,7 @@ describe('WorkspacePanel', () => {
title: 'large-file.ts',
content: longFile,
language: 'typescript',
previewType: 'text',
state: 'ok',
state: 'text',
}]),
}))

Expand Down Expand Up @@ -1163,9 +1162,8 @@ describe('WorkspacePanel', () => {
}))

getMocks().getWorkspaceFileMock.mockResolvedValue({
state: 'ok',
state: 'image',
path: 'logo.png',
previewType: 'image',
dataUrl: 'data:image/png;base64,iVBORw0KGgo=',
mimeType: 'image/png',
language: 'image',
Expand All @@ -1190,7 +1188,7 @@ describe('WorkspacePanel', () => {
title: 'README.md',
language: 'markdown',
content: '# Project Notes\n\n- **Done** item\n\n```ts\nexport const ok = true\n```',
state: 'ok',
state: 'text',
size: 70,
}]),
}))
Expand Down Expand Up @@ -1281,7 +1279,7 @@ describe('WorkspacePanel', () => {
title: 'App.ts',
language: 'text',
content: 'const a = 1\nconst b = 2',
state: 'ok',
state: 'text',
size: 24,
}]),
}))
Expand Down Expand Up @@ -1344,7 +1342,7 @@ describe('WorkspacePanel', () => {
title: 'README.md',
language: 'markdown',
content: '# Project Notes\n\nShip the release.',
state: 'ok',
state: 'text',
size: 34,
}]),
}))
Expand Down Expand Up @@ -1402,7 +1400,7 @@ describe('WorkspacePanel', () => {
? { state: 'ok', path, entries: [{ name: 'lib', path: 'src/lib', isDirectory: true }] }
: { state: 'ok', path, entries: [{ name: 'a.ts', path: 'src/lib/a.ts', isDirectory: false }] }
))
getMocks().getWorkspaceFileMock.mockResolvedValue({ state: 'ok', path: 'src/lib/a.ts', content: 'export {}', language: 'ts', size: 9 })
getMocks().getWorkspaceFileMock.mockResolvedValue({ state: 'text', path: 'src/lib/a.ts', content: 'export {}', language: 'ts', size: 9 })
await setWorkspaceState((state) => ({
...state,
panelByTab: { ...state.panelByTab, 'session-reveal-load': { ...panelState({ id: 'files', kind: 'files' }), selectedFile: 'src/lib/a.ts' } },
Expand All @@ -1427,7 +1425,7 @@ describe('WorkspacePanel', () => {

it('reveals a path segment in the file tree and opens a terminal in it from its menu', async () => {
Object.assign(window, { [ELECTRON_BRIDGE_KEY]: {} })
getMocks().getWorkspaceFileMock.mockResolvedValue({ state: 'ok', path: 'src/index.ts', content: 'export {}', language: 'ts', size: 9 })
getMocks().getWorkspaceFileMock.mockResolvedValue({ state: 'text', path: 'src/index.ts', content: 'export {}', language: 'ts', size: 9 })
await setWorkspaceState((state) => ({
...state,
panelByTab: { ...state.panelByTab, 'session-crumbs': { ...panelState({ id: 'files', kind: 'files' }), selectedFile: 'src/index.ts' } },
Expand Down Expand Up @@ -1766,7 +1764,7 @@ describe('WorkspacePanel', () => {
title: 'App.tsx',
language: 'tsx',
content: 'const title = "Todo"\nexport default title',
state: 'ok',
state: 'text',
size: 42,
}]),
}))
Expand Down Expand Up @@ -1804,7 +1802,7 @@ describe('WorkspacePanel', () => {
title: 'App.ts',
language: 'text',
content: 'const title = "Todo"\nexport default title',
state: 'ok',
state: 'text',
size: 42,
}]),
}))
Expand Down Expand Up @@ -1839,7 +1837,7 @@ describe('WorkspacePanel', () => {
title: 'App.ts',
language: 'text',
content: 'const title = "Todo"\nexport default title',
state: 'ok',
state: 'text',
size: 42,
}]),
}))
Expand Down Expand Up @@ -1869,7 +1867,7 @@ describe('WorkspacePanel', () => {
title: 'App.ts',
language: 'text',
content: 'const title = "Todo"\nexport default title',
state: 'ok',
state: 'text',
size: 42,
}]),
}))
Expand Down Expand Up @@ -1899,7 +1897,7 @@ describe('WorkspacePanel', () => {
title: 'guide.md',
language: 'markdown',
content: '# Guide\nAlpha note and Beta note',
state: 'ok',
state: 'text',
size: 33,
}]),
}))
Expand Down
13 changes: 7 additions & 6 deletions desktop/src/components/workspace/WorkspacePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,15 @@ function FileExpandedBody({
const [wrap, setWrap] = useState(true)
const state = loading || !entry ? 'loading' : entry.state ?? 'loading'
const isDiff = entry?.kind === 'diff'
const isImage = state === 'ok' && entry?.previewType === 'image'
const isMarkdownFile = state === 'ok' && !isDiff && !isImage && entry ? isMarkdownPreview(entry) : false
const isFileContent = state === 'text' || state === 'image'
const isImage = state === 'image'
const isMarkdownFile = isFileContent && !isDiff && !isImage && entry ? isMarkdownPreview(entry) : false
const isMarkdown = isMarkdownFile && (showPreview || !fill)
const isCode = state === 'ok' && !isDiff && !isImage && !isMarkdown
const isCode = isFileContent && !isDiff && !isImage && !isMarkdown
const isEmptyDiff = state === 'ok' && isDiff && !(entry?.diff ?? '').trim()
const frameClass = `overflow-auto ${fill ? 'min-h-0 flex-1' : 'max-h-[420px] rounded-md'}`
const codeSurfaceClass = `${frameClass} bg-code`
const contentMenu = fill && path !== null && state === 'ok' ? fileMenu : undefined
const contentMenu = fill && path !== null && isFileContent ? fileMenu : undefined

let content: ReactNode
if (path === null) {
Expand Down Expand Up @@ -590,7 +591,7 @@ function FileExpandedBody({
className={`${frameClass} bg-background`}
/>
)
} else if (state === 'ok') {
} else if (state === 'text') {
content = (
<CodeSurface
path={path}
Expand Down Expand Up @@ -769,7 +770,7 @@ function PreviewBody({ sessionId, path, kind, fill = false, headerAction, aside,
const fileMenu: FileMenu = [
actions.addAction(filePath),
actions.copySubmenu(filePath),
...(entry?.state === 'ok' && entry.previewType !== 'image' && entry.content !== undefined ? [actions.copyContents(entry.content)] : []),
...(entry?.content !== undefined ? [actions.copyContents(entry.content)] : []),
]
return (
<FileExpandedBody
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/stores/workspacePanelStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('workspacePanelStore', () => {

it('opens a typed address as a project file, or as a web page in the desktop app', async () => {
mocks.getWorkspaceFileMock.mockImplementation(async (_sessionId: string, path: string) => (
path === 'src/a.ts' ? { state: 'ok', path, content: '' } : { state: 'missing', path }
path === 'src/a.ts' ? { state: 'text', path, content: '' } : { state: 'missing', path }
))
mocks.submitBrowserInput.mockResolvedValue(undefined)
const store = useWorkspacePanelStore.getState()
Expand Down
4 changes: 1 addition & 3 deletions desktop/src/stores/workspacePanelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export type WorkspacePreviewEntry = {
content?: string
dataUrl?: string
mimeType?: string
previewType?: 'text' | 'image'
diff?: string
state?: WorkspacePreviewState
error?: string
Expand Down Expand Up @@ -343,7 +342,7 @@ function resolvePanelTarget(

async function isWorkspaceFile(sessionId: string, path: string) {
const result = await sessionsApi.getWorkspaceFile(sessionId, path)
return result.state === 'ok' || result.state === 'binary' || result.state === 'too_large'
return result.state === 'text' || result.state === 'image' || result.state === 'binary' || result.state === 'too_large'
}

export function getShellDisplayName(shell: string | undefined) {
Expand Down Expand Up @@ -979,7 +978,6 @@ async function loadPreview(
content: result.content,
dataUrl: result.dataUrl,
mimeType: result.mimeType,
previewType: result.previewType ?? 'text',
language: result.language,
size: result.size,
state: result.state,
Expand Down
6 changes: 5 additions & 1 deletion desktop/src/types/skill.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { FilePreviewState } from '../api/sessions'

export type SkillSource = 'user' | 'claudeCode' | 'project' | 'plugin' | 'mcp' | 'bundled'

export type SkillMeta = {
Expand All @@ -21,9 +23,11 @@ export type FileTreeNode = {

export type SkillFrontmatter = Record<string, unknown>

export type SkillFileState = Exclude<FilePreviewState, 'missing' | 'error'>

export type SkillFile = {
path: string
kind: 'text' | 'image' | 'binary' | 'too_large'
state: SkillFileState
content: string
language: string
frontmatter?: SkillFrontmatter
Expand Down
2 changes: 1 addition & 1 deletion docs/features/ui-refresh/visual-refresh.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

**服务端。** [openTargetService.ts](../../../src/server/services/openTargetService.ts) 的 `resolveOpenPath` 允许文件:编辑器直接打开文件,文件管理器打开它所在的目录。

**技能详情页(第二轮)。** [SkillDetail.tsx](../../../desktop/src/components/skills/SkillDetail.tsx) 用 `Tabs` 新增的 `line` 变体做两个标签;[SkillFileTree.tsx](../../../desktop/src/components/skills/SkillFileTree.tsx) 用 `@pierre/trees` 显示文件树,样式与 Files 标签共用 [fileTreeCss.ts](../../../desktop/src/components/shared/fileTreeCss.ts)。设置页的内容区改成纵向弹性布局,详情页铺满剩余高度,「内容」标签的树和预览在面板内滚动,不再让整个设置页滚动。服务端 [skills.ts](../../../src/server/api/skills.ts) 给每个文件标 `kind`(`text`、`image`、`binary`、`too_large`),路径统一用 `/` 分隔;图片不随详情一起返回,选中时由页面通过 `/api/filesystem/file` 加载。图片扩展名到 MIME 类型的对应表只有一份,在 [imageMime.ts](../../../src/server/services/imageMime.ts),技能详情、Files 预览和 `/api/filesystem/file` 共用。
**技能详情页(第二轮)。** [SkillDetail.tsx](../../../desktop/src/components/skills/SkillDetail.tsx) 用 `Tabs` 新增的 `line` 变体做两个标签;[SkillFileTree.tsx](../../../desktop/src/components/skills/SkillFileTree.tsx) 用 `@pierre/trees` 显示文件树,样式与 Files 标签共用 [fileTreeCss.ts](../../../desktop/src/components/shared/fileTreeCss.ts)。设置页的内容区改成纵向弹性布局,详情页铺满剩余高度,「内容」标签的树和预览在面板内滚动,不再让整个设置页滚动。服务端 [skills.ts](../../../src/server/api/skills.ts) 给每个文件标 `state`(`text`、`image`、`binary`、`too_large`),路径统一用 `/` 分隔;图片不随详情一起返回,选中时由页面通过 `/api/filesystem/file` 加载。图片扩展名到 MIME 类型的对应表只有一份,在 [imageMime.ts](../../../src/server/services/imageMime.ts),技能详情、Files 预览和 `/api/filesystem/file` 共用。

## 检查

Expand Down
Loading
Loading