🤯 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
♻️ refactor(server): prevent writing useless metadata into documents for agent signal managed skills (#14291)
Neko8830c6d560ec
diff --git a/src/server/routers/lambda/__tests__/integration/agentSkills.integration.test.ts b/src/server/routers/lambda/__tests__/integration/agentSkills.integration.test.tsindex be272e244c1..a91bf796074 100644--- a/src/server/routers/lambda/__tests__/integration/agentSkills.integration.test.ts+++ b/src/server/routers/lambda/__tests__/integration/agentSkills.integration.test.ts@@ -102,23 +102,35 @@ describe('Skill Router Integration Tests', () => {const getManagedSkillBindingId = async ({agentId,- namespace,skillName,}: {agentId: string;- namespace: 'agent';skillName: string;}) => {const documents = await agentDocumentModel.findByAgent(agentId);+ const root = documents.find(+ (item) =>+ item.fileType === 'custom/folder' &&+ item.filename === 'skills' &&+ item.parentId === null &&+ item.templateId === 'agent-skill',+ );+ const folder = documents.find(+ (item) =>+ item.fileType === 'custom/folder' &&+ item.filename === skillName &&+ item.parentId === root?.documentId &&+ item.templateId === 'agent-skill',+ );const document = documents.find((item) =>item.filename === 'SKILL.md' &&- item.metadata?.lobeSkill?.namespace === namespace &&- item.metadata?.lobeSkill?.skillName === skillName,+ item.parentId === folder?.documentId &&+ item.templateId === 'agent-skill',);if (!document) {- throw new Error(`Expected managed skill document ${namespace}:${skillName} to exist`);+ throw new Error(`Expected managed skill document agent:${skillName} to exist`);}return document.id;@@ -596,7 +608,6 @@ describe('Skill Router Integration Tests', () => {const id = await getManagedSkillBindingId({agentId,- namespace: 'agent',skillName: 'research-helper',});@@ -623,7 +634,6 @@ describe('Skill Router Integration Tests', () => {const id = await getManagedSkillBindingId({agentId,- namespace: 'agent',skillName: 'research-helper',});diff --git a/src/server/services/agentDocumentVfs/mounts/skills/providers/ProviderSkillsAgentDocument.test.ts b/src/server/services/agentDocumentVfs/mounts/skills/providers/ProviderSkillsAgentDocument.test.tsindex 21299da739b..7b4c13d710b 100644--- a/src/server/services/agentDocumentVfs/mounts/skills/providers/ProviderSkillsAgentDocument.test.ts+++ b/src/server/services/agentDocumentVfs/mounts/skills/providers/ProviderSkillsAgentDocument.test.ts@@ -34,7 +34,9 @@ const createAgentDocument = (overrides: Record<string, unknown> = {}) =>describe('Agent skill VFS providers', () => {const agentDocumentModel = {associate: vi.fn(),+ create: vi.fn(),delete: vi.fn(),+ deleteSubtreeByDocumentId: vi.fn(),findByAgent: vi.fn(),update: vi.fn(),};@@ -57,25 +59,21 @@ describe('Agent skill VFS providers', () => {fileType: 'custom/folder',filename: 'skills',id: 'agent-doc-root',- metadata: { lobeSkill: { namespace: 'agent', role: 'namespace-root' } },+ templateId: 'agent-skill',}),createAgentDocument({documentId: 'folder-1',fileType: 'custom/folder',filename: 'agent-skill',id: 'agent-doc-folder',- metadata: {- lobeSkill: { namespace: 'agent', role: 'skill-folder', skillName: 'agent-skill' },- },+ templateId: 'agent-skill',parentId: 'root-1',}),createAgentDocument({documentId: 'file-1',filename: 'SKILL.md',id: 'agent-doc-file',- metadata: {- lobeSkill: { namespace: 'agent', role: 'skill-file', skillName: 'agent-skill' },- },+ templateId: 'agent-skill',parentId: 'folder-1',}),createAgentDocument({@@ -111,32 +109,36 @@ describe('Agent skill VFS providers', () => {it('creates a tree-backed agent skill with namespace root, folder, and SKILL.md', async () => {agentDocumentModel.findByAgent.mockResolvedValue([]);- documentService.createDocument+ agentDocumentModel.create.mockResolvedValueOnce({+ documentId: 'root-1',fileType: 'custom/folder',filename: 'skills',- id: 'root-1',- metadata: { lobeSkill: { namespace: 'agent', role: 'namespace-root' } },+ id: 'agent-doc-root',+ metadata: null,parentId: null,+ templateId: 'agent-skill',title: 'skills',}).mockResolvedValueOnce({+ documentId: 'folder-1',fileType: 'custom/folder',filename: 'writer',- id: 'folder-1',- metadata: {- lobeSkill: { namespace: 'agent', role: 'skill-folder', skillName: 'writer' },- },+ id: 'agent-doc-folder',+ metadata: null,parentId: 'root-1',+ templateId: 'agent-skill',title: 'writer',}).mockResolvedValueOnce({content: '# Skill',- fileType: 'custom/document',+ documentId: 'file-1',+ fileType: 'skill/index',filename: 'SKILL.md',- id: 'file-1',- metadata: { lobeSkill: { namespace: 'agent', role: 'skill-file', skillName: 'writer' } },+ id: 'agent-doc-file',+ metadata: null,parentId: 'folder-1',+ templateId: 'agent-skill',title: 'SKILL.md',});@@ -152,41 +154,36 @@ describe('Agent skill VFS providers', () => {targetNamespace: 'agent',});- expect(documentService.createDocument).toHaveBeenNthCalledWith(1, {+ expect(agentDocumentModel.create).toHaveBeenNthCalledWith(1, 'agent-1', 'skills', '', {editorData: { root: { children: [], type: 'root' } },fileType: 'custom/folder',- metadata: { lobeSkill: { namespace: 'agent', role: 'namespace-root' } },+ policyLoad: 'disabled',+ templateId: 'agent-skill',title: 'skills',});- expect(documentService.createDocument).toHaveBeenNthCalledWith(2, {+ expect(agentDocumentModel.create).toHaveBeenNthCalledWith(2, 'agent-1', 'writer', '', {editorData: { root: { children: [], type: 'root' } },fileType: 'custom/folder',- metadata: { lobeSkill: { namespace: 'agent', role: 'skill-folder', skillName: 'writer' } },parentId: 'root-1',- title: 'writer',- });- expect(documentService.createDocument).toHaveBeenNthCalledWith(3, {- content: '# Skill',- editorData: { markdown: '# Skill' },- fileType: 'skill/index',- metadata: { lobeSkill: { namespace: 'agent', role: 'skill-file', skillName: 'writer' } },- parentId: 'folder-1',- title: 'SKILL.md',- });- expect(agentDocumentModel.associate).toHaveBeenNthCalledWith(1, {- agentId: 'agent-1',- documentId: 'root-1',- policyLoad: 'disabled',- });- expect(agentDocumentModel.associate).toHaveBeenNthCalledWith(2, {- agentId: 'agent-1',- documentId: 'folder-1',policyLoad: 'disabled',+ templateId: 'agent-skill',+ title: 'writer',});- expect(agentDocumentModel.associate).toHaveBeenNthCalledWith(3, {- agentId: 'agent-1',- documentId: 'file-1',- });+ expect(agentDocumentModel.create).toHaveBeenNthCalledWith(+ 3,+ 'agent-1',+ 'SKILL.md',+ '# Skill',+ {+ editorData: { markdown: '# Skill' },+ fileType: 'skill/index',+ parentId: 'folder-1',+ templateId: 'agent-skill',+ title: 'SKILL.md',+ },+ );+ expect(documentService.createDocument).not.toHaveBeenCalled();+ expect(agentDocumentModel.associate).not.toHaveBeenCalled();expect(result.path).toBe('./lobe/skills/agent/skills/writer/SKILL.md');});@@ -202,28 +199,19 @@ describe('Agent skill VFS providers', () => {agentDocumentModel.findByAgent.mockResolvedValue([{documentId: 'root-doc',+ fileType: 'custom/folder',filename: 'skills',id: 'root-binding',- metadata: {- lobeSkill: {- namespace: 'agent',- role: 'namespace-root',- },- },parentId: null,+ templateId: 'agent-skill',},{documentId: 'folder-doc',+ fileType: 'custom/folder',filename: 'writer',id: 'folder-binding',- metadata: {- lobeSkill: {- namespace: 'agent',- role: 'skill-folder',- skillName: 'writer',- },- },parentId: 'root-doc',+ templateId: 'agent-skill',},] as never);@@ -248,13 +236,29 @@ describe('Agent skill VFS providers', () => {it('updates an agent skill through the document model and saves history when content changes', async () => {agentDocumentModel.findByAgent.mockResolvedValue([+ createAgentDocument({+ documentId: 'root-1',+ fileType: 'custom/folder',+ filename: 'skills',+ id: 'agent-doc-root',+ parentId: null,+ templateId: 'agent-skill',+ }),+ createAgentDocument({+ documentId: 'folder-1',+ fileType: 'custom/folder',+ filename: 'skill-a',+ id: 'agent-doc-folder',+ parentId: 'root-1',+ templateId: 'agent-skill',+ }),createAgentDocument({content: 'old content',documentId: 'file-1',filename: 'SKILL.md',id: 'agent-doc-file',- metadata: { lobeSkill: { namespace: 'agent', role: 'skill-file', skillName: 'skill-a' } },parentId: 'folder-1',+ templateId: 'agent-skill',}),]);@@ -282,22 +286,28 @@ describe('Agent skill VFS providers', () => {it('soft-deletes the folder subtree for an agent skill', async () => {agentDocumentModel.findByAgent.mockResolvedValue([+ createAgentDocument({+ documentId: 'root-1',+ fileType: 'custom/folder',+ filename: 'skills',+ id: 'agent-doc-root',+ parentId: null,+ templateId: 'agent-skill',+ }),createAgentDocument({documentId: 'folder-1',fileType: 'custom/folder',filename: 'skill-a',id: 'agent-doc-folder',- metadata: {- lobeSkill: { namespace: 'agent', role: 'skill-folder', skillName: 'skill-a' },- },parentId: 'root-1',+ templateId: 'agent-skill',}),createAgentDocument({documentId: 'file-1',filename: 'SKILL.md',id: 'agent-doc-file',- metadata: { lobeSkill: { namespace: 'agent', role: 'skill-file', skillName: 'skill-a' } },parentId: 'folder-1',+ templateId: 'agent-skill',}),]);@@ -311,7 +321,12 @@ describe('Agent skill VFS providers', () => {path: './lobe/skills/agent/skills/skill-a/SKILL.md',});- expect(documentService.deleteDocument).toHaveBeenCalledWith('folder-1');+ expect(agentDocumentModel.deleteSubtreeByDocumentId).toHaveBeenCalledWith(+ 'agent-1',+ 'folder-1',+ 'skill-delete',+ );+ expect(documentService.deleteDocument).not.toHaveBeenCalled();});});});diff --git a/src/server/services/agentDocumentVfs/mounts/skills/providers/ProviderSkillsAgentDocument.ts b/src/server/services/agentDocumentVfs/mounts/skills/providers/ProviderSkillsAgentDocument.tsindex 87fd769297b..a32d5397a94 100644--- a/src/server/services/agentDocumentVfs/mounts/skills/providers/ProviderSkillsAgentDocument.ts+++ b/src/server/services/agentDocumentVfs/mounts/skills/providers/ProviderSkillsAgentDocument.ts@@ -21,7 +21,6 @@ import {getScopedSkillDocuments,getSkillFile,getSkillFolder,- getSkillMetadata,getValidatedSkillName,listScopedSkillFolders,projectDocumentContent,@@ -45,7 +44,7 @@ const DOCUMENT_SKILL_PROVIDER_CONFIGS = {* - Serving agent-level skills from agent documents.** Expects:- * - Managed skill documents carry `metadata.lobeSkill` with namespace and role.+ * - Managed skill documents use the agent-skill template id and document tree paths.** Returns:* - Skill VFS nodes whose paths use the target unified `./lobe/skills/...` layout.@@ -94,11 +93,7 @@ export class ProviderSkillsAgentDocument implements WritableSkillMountProvider {if (!input.resolvedPath.skillName) {return sortSkillFolders(listScopedSkillFolders(documents, this.config.namespace)).map(- (document) =>- buildSkillDirectoryNode(- this.config.namespace,- getSkillMetadata(document)?.skillName ?? document.filename,- ),+ (document) => buildSkillDirectoryNode(this.config.namespace, document.filename),);}@@ -130,7 +125,6 @@ export class ProviderSkillsAgentDocument implements WritableSkillMountProvider {agentDocumentModel: this.deps.agentDocumentModel,agentId: input.agentId,content: snapshot.content,- documentService: this.deps.documentService,editorData: snapshot.editorData,namespace: this.config.namespace,skillName,@@ -179,6 +173,10 @@ export class ProviderSkillsAgentDocument implements WritableSkillMountProvider {);const folder = assertSkillDocument(getSkillFolder(documents, this.config.namespace, skillName));- await this.deps.documentService.deleteDocument(folder.documentId);+ await this.deps.agentDocumentModel.deleteSubtreeByDocumentId(+ input.agentId,+ folder.documentId,+ 'skill-delete',+ );}}diff --git a/src/server/services/agentDocumentVfs/mounts/skills/providers/providerSkillsAgentDocumentUtils.ts b/src/server/services/agentDocumentVfs/mounts/skills/providers/providerSkillsAgentDocumentUtils.tsindex 9ff55909722..9ab2258b88c 100644--- a/src/server/services/agentDocumentVfs/mounts/skills/providers/providerSkillsAgentDocumentUtils.ts+++ b/src/server/services/agentDocumentVfs/mounts/skills/providers/providerSkillsAgentDocumentUtils.ts@@ -8,10 +8,25 @@ import { getUnifiedSkillNamespaceRootPath } from '../path';import type { SkillMountNode } from '../types';export interface AgentSkillDocumentModelLike {- associate: (params: { agentId: string; documentId: string; policyLoad?: PolicyLoad }) => Promise<{- id: string;- }>;+ create: (+ agentId: string,+ filename: string,+ content: string,+ params?: {+ editorData?: Record<string, any>;+ fileType?: string;+ parentId?: string | null;+ policyLoad?: PolicyLoad;+ templateId?: string;+ title?: string;+ },+ ) => Promise<AgentDocument>;delete: (documentId: string, deleteReason?: string) => Promise<void>;+ deleteSubtreeByDocumentId: (+ agentId: string,+ rootDocumentId: string,+ deleteReason?: string,+ ) => Promise<void>;findByAgent: (agentId: string) => Promise<AgentDocument[]>;update: (documentId: string,@@ -25,37 +40,7 @@ export interface AgentSkillDocumentModelLike {}export interface DocumentTreeServiceLike {- createDocument: (params: {- content?: string;- editorData: Record<string, any>;- fileType?: string;- metadata?: Record<string, any>;- parentId?: string;- title: string;- }) => Promise<{- content: string | null;- documentId?: string;- editorData: Record<string, any> | null;- fileType: string;- filename: string | null;- id: string;- metadata: Record<string, any> | null;- parentId: string | null;- title: string | null;- }>;- deleteDocument: (id: string) => Promise<unknown>;trySaveCurrentDocumentHistory: (documentId: string, saveSource: 'llm_call') => Promise<unknown>;- updateDocument: (- id: string,- params: {- content?: string;- editorData?: Record<string, any>;- metadata?: Record<string, any>;- parentId?: string | null;- saveSource?: 'llm_call';- title?: string;- },- ) => Promise<unknown>;}export interface ProviderSkillsAgentDocumentDeps {@@ -67,20 +52,15 @@ export interface CreateSkillTreeInput {agentDocumentModel: AgentSkillDocumentModelLike;agentId: string;content: string;- documentService: DocumentTreeServiceLike;editorData: Record<string, any>;namespace: 'agent';skillName: string;}-export interface LobeSkillMetadata {- namespace: 'agent';- role: 'namespace-root' | 'skill-file' | 'skill-folder';- skillName?: string;-}-export const EMPTY_EDITOR_DATA = { root: { children: [], type: 'root' } };+export const AGENT_SKILL_TEMPLATE_ID = 'agent-skill';+export const SKILL_FILE_NAME = 'SKILL.md';export const SKILL_INDEX_FILE_TYPE = 'skill/index';@@ -175,33 +155,18 @@ export const projectDocumentContent = async (document: AgentDocument) => {}};-export const getSkillMetadata = (document: Pick<AgentDocument, 'metadata'>) => {- const metadata = document.metadata as { lobeSkill?: LobeSkillMetadata } | null;- return metadata?.lobeSkill;-};--export const isManagedSkillDocument = (document: Pick<AgentDocument, 'metadata'>) =>- Boolean(getSkillMetadata(document));--export const isSkillDocumentInScope = (- document: Pick<AgentDocument, 'metadata'>,- namespace: 'agent',-) => {- const metadata = getSkillMetadata(document);-- if (!metadata || metadata.namespace !== namespace) {- return false;- }-- return true;-};+export const isManagedSkillDocument = (document: Pick<AgentDocument, 'templateId'>) =>+ document.templateId === AGENT_SKILL_TEMPLATE_ID;export const getScopedSkillDocuments = (documents: AgentDocument[], namespace: 'agent') =>- documents.filter((document) => isSkillDocumentInScope(document, namespace));+ namespace === 'agent' ? documents.filter(isManagedSkillDocument) : [];export const getNamespaceRoot = (documents: AgentDocument[], namespace: 'agent') =>getScopedSkillDocuments(documents, namespace).find(- (document) => getSkillMetadata(document)?.role === 'namespace-root',+ (document) =>+ document.fileType === DOCUMENT_FOLDER_TYPE &&+ document.filename === 'skills' &&+ document.parentId === null,);export const getSkillFolder = (@@ -210,40 +175,33 @@ export const getSkillFolder = (skillName: string,) => {const root = getNamespaceRoot(documents, namespace);+ if (!root) return undefined;- return getScopedSkillDocuments(documents, namespace).find((document) => {- const metadata = getSkillMetadata(document);-- return (- metadata?.role === 'skill-folder' &&- metadata.skillName === skillName &&- (!root || document.parentId === root.documentId)- );- });+ return getScopedSkillDocuments(documents, namespace).find(+ (document) =>+ document.fileType === DOCUMENT_FOLDER_TYPE &&+ document.filename === skillName &&+ document.parentId === root.documentId,+ );};export const getSkillFile = (documents: AgentDocument[], namespace: 'agent', skillName: string) => {const folder = getSkillFolder(documents, namespace, skillName);+ if (!folder) return undefined;- return getScopedSkillDocuments(documents, namespace).find((document) => {- const metadata = getSkillMetadata(document);-- return (- metadata?.role === 'skill-file' &&- metadata.skillName === skillName &&- (!folder || document.parentId === folder.documentId)- );- });+ return getScopedSkillDocuments(documents, namespace).find(+ (document) => document.filename === SKILL_FILE_NAME && document.parentId === folder.documentId,+ );};export const listScopedSkillFolders = (documents: AgentDocument[], namespace: 'agent') => {const root = getNamespaceRoot(documents, namespace);+ if (!root) return [];- return getScopedSkillDocuments(documents, namespace).filter((document) => {- const metadata = getSkillMetadata(document);-- return metadata?.role === 'skill-folder' && (!root || document.parentId === root.documentId);- });+ return getScopedSkillDocuments(documents, namespace).filter(+ (document) =>+ document.fileType === DOCUMENT_FOLDER_TYPE && document.parentId === root.documentId,+ );};export const assertSkillDocument = <T>(document: T | undefined, message = 'Skill not found') => {@@ -254,23 +212,13 @@ export const assertSkillDocument = <T>(document: T | undefined, message = 'Skillreturn document;};-export const createSkillMetadata = ({ namespace, role, skillName }: LobeSkillMetadata) => ({- lobeSkill: {- namespace,- role,- ...(skillName ? { skillName } : {}),- } satisfies LobeSkillMetadata,-});-export const ensureNamespaceRoot = async ({agentId,agentDocumentModel,- documentService,namespace,}: {agentDocumentModel: AgentSkillDocumentModelLike;agentId: string;- documentService: DocumentTreeServiceLike;namespace: 'agent';}): Promise<{ documentId: string }> => {const documents = await agentDocumentModel.findByAgent(agentId);@@ -280,27 +228,21 @@ export const ensureNamespaceRoot = async ({return { documentId: existingRoot.documentId };}- const root = await documentService.createDocument({+ const root = await agentDocumentModel.create(agentId, 'skills', '', {editorData: EMPTY_EDITOR_DATA,fileType: DOCUMENT_FOLDER_TYPE,- metadata: createSkillMetadata({ namespace, role: 'namespace-root' }),- title: 'skills',- });-- await agentDocumentModel.associate({- agentId,- documentId: root.id,policyLoad: PolicyLoad.DISABLED,+ templateId: AGENT_SKILL_TEMPLATE_ID,+ title: 'skills',});- return { documentId: root.id };+ return { documentId: root.documentId };};export const createSkillTree = async ({agentDocumentModel,agentId,content,- documentService,editorData,namespace,skillName,@@ -319,7 +261,6 @@ export const createSkillTree = async ({: await ensureNamespaceRoot({agentDocumentModel,agentId,- documentService,namespace,});@@ -328,53 +269,45 @@ export const createSkillTree = async ({let createdFileId: string | undefined;try {- const folder = await documentService.createDocument({+ const folder = await agentDocumentModel.create(agentId, skillName, '', {editorData: EMPTY_EDITOR_DATA,fileType: DOCUMENT_FOLDER_TYPE,- metadata: createSkillMetadata({- namespace,- role: 'skill-folder',- skillName,- }),parentId: root.documentId,+ policyLoad: PolicyLoad.DISABLED,+ templateId: AGENT_SKILL_TEMPLATE_ID,title: skillName,});createdFolderId = folder.id;- await agentDocumentModel.associate({- agentId,- documentId: folder.id,- policyLoad: PolicyLoad.DISABLED,- });- const file = await documentService.createDocument({- content,+ const file = await agentDocumentModel.create(agentId, SKILL_FILE_NAME, content, {editorData,fileType: SKILL_INDEX_FILE_TYPE,- metadata: createSkillMetadata({- namespace,- role: 'skill-file',- skillName,- }),- parentId: folder.id,+ parentId: folder.documentId,+ templateId: AGENT_SKILL_TEMPLATE_ID,title: SKILL_FILE_NAME,});createdFileId = file.id;- await agentDocumentModel.associate({ agentId, documentId: file.id });- return { fileDocumentId: file.id, folderDocumentId: folder.id };+ return { fileDocumentId: file.documentId, folderDocumentId: folder.documentId };} catch (error) {if (createdFileId) {- await documentService.deleteDocument(createdFileId);+ await agentDocumentModel.delete(createdFileId, 'skill-create-rollback');}if (createdFolderId) {- await documentService.deleteDocument(createdFolderId);+ await agentDocumentModel.delete(createdFolderId, 'skill-create-rollback');}if (createdRootId) {- await documentService.deleteDocument(createdRootId);+ const rootBinding = await agentDocumentModel+ .findByAgent(agentId)+ .then((documents) => documents.find((document) => document.documentId === createdRootId));++ if (rootBinding) {+ await agentDocumentModel.delete(rootBinding.id, 'skill-create-rollback');+ }}throw error;diff --git a/src/server/services/agentDocuments/index.test.ts b/src/server/services/agentDocuments/index.test.tsindex 9eb9229e6ac..5695422f571 100644--- a/src/server/services/agentDocuments/index.test.ts+++ b/src/server/services/agentDocuments/index.test.ts@@ -570,13 +570,7 @@ describe('AgentDocumentsService', () => {content: 'content',documentId: 'documents-1',id: 'agent-doc-1',- metadata: {- lobeSkill: {- namespace: 'agent',- role: 'skill-folder',- skillName: 'writer',- },- },+ templateId: 'agent-skill',title: 'writer',});@@ -596,13 +590,7 @@ describe('AgentDocumentsService', () => {content: 'content',documentId: 'documents-1',id: 'agent-doc-1',- metadata: {- lobeSkill: {- namespace: 'agent',- role: 'skill-file',- skillName: 'writer',- },- },+ templateId: 'agent-skill',title: 'SKILL.md',});diff --git a/src/server/services/agentSignal/policies/analyzeIntent/actions/__tests__/skillManagement.integration.test.ts b/src/server/services/agentSignal/policies/analyzeIntent/actions/__tests__/skillManagement.integration.test.tsindex 243c81d6472..1ed1dbbea1e 100644--- a/src/server/services/agentSignal/policies/analyzeIntent/actions/__tests__/skillManagement.integration.test.ts+++ b/src/server/services/agentSignal/policies/analyzeIntent/actions/__tests__/skillManagement.integration.test.ts@@ -7,7 +7,6 @@ import { AgentDocumentModel } from '@/database/models/agentDocuments';import { createMarkdownEditorSnapshot } from '@/server/services/agentDocuments/headlessEditor';import { AgentDocumentVfsService } from '@/server/services/agentDocumentVfs';import { createSkillTree } from '@/server/services/agentDocumentVfs/mounts/skills/providers/providerSkillsAgentDocumentUtils';-import { DocumentService } from '@/server/services/document';import {cleanupTestUser,@@ -46,7 +45,6 @@ describe('runSkillManagementAction integration', () => {agentDocumentModel: new AgentDocumentModel(serverDB, userId),agentId,content: snapshot.content,- documentService: new DocumentService(serverDB, userId),editorData: snapshot.editorData,namespace: 'agent',skillName,diff --git a/src/server/services/agentSignal/policies/analyzeIntent/actions/__tests__/skillManagement.test.ts b/src/server/services/agentSignal/policies/analyzeIntent/actions/__tests__/skillManagement.test.tsindex 11bce108978..18d233914b8 100644--- a/src/server/services/agentSignal/policies/analyzeIntent/actions/__tests__/skillManagement.test.ts+++ b/src/server/services/agentSignal/policies/analyzeIntent/actions/__tests__/skillManagement.test.ts@@ -128,26 +128,28 @@ describe('defineSkillManagementActionHandler', () => {collectAgentSkillDecisionCandidates([{documentId: 'folder-doc',- filename: 'Review Skill',- metadata: {- lobeSkill: {- namespace: 'agent',- role: 'skill-folder',- skillName: 'review-skill',- },- },+ fileType: 'custom/folder',+ filename: 'review-skill',+ id: 'folder-binding',+ parentId: 'root-doc',+ templateId: 'agent-skill',title: 'Review Skill',},+ {+ documentId: 'root-doc',+ fileType: 'custom/folder',+ filename: 'skills',+ id: 'root-binding',+ parentId: null,+ templateId: 'agent-skill',+ title: 'skills',+ },{documentId: 'file-doc',filename: 'SKILL.md',- metadata: {- lobeSkill: {- namespace: 'agent',- role: 'skill-file',- skillName: 'review-skill',- },- },+ id: 'file-binding',+ parentId: 'folder-doc',+ templateId: 'agent-skill',title: 'SKILL.md',},] as never),diff --git a/src/server/services/agentSignal/policies/analyzeIntent/actions/skillManagement.ts b/src/server/services/agentSignal/policies/analyzeIntent/actions/skillManagement.tsindex 3607732de17..288975ee40a 100644--- a/src/server/services/agentSignal/policies/analyzeIntent/actions/skillManagement.ts+++ b/src/server/services/agentSignal/policies/analyzeIntent/actions/skillManagement.ts@@ -26,9 +26,7 @@ import { AgentDocumentVfsService } from '@/server/services/agentDocumentVfs';import {createSkillTree,getSkillFolder,- getSkillMetadata,} from '@/server/services/agentDocumentVfs/mounts/skills/providers/providerSkillsAgentDocumentUtils';-import { DocumentService } from '@/server/services/document';import { SkillMaintainerService } from '@/server/services/skillMaintainer/SkillMaintainerService';import { SkillReferenceResolver } from '@/server/services/skillMaintainer/SkillReferenceResolver';import { VfsSkillPackageAdapter } from '@/server/services/skillMaintainer/VfsSkillPackageAdapter';@@ -302,7 +300,7 @@ const toSkillManagementDecision = (** Expects:* - `documents` come from one agent's document bindings- * - Managed skill folders store package names in `metadata.lobeSkill.skillName`+ * - Managed skill folders use their directory filename as the package id** Returns:* - Agent-scoped candidate ids that are package names for `targetSkillIds`@@ -313,19 +311,15 @@ export const collectAgentSkillDecisionCandidates = (const candidates: SkillManagementCandidateSkill[] = [];for (const document of documents) {- const metadata = getSkillMetadata(document);+ const folder = getSkillFolder(documents, 'agent', document.filename);- if (- metadata?.namespace !== 'agent' ||- metadata.role !== 'skill-folder' ||- !metadata.skillName- ) {+ if (!folder || folder.id !== document.id) {continue;}candidates.push({- id: metadata.skillName,- name: document.title ?? document.filename ?? metadata.skillName,+ id: document.filename,+ name: document.title ?? document.filename,scope: 'agent',});}@@ -803,7 +797,6 @@ export const runSkillManagementAction = async (agentDocumentModel: new AgentDocumentModel(options.db, options.userId),agentId: input.agentId,content: snapshot.content,- documentService: new DocumentService(options.db, options.userId),editorData: snapshot.editorData,namespace: 'agent',skillName,