🤯 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
⚡️ perf(device): stop skill directory recursion at SKILL.md (#23512)
AmAzing-a09a54f41f58
diff --git a/apps/desktop/src/main/controllers/__tests__/WorkspaceCtr.test.ts b/apps/desktop/src/main/controllers/__tests__/WorkspaceCtr.test.tsindex ecbb970454e..293313d6532 100644--- a/apps/desktop/src/main/controllers/__tests__/WorkspaceCtr.test.ts+++ b/apps/desktop/src/main/controllers/__tests__/WorkspaceCtr.test.ts@@ -1,3 +1,5 @@+import type * as NodeOs from 'node:os';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { type App } from '@/core/App';@@ -15,6 +17,11 @@ vi.mock('electron', () => ({},}));+vi.mock('node:os', async (importOriginal) => ({+ ...(await importOriginal<typeof NodeOs>()),+ homedir: () => '/device-home',+}));+vi.mock('node:fs/promises', () => ({readFile: vi.fn(),readdir: vi.fn(),@@ -72,9 +79,7 @@ describe('WorkspaceCtr', () => {it('merges skills from both sources and reads instruction files', async () => {vi.mocked(mockFsPromises.readdir).mockImplementation(async (dir: string) => {if (dir === '/proj/.agents/skills') return [dirent('spa-routes', 'dir')];- if (dir === '/proj/.agents/skills/spa-routes') return [dirent('SKILL.md', 'file')];if (dir === '/proj/.claude/skills') return [dirent('reviewer', 'dir')];- if (dir === '/proj/.claude/skills/reviewer') return [dirent('SKILL.md', 'file')];throw new Error('ENOENT');});vi.mocked(mockFsPromises.readFile).mockImplementation(async (file: string) => {@@ -90,6 +95,14 @@ describe('WorkspaceCtr', () => {const result = await workspaceCtr.initWorkspace({ scope: '/proj' });expect(result.skills.map((s) => s.name)).toEqual(['reviewer', 'spa-routes']);+ expect(mockFsPromises.readdir).not.toHaveBeenCalledWith(+ '/proj/.agents/skills/spa-routes',+ expect.anything(),+ );+ expect(mockFsPromises.readdir).not.toHaveBeenCalledWith(+ '/proj/.claude/skills/reviewer',+ expect.anything(),+ );expect(result.instructions).toEqual([{ content: '# Agents', path: '/proj/AGENTS.md', source: 'AGENTS.md' },{ content: '# Claude', path: '/proj/CLAUDE.md', source: 'CLAUDE.md' },@@ -102,7 +115,6 @@ describe('WorkspaceCtr', () => {vi.mocked(mockFsPromises.readdir).mockImplementation(async (dir: string) => {if (dir === '/proj/.agents/skills') return [dirent('shared', 'dir')];if (dir === '/proj/.claude/skills') return [dirent('shared', 'dir')];- if (dir.endsWith('/shared')) return [dirent('SKILL.md', 'file')];throw new Error('ENOENT');});vi.mocked(mockFsPromises.readFile).mockImplementation(async (file: string) => {@@ -125,12 +137,8 @@ describe('WorkspaceCtr', () => {it('merges execution-device skills and keeps project skills first on duplicate names', async () => {vi.mocked(mockFsPromises.readdir).mockImplementation(async (dir: string) => {if (dir === '/proj/.agents/skills') return [dirent('shared', 'dir')];- if (dir === '/proj/.agents/skills/shared') return [dirent('SKILL.md', 'file')];if (dir === '/device-home/.agents/skills')return [dirent('device-writer', 'dir'), dirent('shared', 'dir')];- if (dir === '/device-home/.agents/skills/device-writer')- return [dirent('SKILL.md', 'file')];- if (dir === '/device-home/.agents/skills/shared') return [dirent('SKILL.md', 'file')];throw new Error('ENOENT');});vi.mocked(mockFsPromises.readFile).mockImplementation(async (file: string) => {@@ -188,7 +196,6 @@ describe('WorkspaceCtr', () => {it('returns the first source with skills (.agents/skills wins) and ignores .claude', async () => {vi.mocked(mockFsPromises.readdir).mockImplementation(async (dir: string) => {if (dir === '/proj/.agents/skills') return [dirent('alpha', 'dir')];- if (dir === '/proj/.agents/skills/alpha') return [dirent('SKILL.md', 'file')];throw new Error('ENOENT');});vi.mocked(mockFsPromises.readFile).mockResolvedValue(frontmatter('alpha', 'A'));@@ -202,7 +209,6 @@ describe('WorkspaceCtr', () => {it('parses folded block scalar descriptions', async () => {vi.mocked(mockFsPromises.readdir).mockImplementation(async (dir: string) => {if (dir === '/proj/.agents/skills') return [dirent('agent-testing', 'dir')];- if (dir === '/proj/.agents/skills/agent-testing') return [dirent('SKILL.md', 'file')];throw new Error('ENOENT');});vi.mocked(mockFsPromises.readFile).mockResolvedValue(diff --git a/apps/server/src/services/deviceGateway/index.projectFiles.test.ts b/apps/server/src/services/deviceGateway/index.projectFiles.test.tsindex 67194e03315..3109eaba55a 100644--- a/apps/server/src/services/deviceGateway/index.projectFiles.test.ts+++ b/apps/server/src/services/deviceGateway/index.projectFiles.test.ts@@ -19,8 +19,6 @@ const createReadProjectFileInput = () => ({const createProjectSkillItem = () => ({description: 'spa',- fileCount: 3,- files: ['SKILL.md'],name: 'spa-routes',path: '/proj/.agents/skills/spa-routes/SKILL.md',previewRoot: '/proj',@@ -71,8 +69,6 @@ describe('DeviceGateway', () => {createProjectSkillItem(),{description: 'device',- fileCount: 2,- files: ['SKILL.md', 'refs.md'],name: 'device-writer',path: '/home/.agents/skills/device-writer/SKILL.md',previewRoot: '/home/.agents/skills',diff --git a/packages/device-control/src/__tests__/workspace.test.ts b/packages/device-control/src/__tests__/workspace.test.tsindex 2e02f870008..c179595472d 100644--- a/packages/device-control/src/__tests__/workspace.test.ts+++ b/packages/device-control/src/__tests__/workspace.test.ts@@ -219,4 +219,28 @@ describe('listProjectSkills', () => {]);expect(approveProjectRoot).toHaveBeenCalledWith(path.join(repo, '.agents', 'skills'));});++ it('stops at SKILL.md without traversing subdirectories inside a skill directory', async () => {+ const repo = path.join(base, 'repo');+ const skillDir = path.join(repo, '.agents', 'skills', 'lobe-design');+ await mkdir(path.join(repo, '.git'), { recursive: true });+ await writeSkill(path.join(repo, '.agents', 'skills'), 'lobe-design');+ await write(path.join(skillDir, 'references', 'rules.md'), '# rules');+ await write(path.join(skillDir, 'scripts', 'route.mjs'), 'export default {}');++ const result = await listProjectSkills({ scope: repo });++ expect(result.skills).toEqual([+ {+ description: 'lobe-design skill',+ disableModelInvocation: false,+ name: 'lobe-design',+ path: path.join(skillDir, 'SKILL.md'),+ previewRoot: repo,+ scope: 'project',+ skillDir,+ source: '.agents/skills',+ },+ ]);+ });});diff --git a/packages/device-control/src/types.ts b/packages/device-control/src/types.tsindex b827f5aa21b..37d3c6a5a36 100644--- a/packages/device-control/src/types.ts+++ b/packages/device-control/src/types.ts@@ -17,10 +17,6 @@ export interface ProjectSkillItem {description?: string;/** SKILL.md declares that the model must not invoke this skill automatically. */disableModelInvocation?: boolean;- /** Total number of regular files under `skillDir` (recursive, including `SKILL.md`). */- fileCount: number;- /** Relative paths (within `skillDir`) of all regular files, sorted, capped. */- files: string[];name: string;/** Absolute path to the SKILL.md file. */path: string;diff --git a/packages/device-control/src/workspace.ts b/packages/device-control/src/workspace.tsindex 31b245dd0a9..25a9b4416da 100644--- a/packages/device-control/src/workspace.ts+++ b/packages/device-control/src/workspace.ts@@ -21,8 +21,6 @@ import type {WorkspaceScanDeps,} from './types';-// Cap recursion to guard against pathological directory trees.-const MAX_SKILL_FILE_COUNT = 1000;const DEFAULT_DIRECTORY_PAGE_SIZE = 200;const MAX_DIRECTORY_PAGE_SIZE = 1000;@@ -122,34 +120,6 @@ const createSkillRoots = async (root: string): Promise<SkillScanRoot[]> => [...createDeviceSkillRoots(),];-const toPosixRelativePath = (filePath: string) => filePath.split(path.sep).join('/');--const listSkillFilesRecursive = async (dir: string): Promise<string[]> => {- const results: string[] = [];- const stack: string[] = [dir];-- while (stack.length > 0 && results.length < MAX_SKILL_FILE_COUNT) {- const current = stack.pop()!;- let entries;- try {- entries = await readdir(current, { withFileTypes: true });- } catch {- continue;- }- for (const entry of entries) {- if (entry.name.startsWith('.')) continue;- const full = path.join(current, entry.name);- if (entry.isDirectory()) {- stack.push(full);- } else if (entry.isFile()) {- results.push(toPosixRelativePath(path.relative(dir, full)));- if (results.length >= MAX_SKILL_FILE_COUNT) break;- }- }- }- return results.sort();-};-interface SkillFrontmatterFields {description?: string;disableModelInvocation?: boolean;@@ -180,7 +150,9 @@ const parseSkillFrontmatter = (raw: string): SkillFrontmatterFields => {/*** Scan one skill source directory and return parsed frontmatter for each- * `SKILL.md`. Returns `[]` when the source directory is absent or unreadable.+ * `SKILL.md`. Once a directory contains `SKILL.md`, treat it as a skill root+ * and do not recurse into its subdirectories (`scripts/`, `references/`, etc.).+ * Returns `[]` when the source directory is absent or unreadable.* Unsorted — callers sort/merge.*/const scanSkillsInSource = async ({@@ -198,19 +170,18 @@ const scanSkillsInSource = async ({const skills = await Promise.all(entries- .filter((entry) => entry.isDirectory() || entry.isSymbolicLink())+ .filter(+ (entry) => !entry.name.startsWith('.') && (entry.isDirectory() || entry.isSymbolicLink()),+ ).map(async (entry): Promise<ProjectSkillItem | null> => {const skillDir = path.join(sourceRoot, entry.name);const skillFile = path.join(skillDir, 'SKILL.md');try {const raw = await readFile(skillFile, 'utf8');const fields = parseSkillFrontmatter(raw);- const files = await listSkillFilesRecursive(skillDir);return {description: fields.description || undefined,disableModelInvocation: fields.disableModelInvocation,- fileCount: files.length,- files,name: fields.name || entry.name,path: skillFile,previewRoot,diff --git a/packages/electron-client-ipc/src/types/localSystem.ts b/packages/electron-client-ipc/src/types/localSystem.tsindex 0119a263add..8e34488764e 100644--- a/packages/electron-client-ipc/src/types/localSystem.ts+++ b/packages/electron-client-ipc/src/types/localSystem.ts@@ -773,13 +773,6 @@ export interface ProjectSkillItem {description?: string;/** SKILL.md declares that the model must not invoke this skill automatically. */disableModelInvocation?: boolean;- /** Total number of regular files under `skillDir` (recursive, including `SKILL.md`). */- fileCount: number;- /**- * Relative paths (within `skillDir`) of all regular files under the skill,- * sorted lexicographically and capped to a safe maximum. Includes `SKILL.md`.- */- files: string[];name: string;/** Absolute path to the SKILL.md file. */path: string;diff --git a/packages/types/src/device.ts b/packages/types/src/device.tsindex 8dc54c4657b..89804b2d7ff 100644--- a/packages/types/src/device.ts+++ b/packages/types/src/device.ts@@ -871,8 +871,6 @@ export interface DeviceTrashProjectFilesResult {*/export interface DeviceProjectSkillItem {description?: string;- fileCount: number;- files: string[];name: string;/** Absolute path to the SKILL.md file on the device. */path: string;diff --git a/src/features/SkillsList/useProjectSkills.test.ts b/src/features/SkillsList/useProjectSkills.test.tsindex 5f0f5df9d3e..57e256e561e 100644--- a/src/features/SkillsList/useProjectSkills.test.ts+++ b/src/features/SkillsList/useProjectSkills.test.ts@@ -46,8 +46,6 @@ const wrapper = ({ children }: PropsWithChildren) =>);const skill = (name: string): ProjectSkillItem => ({- fileCount: 1,- files: ['SKILL.md'],name,path: `/repo/.agents/skills/${name}/SKILL.md`,previewRoot: '/repo',diff --git a/src/features/SkillsList/useProjectSkills.ts b/src/features/SkillsList/useProjectSkills.tsindex e43a8b99330..92edab61164 100644--- a/src/features/SkillsList/useProjectSkills.ts+++ b/src/features/SkillsList/useProjectSkills.ts@@ -60,7 +60,6 @@ export const useProjectSkills = (() =>(data?.skills ?? []).map((skill) => ({description: skill.description,- files: skill.files,id: skill.skillDir,name: skill.name,scope: skill.scope,diff --git a/src/store/tool/slices/projectSkills/action.test.ts b/src/store/tool/slices/projectSkills/action.test.tsindex cf727bca823..33dfcb4ede3 100644--- a/src/store/tool/slices/projectSkills/action.test.ts+++ b/src/store/tool/slices/projectSkills/action.test.ts@@ -43,14 +43,12 @@ const wrapper = ({ children }: PropsWithChildren) =>);const skill = (name: string): ProjectSkillItem => ({- fileCount: 1,- files: ['SKILL.md'],name,path: `/repo/.agents/skills/${name}/SKILL.md`,previewRoot: '/repo',scope: 'project',skillDir: `/repo/.agents/skills/${name}`,- source: 'agents',+ source: '.agents/skills',});const scan = (...names: string[]): ListProjectSkillsResult => ({diff --git a/src/store/tool/slices/projectSkills/projection.ts b/src/store/tool/slices/projectSkills/projection.tsindex 6fc79dfd761..bcff2c0ba0a 100644--- a/src/store/tool/slices/projectSkills/projection.ts+++ b/src/store/tool/slices/projectSkills/projection.ts@@ -10,9 +10,8 @@ export interface ProjectSkillsParams {}/**- * How many scans stay persisted per scope. Each scan carries every skill's file- * list (capped by the scanner), so only the recently opened device + directory- * pairs are kept; the one on screen is pinned by its mounted `useSync`.+ * How many scans stay persisted per scope. Only the recently opened device ++ * directory pairs are kept; the one on screen is pinned by its mounted `useSync`.*/export const MAX_PERSISTED_PROJECT_SKILL_SCANS = 20;