🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(document-tree): give the agent documents tree a document-reading layout (#18495)
Arvin Xu6a0694f52acc
diff --git a/src/features/AgentDocumentsExplorer/DocumentExplorerToolbar.tsx b/src/features/AgentDocumentsExplorer/DocumentExplorerToolbar.tsxindex 6677ecec055..99f9c4094ca 100644--- a/src/features/AgentDocumentsExplorer/DocumentExplorerToolbar.tsx+++ b/src/features/AgentDocumentsExplorer/DocumentExplorerToolbar.tsx@@ -7,8 +7,11 @@ import { useTranslation } from 'react-i18next';const styles = createStaticStyles(({ css, cssVar }) => ({toolbar: css`- padding-block: 4px;- padding-inline: 12px 4px;+ /* padding-inline start matches a tree row's content edge:+ --trees-padding-inline (4) - --trees-item-margin-x (4), clamped at 0,+ plus the row's own margin (4) and padding (8). */+ padding-block: 8px 4px;+ padding-inline: 12px 8px;color: ${cssVar.colorTextSecondary};`,title: css`diff --git a/src/features/AgentDocumentsExplorer/DocumentExplorerTree.test.tsx b/src/features/AgentDocumentsExplorer/DocumentExplorerTree.test.tsxindex 2182c821e06..80896bfc184 100644--- a/src/features/AgentDocumentsExplorer/DocumentExplorerTree.test.tsx+++ b/src/features/AgentDocumentsExplorer/DocumentExplorerTree.test.tsx@@ -164,7 +164,16 @@ vi.mock('@/features/ExplorerTree', () => {return {DISABLE_ROW_TEXT_SELECTION_CSS: '',+ DOCUMENT_TREE_ROW_CSS: '',DOCUMENT_TREE_ICON_CSS: '',+ DOCUMENT_TREE_LAYOUT: {+ fontSize: 14,+ iconGap: 8,+ iconSize: 16,+ iconWidth: 16,+ itemHeight: 36,+ levelGap: 8,+ },ExplorerTree,FOLDER_ICON_CSS: '',HIDE_POINTER_FOCUS_RING_CSS: '',diff --git a/src/features/AgentDocumentsExplorer/DocumentExplorerTree.tsx b/src/features/AgentDocumentsExplorer/DocumentExplorerTree.tsxindex 7c3b69086b5..49c39d8e659 100644--- a/src/features/AgentDocumentsExplorer/DocumentExplorerTree.tsx+++ b/src/features/AgentDocumentsExplorer/DocumentExplorerTree.tsx@@ -17,6 +17,8 @@ import type {import {DISABLE_ROW_TEXT_SELECTION_CSS,DOCUMENT_TREE_ICON_CSS,+ DOCUMENT_TREE_LAYOUT,+ DOCUMENT_TREE_ROW_CSS,ExplorerTree,getExplorerTreeStyleVars,HIDE_POINTER_FOCUS_RING_CSS,@@ -30,12 +32,22 @@ import DocumentExplorerToolbar from './DocumentExplorerToolbar';import { useDocumentTreeOps } from './hooks/useDocumentTreeOps';import type { AgentDocumentItem } from './types';import { isOrphanSkillBundleItem } from './types';+import { usePanelBackground } from './usePanelBackground';import { canDropDocument } from './utils/canDrop';const SKILL_INDEX_FILENAME = 'SKILL.md';const FILE_TREE_HOST_TAG = 'file-tree-container';const RENAME_INPUT_SELECTOR = 'input[data-item-rename-input]';-const DOCUMENT_TREE_UNSAFE_CSS = `${DOCUMENT_TREE_ICON_CSS}\n${HIDE_POINTER_FOCUS_RING_CSS}\n${DISABLE_ROW_TEXT_SELECTION_CSS}`;+// Only used when every ancestor is transparent; the documents page is the+// common case and paints colorBgLayout.+const DEFAULT_PANEL_BACKGROUND = '#000';++const DOCUMENT_TREE_UNSAFE_CSS = [+ DOCUMENT_TREE_ICON_CSS,+ DOCUMENT_TREE_ROW_CSS,+ HIDE_POINTER_FOCUS_RING_CSS,+ DISABLE_ROW_TEXT_SELECTION_CSS,+].join('\n');// pierre/trees auto-selects the full value when the rename input mounts. For// files with extensions (e.g. `Untitled document.md`), narrow the selection to@@ -59,12 +71,31 @@ const styles = createStaticStyles(({ css, cssVar }) => ({--trees-selected-bg-override: ${cssVar.colorFillSecondary};--trees-selected-fg-override: ${cssVar.colorText};--trees-bg-muted-override: ${cssVar.colorFillTertiary};- --trees-fg-override: ${cssVar.colorTextSecondary};- --trees-fg-muted-override: ${cssVar.colorTextSecondary};++ /* Every row is a document the user can open, so labels keep the primary+ text color; only the glyphs step back. Mirrors the sidebar NavItem, which+ pairs colorText titles with colorTextDescription icons. */+ --trees-fg-override: ${cssVar.colorText};+ --trees-fg-muted-override: ${cssVar.colorTextDescription};--trees-accent-override: ${cssVar.colorPrimary};- --trees-padding-inline-override: 0px;- --trees-font-size-override: 12px;- --trees-border-radius-override: 6px;++ /* Nesting reads from indentation alone — no indent guides. */+ --trees-indent-guide-bg-override: transparent;++ /* Documents are prose, not code: give rows the breathing room of a+ Notion / 语雀 outline instead of the IDE density the Files tree wants.+ Row height and label size match the sidebar NavItem (36px / 14px). */+ --trees-font-size-override: ${DOCUMENT_TREE_LAYOUT.fontSize}px;+ --trees-level-gap-override: ${DOCUMENT_TREE_LAYOUT.levelGap}px;+ --trees-item-row-gap-override: ${DOCUMENT_TREE_LAYOUT.iconGap}px;+ --trees-item-padding-x-override: 8px;+ --trees-item-margin-x-override: 4px;+ --trees-padding-inline-override: 4px;+ --trees-border-radius-override: 8px;++ /* Consumed by DOCUMENT_TREE_ICON_CSS inside the shadow root. */+ --explorer-tree-icon-fg: ${cssVar.colorTextDescription};+`,}));@@ -140,11 +171,25 @@ const DocumentExplorerTree = memo<Props>(({ agentId, data, mutate, onOpenDocumen})),[documents, resolveNodeName, resolveParentRowId],);+ // pierre's truncation marker masks the characters it overlays with this color;+ // it has to be whatever the surrounding panel paints (see usePanelBackground).+ const panelBackground = usePanelBackground(containerRef, DEFAULT_PANEL_BACKGROUND);+const treeStyleVars = useMemo(- () => getExplorerTreeStyleVars({ reserveChevronSlot: nodes.some((node) => node.isFolder) }),+ () =>+ getExplorerTreeStyleVars({+ iconWidth: DOCUMENT_TREE_LAYOUT.iconWidth,+ reserveChevronSlot: nodes.some((node) => node.isFolder),+ rowGap: DOCUMENT_TREE_LAYOUT.iconGap,+ }),[nodes],);+ const treeStyle = useMemo(+ () => ({ ...style, ...treeStyleVars, '--explorer-tree-panel-bg': panelBackground }),+ [panelBackground, style, treeStyleVars],+ );+const parentMap = useMemo(() => {const map = new Map<string, string | null>();for (const doc of documents) map.set(doc.id, resolveParentRowId(doc.parentId));@@ -386,7 +431,7 @@ const DocumentExplorerTree = memo<Props>(({ agentId, data, mutate, onOpenDocumen);return (- <div className={styles.tree} ref={containerRef} style={{ ...style, ...treeStyleVars }}>+ <div className={styles.tree} ref={containerRef} style={treeStyle}>{nodes.length === 0 ? (// Keep the toolbar reachable (new folder / new doc) above the placeholder.<Flexbox height={'100%'}>@@ -404,6 +449,7 @@ const DocumentExplorerTree = memo<Props>(({ agentId, data, mutate, onOpenDocumengetContextMenuItems={getContextMenuItems}header={toolbar}iconSet="complete"+ itemHeight={DOCUMENT_TREE_LAYOUT.itemHeight}nodes={nodes}ref={treeRef}style={{ height: '100%' }}diff --git a/src/features/AgentDocumentsExplorer/usePanelBackground.ts b/src/features/AgentDocumentsExplorer/usePanelBackground.tsnew file mode 100644index 00000000000..bcf8055ecd7--- /dev/null+++ b/src/features/AgentDocumentsExplorer/usePanelBackground.ts@@ -0,0 +1,44 @@+import { type RefObject, useLayoutEffect, useState } from 'react';++const TRANSPARENT = new Set(['transparent', 'rgba(0, 0, 0, 0)']);++/**+ * Resolve the background actually painted behind a node.+ *+ * pierre's truncation marker paints the ellipsis over the characters it+ * replaces and masks them with `--truncate-marker-background-color`. The+ * document tree keeps its rows transparent so the surrounding panel shows+ * through, which leaves that mask with nothing to paint — the ellipsis lands on+ * top of the text. Feeding it the panel's own color fixes that, but the color is+ * not a constant: the documents page renders on `colorBgLayout` (#000) while the+ * conversation working sidebar renders on `colorBgContainer` (#0d0d0d), so a+ * single token leaves a visible patch on whichever surface it does not match.+ *+ * Walking up for the first non-transparent background reads whatever the current+ * host actually paints, so a third surface needs no change here. `fallback`+ * covers the case where every ancestor is transparent (nothing is painted, so+ * the mask has nothing to hide anyway).+ */+export const usePanelBackground = (+ ref: RefObject<HTMLElement | null>,+ fallback: string,+): string => {+ const [background, setBackground] = useState(fallback);++ useLayoutEffect(() => {+ let node: HTMLElement | null = ref.current;+ while (node) {+ const color = getComputedStyle(node).backgroundColor;+ if (color && !TRANSPARENT.has(color)) {+ setBackground(color);+ return;+ }+ node = node.parentElement;+ }+ setBackground(fallback);+ // The theme swaps every token at once, so re-resolve whenever the fallback+ // (itself a themed token) changes.+ }, [fallback, ref]);++ return background;+};diff --git a/src/features/ExplorerTree/documentTreeStyle.test.ts b/src/features/ExplorerTree/documentTreeStyle.test.tsnew file mode 100644index 00000000000..f7f0ec6ae74--- /dev/null+++ b/src/features/ExplorerTree/documentTreeStyle.test.ts@@ -0,0 +1,86 @@+import { readFileSync } from 'node:fs';+import { join } from 'node:path';++import { describe, expect, it } from 'vitest';++import {+ DOCUMENT_TREE_ICON_CSS,+ DOCUMENT_TREE_LAYOUT,+ DOCUMENT_TREE_ROW_CSS,+} from './documentTreeStyle';+import { FOLDER_ICON_CSS, getExplorerTreeStyleVars } from './folderIconStyle';++const MATERIAL_ASSET_HOST = '@lobehub/assets-fileicon';++// The document tree (agent documents) and the code trees (project Files, review+// diff) share one ExplorerTree component but MUST NOT share a look: documents are+// prose and get a 36px/14px monochrome outline treatment, code files keep the+// dense material icon set. These assertions are the guard rail for that split —+// they fail the moment a document-only token starts leaking into the code trees.+describe('document tree and code tree are styled independently', () => {+ it('paints the document tree with inline lucide masks, never the material sprite set', () => {+ expect(DOCUMENT_TREE_ICON_CSS).toContain('mask-image');+ expect(DOCUMENT_TREE_ICON_CSS).toContain('data:image/svg+xml');+ // No CDN sprite lookups at all — a document row must not depend on the+ // material asset package.+ expect(DOCUMENT_TREE_ICON_CSS).not.toContain(MATERIAL_ASSET_HOST);+ expect(DOCUMENT_TREE_ICON_CSS).not.toContain('background-image');+ });++ it('keeps the code tree on the material sprite set with no document overrides', () => {+ expect(FOLDER_ICON_CSS).toContain(MATERIAL_ASSET_HOST);+ expect(FOLDER_ICON_CSS).toContain('folder-open.svg');+ // Document-only presentation must not reach the Files / Review trees.+ expect(FOLDER_ICON_CSS).not.toContain('mask-image');+ expect(FOLDER_ICON_CSS).not.toContain('--explorer-tree-icon-fg');+ expect(FOLDER_ICON_CSS).not.toContain('data-truncate-segment-priority');+ expect(FOLDER_ICON_CSS).not.toContain('font-weight');+ });++ it('confines the row treatment (folder weight, focus ring, trailing ellipsis) to the document tree', () => {+ expect(DOCUMENT_TREE_ROW_CSS).toContain('font-weight: 500');+ expect(DOCUMENT_TREE_ROW_CSS).toContain('data-truncate-segment-priority');+ expect(DOCUMENT_TREE_ROW_CSS).toContain('outline: none');+ expect(FOLDER_ICON_CSS).not.toContain(DOCUMENT_TREE_ROW_CSS.trim());+ });++ it('leaves the code trees on pierre defaults for the reserved icon column', () => {+ // Files / Review call getExplorerTreeStyleVars with no metrics; the document+ // tree passes its own. Widening the document gap must not move theirs.+ expect(getExplorerTreeStyleVars({ reserveChevronSlot: true })).toEqual({+ '--explorer-file-icon-offset': '22px',+ });+ expect(+ getExplorerTreeStyleVars({+ iconWidth: DOCUMENT_TREE_LAYOUT.iconWidth,+ reserveChevronSlot: true,+ rowGap: DOCUMENT_TREE_LAYOUT.iconGap,+ }),+ ).toEqual({ '--explorer-file-icon-offset': '24px' });+ });+});++// Reading the call sites keeps this honest: asserting on the constants alone+// would still pass if a code tree started importing the document bundle.+describe('code tree call sites', () => {+ const read = (relativePath: string) =>+ readFileSync(join(__dirname, '..', '..', '..', 'src', relativePath), 'utf8');++ const CODE_TREE_FILES = [+ 'features/Conversation/WorkingSidebar/Files/index.tsx',+ 'features/Conversation/WorkingSidebar/Review/FileTreeNav.tsx',+ ];++ it.each(CODE_TREE_FILES)('%s renders with FOLDER_ICON_CSS and no document tokens', (file) => {+ const source = read(file);+ expect(source).toContain('FOLDER_ICON_CSS');+ expect(source).not.toContain('DOCUMENT_TREE_ICON_CSS');+ expect(source).not.toContain('DOCUMENT_TREE_ROW_CSS');+ expect(source).not.toContain('DOCUMENT_TREE_LAYOUT');+ // They keep their own pre-existing 12px label and pierre's default 30px row+ // (no `itemHeight` prop) — that is what "文件的那个 tree 渲染保留原样" means.+ // The document tree's 14px / 36px must never reach them.+ expect(source).toContain('--trees-font-size-override: 12px');+ expect(source).not.toContain('itemHeight');+ });+});diff --git a/src/features/ExplorerTree/documentTreeStyle.ts b/src/features/ExplorerTree/documentTreeStyle.tsnew file mode 100644index 00000000000..1f680f39094--- /dev/null+++ b/src/features/ExplorerTree/documentTreeStyle.ts@@ -0,0 +1,168 @@+import { FILE_ICON_OFFSET_VAR, HIDE_FILE_SLOT_SVG_CSS, svgMaskUrl } from './folderIconStyle';++// Layout + icon + hierarchy styling for the document-facing tree (agent+// documents explorer). The code trees (project Files, review diff) intentionally+// stay IDE-dense and keep the colored material icon set, so these tokens live+// apart from pierre's defaults rather than overriding `--trees-*` globally.++export const DOCUMENT_TREE_LAYOUT = {+ /** Gap between the icon slot and the label — also the guide/indent rhythm. */+ iconGap: 8,+ /** Both glyphs render at this size so a folder never reads heavier than a file. */+ iconSize: 16,+ /** Matches pierre's `--trees-icon-width` default; kept explicit so the+ * reserved file-icon offset can be derived from the same number. */+ iconWidth: 16,+ /** Row height and label size are the sidebar `NavItem`'s (36px / 14px), so a+ * document row and a nav row read as the same kind of list item. */+ itemHeight: 36,+ fontSize: 14,+ /** Horizontal step per nesting level. The rendered step is this plus pierre's+ * own per-level padding, so 8 lands each level ~23.5px in. */+ levelGap: 8,+} as const;++// Both glyphs are lucide outlines at the same stroke weight, painted as CSS+// masks so they inherit one themed color. The material folder sprites the code+// trees use are filled and multi-colored — next to a monochrome outline file+// glyph a folder row reads as a much heavier object than its own children,+// which is the wrong hierarchy signal for a document outline.+const STROKE =+ 'fill="none" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"';+const svg = (paths: string) =>+ `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" ${STROKE}>${paths}</svg>`;++// lucide `file-text`, matched to the Pages (文稿) list item icon so document+// rows read as manuscripts rather than generic files.+const FILE_TEXT_ICON_SVG = svg(+ '<path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/>',+);++// lucide `folder` / `folder-open`.+const FOLDER_ICON_SVG = svg(+ '<path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/>',+);+const FOLDER_OPEN_ICON_SVG = svg(+ '<path d="m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"/>',+);++const ICON_FG_VAR = '--explorer-tree-icon-fg';+const { iconGap, iconSize } = DOCUMENT_TREE_LAYOUT;++const maskGlyph = (glyph: string) => `+ background-color: var(${ICON_FG_VAR}, currentColor);+ -webkit-mask-image: ${svgMaskUrl(glyph)};+ -webkit-mask-position: center;+ -webkit-mask-repeat: no-repeat;+ -webkit-mask-size: ${iconSize}px ${iconSize}px;+ mask-image: ${svgMaskUrl(glyph)};+ mask-position: center;+ mask-repeat: no-repeat;+ mask-size: ${iconSize}px ${iconSize}px;+`;++export const DOCUMENT_TREE_ICON_CSS = `+ [data-item-type='folder'] [data-item-section='content'] {+ display: flex;+ align-items: center;+ }++ /* The chevron owns the icon slot on a folder row, so the folder glyph is+ painted as the label's ::before. Its trailing gap matches the row gap the+ file glyph gets, so both kinds of row have the same glyph→label rhythm. */+ [data-item-type='folder'] [data-item-section='content']::before {+ content: '';+ flex: 0 0 auto;+ width: ${iconSize}px;+ height: ${iconSize}px;+ margin-inline-end: ${iconGap}px;+${maskGlyph(FOLDER_ICON_SVG)} }++ [data-item-type='folder'][aria-expanded='true'] [data-item-section='content']::before {+${maskGlyph(FOLDER_OPEN_ICON_SVG)} }++ [data-item-type='file'] > [data-item-section='icon'] {+ margin-inline-start: var(${FILE_ICON_OFFSET_VAR}, 0px);+${maskGlyph(FILE_TEXT_ICON_SVG)} }++${HIDE_FILE_SLOT_SVG_CSS}+`;++// A row already reads as current from its filled background, so the outline+// pierre paints on the focused row is redundant chrome — a stray 1px ring around+// whichever row was last clicked. Drop it in every state, including+// :focus-visible: pierre marks a row focus-visible after a plain mouse click, so+// gating on that still leaves the ring the user sees.+//+// Keyboard focus must stay visible without it. A focused row that is not also+// selected carries no background of its own, so give it the hover fill —+// arrowing through the tree then reads the same way hovering it does.+const DOCUMENT_TREE_NO_FOCUS_BORDER_CSS = `+ [data-type='item'][data-item-focused='true']::before,+ [data-type='item']:focus-visible::before {+ outline: none;+ }++ [data-type='item'][data-item-focused='true']:not([data-item-selected='true']) {+ background-color: var(--trees-bg-muted);+ }+`;++// pierre truncates every row with `MiddleTruncate split:"extension"` and no way+// to configure it (FileTreeView hard-codes it; FileTreeOptions has no field for+// truncation). The stem is rendered as a shrink-first segment and the extension+// as a shrink-last one, so a long title collapses to `…承载md` — the ellipsis+// lands mid-word and the extension survives, which is backwards for a document+// outline where the title is the content and `.md` is storage detail.+//+// The split itself is only a flex priority in pierre's own stylesheet, so+// swapping the two priorities is enough: the stem now holds its width and the+// extension collapses to its own leading marker, which renders as one trailing+// ellipsis. A title that fits is untouched — both halves render in full.+const DOCUMENT_TREE_TRAILING_ELLIPSIS_CSS = `+ [data-item-section='content'] [data-truncate-group-container='middle'] {+ & > div[data-truncate-segment-priority='1'] {+ flex: 0 999999 max-content;+ }++ & > div[data-truncate-segment-priority='2'] {+ flex: 0 1 max-content;+ }+ }++ /* The swap leaves a narrow band where the overflow is smaller than the+ extension: it then shrinks to a few pixels and, being right-aligned, leaks+ its last character ("…研究报告 d"). pierre's own overflow query fires on that+ segment, so stretch its marker across the segment — the marker is opaque and+ sits above the text, so a partially rendered extension is covered rather+ than half-shown. A fully collapsed one is zero-wide and stays invisible. */+ @container measure (height > 1lh) {+ [data-item-section='content'] [data-truncate-container='fruncate'] [data-truncate-marker] {+ inset: 0;+ justify-content: flex-start;+ }+ }++ /* pierre paints the marker over the last characters and masks them with+ --truncate-marker-background-color, which defaults to --trees-bg. These rows+ are transparent so the panel shows through, and the ellipsis ended up drawn+ on top of the text. Point the marker at the panel's own background so it+ masks again, without giving the rows an opaque fill of their own. */+ [data-type='item'] {+ --truncate-marker-background-color: var(--explorer-tree-panel-bg, transparent);+ }++`;++// Row presentation for the document tree. Nesting is carried by indentation+// alone — no indent guides — with folder rows a little heavier so a parent still+// reads as a parent once its children have scrolled it out of view. Every label+// keeps the primary text color: a document row is a destination, not chrome.+export const DOCUMENT_TREE_ROW_CSS = `+ [data-item-type='folder'] > [data-item-section='content'] {+ font-weight: 500;+ }++${DOCUMENT_TREE_NO_FOCUS_BORDER_CSS}+${DOCUMENT_TREE_TRAILING_ELLIPSIS_CSS}+`;diff --git a/src/features/ExplorerTree/folderIconStyle.test.ts b/src/features/ExplorerTree/folderIconStyle.test.tsindex b443bb3843f..d2584f60ade 100644--- a/src/features/ExplorerTree/folderIconStyle.test.ts+++ b/src/features/ExplorerTree/folderIconStyle.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest';-import { getExplorerTreeIconCSS } from './folderIconStyle';+import { getExplorerTreeIconCSS, getExplorerTreeStyleVars } from './folderIconStyle';describe('getExplorerTreeIconCSS', () => {it('maps ico files to the image icon', () => {@@ -13,3 +13,24 @@ describe('getExplorerTreeIconCSS', () => {expect(css).toMatch(icoImageRule);});});++describe('getExplorerTreeStyleVars', () => {+ it('reserves the chevron column from pierre defaults when no metrics are given', () => {+ expect(getExplorerTreeStyleVars({ reserveChevronSlot: true })).toEqual({+ '--explorer-file-icon-offset': '22px',+ });+ });++ it('widens the reserved offset for trees that widen the icon gap', () => {+ // The document tree runs a 8px row gap, so files must clear 16 + 8.+ expect(+ getExplorerTreeStyleVars({ iconWidth: 16, reserveChevronSlot: true, rowGap: 8 }),+ ).toEqual({ '--explorer-file-icon-offset': '24px' });+ });++ it('claims no offset when the tree has no folders', () => {+ expect(getExplorerTreeStyleVars({ reserveChevronSlot: false, rowGap: 8 })).toEqual({+ '--explorer-file-icon-offset': '0px',+ });+ });+});diff --git a/src/features/ExplorerTree/folderIconStyle.ts b/src/features/ExplorerTree/folderIconStyle.tsindex 97a5301c9ee..f37e2218711 100644--- a/src/features/ExplorerTree/folderIconStyle.ts+++ b/src/features/ExplorerTree/folderIconStyle.ts@@ -6,20 +6,15 @@ import type { CSSProperties } from 'react';// the file-icon offset through a CSS custom property the wrapper sets — custom// properties cascade through shadow DOM, so toggling it on the host reflows// the offset live (see `getExplorerTreeStyleVars`).-const FILE_ICON_OFFSET_VAR = '--explorer-file-icon-offset';+export const FILE_ICON_OFFSET_VAR = '--explorer-file-icon-offset';const FOLDER_ICON_SIZE = '18px';const FILE_ICON_SIZE = '16px';-// Chevron column width + row gap at default density (16 + 6). We standardised-// consumers on default density, so this matches `--trees-icon-width` +-// `--trees-item-row-gap` exactly.-const RESERVED_FILE_ICON_OFFSET = '22px';--// Lucide `file-text` glyph (v1.17.0), matched to the Pages (文稿) list item icon-// so document rows read as manuscripts rather than generic files. Painted as a-// CSS mask (not a background-image) so the slot inherits the themed tree-// foreground color instead of the colored material `file.svg`.-const FILE_TEXT_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/></svg>`;+// The file-icon slot has to clear the folder chevron column, i.e.+// `--trees-icon-width` + `--trees-item-row-gap`. These are pierre's defaults at+// default density; trees that widen either (the document tree) pass their own.+const DEFAULT_ICON_WIDTH = 16;+const DEFAULT_ITEM_ROW_GAP = 6;const MATERIAL_FILE_ICON_ASSETS_URL = genCdnUrl({path: 'assets',@@ -120,7 +115,7 @@ const cssString = (value: string) => value.replaceAll('\\', '\\\\').replaceAll('const cssUrl = (url: string) => `url("${cssString(url)}")`;-const svgMaskUrl = (svg: string) => `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;+export const svgMaskUrl = (svg: string) => `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;const iconUrl = (iconsUrl: string, iconName: string, open = false) =>`${iconsUrl}/${iconName}${open ? '-open' : ''}.svg`;@@ -213,7 +208,7 @@ ${MATERIAL_FILE_PREFIX_RULES.map(({ iconName, prefixes }) =>// pierre renders its own <svg> in the file icon slot; we paint the material /// 文稿 glyph over it, so hide the built-in one.-const HIDE_FILE_SLOT_SVG_CSS = `+export const HIDE_FILE_SLOT_SVG_CSS = `[data-item-type="file"] > [data-item-section="icon"] > svg {visibility: hidden;}@@ -254,25 +249,6 @@ ${HIDE_FILE_SLOT_SVG_CSS}${getFileIconRules(iconsUrl)}`;-// Every row in the agent documents tree is a manuscript, so paint the file slot-// with the shared 文稿 glyph (themed, monochrome) instead of extension-specific-// material icons.-const DOCUMENT_FILE_ICON_CSS = `- [data-item-type="file"] > [data-item-section="icon"] {- margin-inline-start: var(${FILE_ICON_OFFSET_VAR}, 0px);- background-color: var(--trees-fg-override, currentColor);- -webkit-mask-image: ${svgMaskUrl(FILE_TEXT_ICON_SVG)};- -webkit-mask-position: center;- -webkit-mask-repeat: no-repeat;- -webkit-mask-size: ${FILE_ICON_SIZE} ${FILE_ICON_SIZE};- mask-image: ${svgMaskUrl(FILE_TEXT_ICON_SVG)};- mask-position: center;- mask-repeat: no-repeat;- mask-size: ${FILE_ICON_SIZE} ${FILE_ICON_SIZE};- }-${HIDE_FILE_SLOT_SVG_CSS}-`;-export const getExplorerTreeIconCSS = (iconsUrl = MATERIAL_FILE_ICON_ASSETS_URL) => `${getFolderIconCSS(iconsUrl)}${getMaterialFileIconCSS(iconsUrl)}@@ -280,13 +256,6 @@ ${getMaterialFileIconCSS(iconsUrl)}export const FOLDER_ICON_CSS = getExplorerTreeIconCSS();-// Folder rows keep their material icons; file rows use the 文稿 glyph. Used by-// the agent documents tree only — the project Files tree keeps FOLDER_ICON_CSS.-export const DOCUMENT_TREE_ICON_CSS = `-${getFolderIconCSS(MATERIAL_FILE_ICON_ASSETS_URL)}-${DOCUMENT_FILE_ICON_CSS}-`;-// Tree rows are pointer targets, not prose: allowing text selection lets a// drag-select swallow the row so a subsequent right-click hits the browser's// native selection menu instead of our context menu. Disable selection on rows@@ -316,10 +285,14 @@ export const HIDE_POINTER_FOCUS_RING_CSS = ``;export const getExplorerTreeStyleVars = ({+ iconWidth = DEFAULT_ICON_WIDTH,reserveChevronSlot,+ rowGap = DEFAULT_ITEM_ROW_GAP,}: {+ iconWidth?: number;reserveChevronSlot: boolean;+ rowGap?: number;}): CSSProperties =>({- [FILE_ICON_OFFSET_VAR]: reserveChevronSlot ? RESERVED_FILE_ICON_OFFSET : '0px',+ [FILE_ICON_OFFSET_VAR]: reserveChevronSlot ? `${iconWidth + rowGap}px` : '0px',}) as CSSProperties;diff --git a/src/features/ExplorerTree/index.tsx b/src/features/ExplorerTree/index.tsxindex 858e557819b..2e2452f4dea 100644--- a/src/features/ExplorerTree/index.tsx+++ b/src/features/ExplorerTree/index.tsx@@ -1,6 +1,10 @@export {- DISABLE_ROW_TEXT_SELECTION_CSS,DOCUMENT_TREE_ICON_CSS,+ DOCUMENT_TREE_LAYOUT,+ DOCUMENT_TREE_ROW_CSS,+} from './documentTreeStyle';+export {+ DISABLE_ROW_TEXT_SELECTION_CSS,FOLDER_ICON_CSS,getExplorerTreeStyleVars,HIDE_POINTER_FOCUS_RING_CSS,