π€― 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(mecha): assemble the run's skill pool in the shared core (#19667)
Arvin Xu7334cca4b98c
diff --git a/apps/server/src/services/aiAgent/pipeline/operationPrep.ts b/apps/server/src/services/aiAgent/pipeline/operationPrep.tsindex f877319b6aa..2e9ceb786d0 100644--- a/apps/server/src/services/aiAgent/pipeline/operationPrep.ts+++ b/apps/server/src/services/aiAgent/pipeline/operationPrep.ts@@ -2,9 +2,10 @@ import type { AgentRuntimeContext } from '@lobechat/agent-runtime';import { extractActivatedToolIdsFromMessages } from '@lobechat/agent-runtime';import { builtinSkills } from '@lobechat/builtin-skills';import { getShellSyntaxGuidance } from '@lobechat/builtin-tool-local-system';-import type { ProjectInstructionFile } from '@lobechat/context-engine';-import { buildExpertiseContextSnapshot, SkillEngine } from '@lobechat/context-engine';+import type { OperationSkillSet, ProjectInstructionFile } from '@lobechat/context-engine';+import { buildExpertiseContextSnapshot } from '@lobechat/context-engine';import type { LobeChatDatabase } from '@lobechat/database';+import { assembleSkillPool } from '@lobechat/mecha';import { buildTaskManagerDefaultsPrompt, resourcesTreePrompt } from '@lobechat/prompts';import type { LobeAgentAgencyConfig, WorkingDirConfig, WorkspaceInitResult } from '@lobechat/types';import {@@ -23,7 +24,6 @@ import type { MessageModel } from '@/database/models/message';import type { TopicModel } from '@/database/models/topic';import { UserPersonaModel } from '@/database/models/userMemory/persona';import { isDeviceCapablePlan } from '@/helpers/executionTarget';-import { shouldEnableBuiltinSkill } from '@/helpers/skillFilters';import type { ServerUserMemoryConfig } from '@/server/modules/Mecha/ContextEngineering/types';import type { AgentDocumentsService } from '@/server/services/agentDocuments';import { deviceGateway } from '@/server/services/deviceGateway';@@ -196,7 +196,7 @@ export interface OperationPrepResult {deviceSystemInfo: Record<string, string>;expertise?: Awaited<ReturnType<typeof buildExpertiseContextSnapshot>>;initialContext: AgentRuntimeContext;- operationSkillSet?: ReturnType<SkillEngine['generate']>;+ operationSkillSet?: OperationSkillSet;/*** A project's root instruction files. Run context, not agent config β it* travels on the operation like `expertise` does, and the context engine@@ -801,62 +801,46 @@ export const prepareOperation = async ();}- // Precedence on name collision: project > db > agent-skills > builtin.- // Agent-skills carry the `agent-skills:` prefix in their `name`, so they- // can only collide with each other β but we still dedupe by name to keep- // a single shape for the SkillEngine input.+ // Precedence, name dedupe, the disabled drop, the share allowlist and the+ // device-only builtin gate are the shared rules in `@lobechat/mecha`; this+ // pipeline supplies the four sources and the run's facts.//- // Disabled skills are dropped here, not just rule-gated later: this- // `skills` array is the sole candidate pool SkillEngine/SkillResolver- // build `<available_skills>` from AND the pool `activateSkill` resolves- // against, so a disabled identifier absent here is neither listed nor- // activatable β mirrors the tool-manifest treatment above (installedPlugins/- // additionalManifests), which this array had never received.- //- // Shared runs only see skills allowed by the share configuration. The- // candidate pool must be trimmed here rather than left to- // `SkillEngine.generate`, which annotates activation state on its input- // rather than shrinking it. Reuse `filterPluginsByShareGate` (id-list- // intersection, not tool-specific) to keep this pool the single- // enforcement point β an empty/missing allowlist collapses it to nothing.+ // A shared run only sees skills its share configuration allows. The+ // allowlist is an id-list intersection (`filterPluginsByShareGate`), not+ // tool-specific, so the pool stays the single enforcement point β an+ // empty or missing allowlist collapses it to nothing.const shareAllowedSkillIds = shareGate- ? new Set(- filterPluginsByShareGate(- [...projectMetas, ...dbMetas, ...agentSkillMetas, ...builtinMetas].map(- (skill) => skill.identifier,- ),- shareGate,+ ? filterPluginsByShareGate(+ [...projectMetas, ...dbMetas, ...agentSkillMetas, ...builtinMetas].map(+ (skill) => skill.identifier,),+ shareGate,): undefined;- const seenNames = new Set<string>();- const skills = [...projectMetas, ...dbMetas, ...agentSkillMetas, ...builtinMetas].filter(- (skill) => {- if (disabledPluginIds.includes(skill.identifier)) return false;- if (shareAllowedSkillIds && !shareAllowedSkillIds.has(skill.identifier)) return false;- if (seenNames.has(skill.name)) return false;- seenNames.add(skill.name);- return true;++ // Device-only builtin skills are gated on the run's execution plan, not+ // the compile-time `isDesktop` constant (always false on the server). Use+ // the device-CAPABLE plan rather than `activeDeviceId`: a+ // `device-unrouted` run lets the model pick a device mid-run, and this+ // skill set is built once per operation, so gating on the routed device+ // would hide the skill forever in those runs. Activation and loading+ // apply the same plan gate via `ToolExecutionContext.deviceCapable`; only+ // command execution is gated at the device tool layer.+ operationSkillSet = assembleSkillPool(+ {+ agentSkills: agentSkillMetas,+ builtin: builtinMetas,+ db: dbMetas,+ project: projectMetas,+ },+ {+ canExecuteOnDevice: executionPlan ? isDeviceCapablePlan(executionPlan) : false,+ disabledIds: disabledPluginIds,+ enabledPluginIds: agentPlugins ?? [],+ shareAllowedIds: shareAllowedSkillIds,+ skillActivateMode: agentConfig.chatConfig?.skillActivateMode,},);-- // Device-only builtin skills (agent-browser) are gated on the run's- // execution plan, not the compile-time `isDesktop` constant (always false- // on the server). Gate the static `<available_skills>` listing on the- // device-CAPABLE plan rather than `activeDeviceId`: `device-unrouted`- // runs let the model pick a device mid-run, and this skill set is built- // once per operation β gating on `activeDeviceId` would hide the skill- // forever in those runs. Activation/loading apply the same plan gate via- // `ToolExecutionContext.deviceCapable`; only actual command execution is- // gated at the device tool layer.- const skillEngine = new SkillEngine({- enableChecker: (skill) =>- shouldEnableBuiltinSkill(skill.identifier, {- canExecuteOnDevice: executionPlan ? isDeviceCapablePlan(executionPlan) : false,- }),- skills,- });- operationSkillSet = skillEngine.generate(agentPlugins ?? []);} catch (error) {log('execAgent: failed to build operationSkillSet: %O', error);}diff --git a/packages/mecha/package.json b/packages/mecha/package.jsonindex 06a629e190b..8af9433849a 100644--- a/packages/mecha/package.json+++ b/packages/mecha/package.json@@ -2,6 +2,10 @@"name": "@lobechat/mecha","version": "0.0.1","description": "Host-agnostic Mecha layer: resolving an agent's effective run configuration and the context it runs on",+ "exports": {+ ".": "./src/index.ts",+ "./builtinSkillGate": "./src/toolSet/builtinSkillGate.ts"+ },"main": "src/index.ts","scripts": {"test": "vitest",@@ -10,6 +14,7 @@"dependencies": {"@lobechat/agent-runtime": "workspace:*","@lobechat/builtin-agents": "workspace:*",+ "@lobechat/builtin-skills": "workspace:*","@lobechat/builtin-tool-agent-builder": "workspace:*","@lobechat/builtin-tool-auv": "workspace:*","@lobechat/builtin-tool-browser": "workspace:*",diff --git a/packages/mecha/src/toolSet/builtinSkillGate.ts b/packages/mecha/src/toolSet/builtinSkillGate.tsnew file mode 100644index 00000000000..2aa886b20c1--- /dev/null+++ b/packages/mecha/src/toolSet/builtinSkillGate.ts@@ -0,0 +1,32 @@+import { AgentBrowserIdentifier } from '@lobechat/builtin-skills/manifests';++/** Builtin skills that only work where the run can execute commands on a device. */+const DEVICE_ONLY_BUILTIN_SKILLS = new Set<string>([AgentBrowserIdentifier]);++/** Builtin skills the product drives itself; never listed to the user or the model. */+export const USER_HIDDEN_BUILTIN_SKILLS = new Set<string>(['task']);++export interface BuiltinSkillEnvironment {+ /**+ * The run can execute commands on a device: the desktop app is itself that+ * device, a gateway run needs a device-capable execution plan. The+ * compile-time `isDesktop` constant is meaningless on the server.+ */+ canExecuteOnDevice: boolean;+}++/**+ * Whether a builtin skill may be listed and activated for this run.+ *+ * Kept in its own module, free of every other tool import, so the leaf callers+ * that only need this gate (store slices, settings UI) do not pull the whole+ * runtime graph in behind it.+ */+export const isBuiltinSkillEnabled = (+ skillId: string,+ environment: BuiltinSkillEnvironment,+): boolean => {+ if (USER_HIDDEN_BUILTIN_SKILLS.has(skillId)) return false;+ if (DEVICE_ONLY_BUILTIN_SKILLS.has(skillId)) return environment.canExecuteOnDevice;+ return true;+};diff --git a/packages/mecha/src/toolSet/index.ts b/packages/mecha/src/toolSet/index.tsindex 46111958180..37bf58804c3 100644--- a/packages/mecha/src/toolSet/index.ts+++ b/packages/mecha/src/toolSet/index.ts@@ -1,5 +1,7 @@+export * from './builtinSkillGate';export * from './deviceTools';export * from './discoveryPool';export * from './manifestPool';export { deviceToolWallParams, resolveToolRules } from './resolveToolRules';+export * from './skillPool';export type * from './types';diff --git a/packages/mecha/src/toolSet/skillPool.test.ts b/packages/mecha/src/toolSet/skillPool.test.tsnew file mode 100644index 00000000000..0f74719afbe--- /dev/null+++ b/packages/mecha/src/toolSet/skillPool.test.ts@@ -0,0 +1,117 @@+import { AgentBrowserIdentifier } from '@lobechat/builtin-skills/manifests';+import type { SkillMeta } from '@lobechat/context-engine';+import { describe, expect, it } from 'vitest';++import { assembleSkillPool, isBuiltinSkillEnabled } from './skillPool';++const skill = (identifier: string, name = identifier, extra: Partial<SkillMeta> = {}): SkillMeta =>+ ({ description: '', identifier, name, ...extra }) as SkillMeta;++describe('isBuiltinSkillEnabled', () => {+ it('hides the product-driven skills and gates the device-only ones', () => {+ expect(isBuiltinSkillEnabled('task', { canExecuteOnDevice: true })).toBe(false);+ expect(isBuiltinSkillEnabled(AgentBrowserIdentifier, { canExecuteOnDevice: false })).toBe(+ false,+ );+ expect(isBuiltinSkillEnabled(AgentBrowserIdentifier, { canExecuteOnDevice: true })).toBe(true);+ expect(isBuiltinSkillEnabled('artifacts', { canExecuteOnDevice: false })).toBe(true);+ });+});++describe('assembleSkillPool', () => {+ it('resolves a name collision as project > db > agent-skills > builtin', () => {+ const pool = assembleSkillPool({+ agentSkills: [skill('agent-skills:review', 'review')],+ builtin: [skill('builtin-review', 'review')],+ db: [skill('db-review', 'review')],+ project: [skill('project:review', 'review')],+ });+ expect(pool.skills.map((s) => s.identifier)).toEqual(['project:review']);++ const withoutProject = assembleSkillPool({+ agentSkills: [skill('agent-skills:review', 'review')],+ builtin: [skill('builtin-review', 'review')],+ db: [skill('db-review', 'review')],+ });+ expect(withoutProject.skills.map((s) => s.identifier)).toEqual(['db-review']);+ });++ it('keeps distinct names from every source, in precedence order', () => {+ const pool = assembleSkillPool({+ agentSkills: [skill('agent-skills:notes', 'agent-skills:notes')],+ builtin: [skill('artifacts')],+ db: [skill('my-skill')],+ project: [skill('project:deploy', 'deploy')],+ });+ expect(pool.skills.map((s) => s.identifier)).toEqual([+ 'project:deploy',+ 'my-skill',+ 'agent-skills:notes',+ 'artifacts',+ ]);+ });++ it('drops disabled skills from the pool, so they are neither listed nor activatable', () => {+ const pool = assembleSkillPool(+ { builtin: [skill('artifacts')], db: [skill('gone'), skill('kept')] },+ { disabledIds: ['gone'] },+ );+ expect(pool.skills.map((s) => s.identifier)).toEqual(['kept', 'artifacts']);+ });++ it('withholds everything a share configuration does not allow', () => {+ const sources = { builtin: [skill('artifacts')], db: [skill('shared'), skill('private')] };+ expect(+ assembleSkillPool(sources, { shareAllowedIds: ['shared'] }).skills.map((s) => s.identifier),+ ).toEqual(['shared']);+ // An empty allowlist collapses the pool; no allowlist means no gate.+ expect(assembleSkillPool(sources, { shareAllowedIds: [] }).skills).toEqual([]);+ expect(assembleSkillPool(sources).skills).toHaveLength(3);+ });++ it('gates the device-only builtin on the run, not on the host', () => {+ const sources = { builtin: [skill(AgentBrowserIdentifier), skill('artifacts')] };+ expect(assembleSkillPool(sources).skills.map((s) => s.identifier)).toEqual(['artifacts']);+ expect(+ assembleSkillPool(sources, { canExecuteOnDevice: true }).skills.map((s) => s.identifier),+ ).toEqual([AgentBrowserIdentifier, 'artifacts']);+ });++ it('exposes only the selected skills in manual mode, keeping the discovered project ones', () => {+ const sources = {+ agentSkills: [skill('agent-skills:notes', 'agent-skills:notes')],+ builtin: [skill('artifacts')],+ db: [skill('picked'), skill('not-picked')],+ // Project / device skills come from the working directory and can never+ // be picked in the UI, so the mode does not speak about them.+ project: [skill('project:deploy', 'deploy')],+ };++ const manual = assembleSkillPool(sources, {+ enabledPluginIds: ['picked'],+ skillActivateMode: 'manual',+ });+ expect(manual.skills.map((s) => s.identifier)).toEqual(['project:deploy', 'picked']);++ const auto = assembleSkillPool(sources, {+ enabledPluginIds: ['picked'],+ skillActivateMode: 'auto',+ });+ expect(auto.skills.map((s) => s.identifier)).toEqual([+ 'project:deploy',+ 'picked',+ 'not-picked',+ 'agent-skills:notes',+ 'artifacts',+ ]);+ });++ it('pairs the pool with the runβs enabled plugin ids for the resolver', () => {+ const pool = assembleSkillPool(+ { db: [skill('pinned'), skill('listed')] },+ { enabledPluginIds: ['pinned'] },+ );+ expect(pool.enabledPluginIds).toEqual(['pinned']);+ expect(pool.skills.map((s) => s.identifier)).toEqual(['pinned', 'listed']);+ });+});diff --git a/packages/mecha/src/toolSet/skillPool.ts b/packages/mecha/src/toolSet/skillPool.tsnew file mode 100644index 00000000000..297ff751098--- /dev/null+++ b/packages/mecha/src/toolSet/skillPool.ts@@ -0,0 +1,111 @@+import { type OperationSkillSet, SkillEngine, type SkillMeta } from '@lobechat/context-engine';+import debug from 'debug';++import { type BuiltinSkillEnvironment, isBuiltinSkillEnabled } from './builtinSkillGate';++const log = debug('mecha:skillPool');++export type { BuiltinSkillEnvironment };+export { isBuiltinSkillEnabled, USER_HIDDEN_BUILTIN_SKILLS } from './builtinSkillGate';++/**+ * The skill sources of a run, in precedence order. A host that has no such+ * source leaves it out: the browser runtime scans no project directory and+ * mounts no agent-document bundles.+ */+export interface SkillPoolSources {+ /** Agent-document skill bundles, identified as `agent-skills:<filename>`. */+ agentSkills?: readonly SkillMeta[];+ builtin?: readonly SkillMeta[];+ /** The user's DB skills (personal and market installs). */+ db?: readonly SkillMeta[];+ /** SKILL.md files scanned from the run's project or device directory. */+ project?: readonly SkillMeta[];+}++export interface AssembleSkillPoolOptions {+ /** Gates the device-only builtin skills. */+ canExecuteOnDevice?: boolean;+ /** Skills the agent explicitly disabled; neither listed nor activatable. */+ disabledIds?: readonly string[];+ /**+ * The run's enabled plugin ids, paired with the pool for the resolver: a+ * skill matching one is auto-activated and its content injected directly.+ */+ enabledPluginIds?: readonly string[];+ /**+ * Identifiers a share configuration allows. `undefined` means the run is not+ * shared; an empty list collapses the pool to nothing.+ */+ shareAllowedIds?: readonly string[];+ /**+ * The agent's skill activation mode. `manual` means what the UI promises β+ * "only user-selected tools and skills are available to AI" β so the+ * selectable sources collapse to `enabledPluginIds`. Withholding the+ * discovery tools is not enough on its own: `activateSkill` ships with the+ * always-on `lobe-skills` tool and resolves against this pool.+ */+ skillActivateMode?: 'auto' | 'manual';+}++/**+ * The candidate pool `<available_skills>` is built from and `activateSkill`+ * resolves against. Precedence on a name collision is+ * project > db > agent-skills > builtin, disabled skills and anything a share+ * configuration withholds are dropped here rather than rule-gated later β the+ * resolver annotates its input rather than shrinking it, so a skill left in+ * the pool stays activatable.+ */+export const assembleSkillPool = (+ sources: SkillPoolSources,+ options: AssembleSkillPoolOptions = {},+): OperationSkillSet => {+ const enabledPluginIds = new Set(options.enabledPluginIds ?? []);+ // Manual mode exposes only what the user picked. Project / device skills are+ // discovered from the run's working directory and can never be picked in the+ // UI, so the mode does not speak about them and they stay.+ const selectable =+ options.skillActivateMode === 'manual'+ ? (skills: readonly SkillMeta[] = []) =>+ skills.filter((skill) => enabledPluginIds.has(skill.identifier))+ : (skills: readonly SkillMeta[] = []) => skills;++ const ordered = [+ ...(sources.project ?? []),+ ...selectable(sources.db),+ ...selectable(sources.agentSkills),+ ...selectable(sources.builtin),+ ];+ const disabled = new Set(options.disabledIds ?? []);+ const shareAllowed = options.shareAllowedIds ? new Set(options.shareAllowedIds) : undefined;+ const seenNames = new Set<string>();++ const skills = ordered.filter((skill) => {+ if (disabled.has(skill.identifier)) return false;+ if (shareAllowed && !shareAllowed.has(skill.identifier)) return false;+ // Agent-document skills carry their prefix in `name`, so they can only+ // collide with each other; dedupe by name keeps one shape for the engine.+ if (seenNames.has(skill.name)) return false;+ seenNames.add(skill.name);+ return true;+ });++ log(+ 'Assembled %d/%d skills (project=%d db=%d agent=%d builtin=%d)',+ skills.length,+ ordered.length,+ sources.project?.length ?? 0,+ sources.db?.length ?? 0,+ sources.agentSkills?.length ?? 0,+ sources.builtin?.length ?? 0,+ );++ const engine = new SkillEngine({+ enableChecker: (skill) =>+ isBuiltinSkillEnabled(skill.identifier, {+ canExecuteOnDevice: options.canExecuteOnDevice ?? false,+ }),+ skills,+ });+ return engine.generate([...enabledPluginIds]);+};diff --git a/src/helpers/skillFilters.ts b/src/helpers/skillFilters.tsindex 91027ae56de..a0266a6b918 100644--- a/src/helpers/skillFilters.ts+++ b/src/helpers/skillFilters.ts@@ -1,48 +1,33 @@-import { AgentBrowserIdentifier } from '@lobechat/builtin-skills/manifests';import { isDesktop } from '@lobechat/const';+// Imported from the leaf module rather than the package barrel: this helper+// is used by store slices and settings UI, which must not pull the whole+// agent-runtime graph in behind a two-line gate.+import {+ type BuiltinSkillEnvironment,+ isBuiltinSkillEnabled,+ USER_HIDDEN_BUILTIN_SKILLS,+} from '@lobechat/mecha/builtinSkillGate';import { type BuiltinSkill } from '@lobechat/types';-export interface BuiltinSkillFilterContext {- /**- * Whether the current run can execute commands on a local device. Server-side- * callers must derive this from the run's execution plan (`activeDeviceId`- * presence) β the compile-time `isDesktop` constant is always false there.- */- canExecuteOnDevice: boolean;-}+export type BuiltinSkillFilterContext = BuiltinSkillEnvironment;-const DEVICE_ONLY_BUILTIN_SKILLS = new Set([AgentBrowserIdentifier]);-const USER_HIDDEN_BUILTIN_SKILLS = new Set(['task']);--// Client default: the desktop app is itself the execution device.-const DEFAULT_CONTEXT: BuiltinSkillFilterContext = {- canExecuteOnDevice: isDesktop,-};--const resolveBuiltinSkillFilterContext = (- context: BuiltinSkillFilterContext = DEFAULT_CONTEXT,-): BuiltinSkillFilterContext => ({- canExecuteOnDevice: context.canExecuteOnDevice ?? DEFAULT_CONTEXT.canExecuteOnDevice,-});+// The rule lives in `@lobechat/mecha` so both hosts gate the device-only+// builtin skills the same way. On the client the desktop app is itself the+// execution device; server callers must derive it from the run's execution+// plan, since the compile-time `isDesktop` constant is always false there.+const DEFAULT_CONTEXT: BuiltinSkillFilterContext = { canExecuteOnDevice: isDesktop };export const shouldEnableBuiltinSkill = (skillId: string,context: BuiltinSkillFilterContext = DEFAULT_CONTEXT,-): boolean => {- const resolvedContext = resolveBuiltinSkillFilterContext(context);-- if (USER_HIDDEN_BUILTIN_SKILLS.has(skillId)) return false;-- if (DEVICE_ONLY_BUILTIN_SKILLS.has(skillId)) return resolvedContext.canExecuteOnDevice;-- return true;-};+): boolean =>+ isBuiltinSkillEnabled(skillId, {+ canExecuteOnDevice: context.canExecuteOnDevice ?? DEFAULT_CONTEXT.canExecuteOnDevice,+ });export const filterBuiltinSkills = <T extends Pick<BuiltinSkill, 'identifier'>>(skills: T[],context: BuiltinSkillFilterContext = DEFAULT_CONTEXT,-): T[] => {- return skills.filter((skill) => shouldEnableBuiltinSkill(skill.identifier, context));-};+): T[] => skills.filter((skill) => shouldEnableBuiltinSkill(skill.identifier, context));export { USER_HIDDEN_BUILTIN_SKILLS };diff --git a/src/services/chat/mecha/contextEngineering.ts b/src/services/chat/mecha/contextEngineering.tsindex 990ceacdf18..d12228018e2 100644--- a/src/services/chat/mecha/contextEngineering.ts+++ b/src/services/chat/mecha/contextEngineering.ts@@ -242,8 +242,6 @@ export const contextEngineering = async ({: undefined;const agentMeta = agentId ? agentSelectors.getAgentMetaById(agentId)(agentStoreState) : undefined;const agentItem = agentId ? agentByIdSelectors.getAgentById(agentId)(agentStoreState) : undefined;- const isInAutoSkillMode =- agentChatConfigSelectors.skillActivateMode(agentStoreState) !== 'manual';const facts = await gatherContextFacts({agent: {@@ -279,13 +277,15 @@ export const contextEngineering = async ({// In manual mode: only expose user-selected skills (filtered by pluginIds).let enabledSkills: OperationSkillSet['skills'] | undefined;if (plugins) {- const skillSet = await resolveClientSkills(plugins, disabledPluginIds);- if (isInAutoSkillMode) {- enabledSkills = skillSet.skills;- } else {- const selectedIds = new Set(plugins);- enabledSkills = skillSet.skills.filter((s) => selectedIds.has(s.identifier));- }+ // Manual mode narrows the pool itself, so an unselected skill is neither+ // listed nor resolvable by `activateSkill`.+ enabledSkills = (+ await resolveClientSkills(+ plugins,+ disabledPluginIds,+ agentChatConfigSelectors.skillActivateMode(agentStoreState),+ )+ ).skills;}// One timezone for every date the prompt renders β the core's temporaldiff --git a/src/services/chat/mecha/skillEngineering.ts b/src/services/chat/mecha/skillEngineering.tsindex 1a9f7797787..a3a1a4a95a4 100644--- a/src/services/chat/mecha/skillEngineering.ts+++ b/src/services/chat/mecha/skillEngineering.ts@@ -1,10 +1,10 @@+import { isDesktop } from '@lobechat/const';import type { OperationSkillSet } from '@lobechat/context-engine';-import { SkillEngine } from '@lobechat/context-engine';+import { assembleSkillPool } from '@lobechat/mecha';import { resourcesTreePrompt } from '@lobechat/prompts';import type { SkillItem } from '@lobechat/types';import debug from 'debug';-import { isBuiltinSkillAvailableInCurrentEnv } from '@/helpers/toolAvailability';import { agentSkillService } from '@/services/skill';import { getToolStoreState } from '@/store/tool';import { loadBuiltinSkills } from '@/store/tool/slices/builtin/loadBuiltinSkills';@@ -37,12 +37,14 @@ const buildDbSkillContent = (detail: SkillItem): string | undefined => {* memory; DB content is fetched on demand (store cache first) and only for the* pinned skills, to avoid bulk network calls when auto mode exposes every skill.*- * Uses isBuiltinSkillAvailableInCurrentEnv as the enableChecker to- * filter platform-specific skills (e.g., agent-browser on desktop only).+ * Platform-specific skills (e.g. agent-browser on desktop only) are filtered+ * by the shared rule, which the desktop client satisfies by being the+ * execution device itself.*/export const resolveClientSkills = async (pluginIds?: string[],disabledIds?: string[],+ skillActivateMode?: 'auto' | 'manual',): Promise<OperationSkillSet> => {const toolState = getToolStoreState();const pinnedIds = new Set(pluginIds ?? []);@@ -101,10 +103,16 @@ export const resolveClientSkills = async (}),);- const skillEngine = new SkillEngine({- enableChecker: (skill) => isBuiltinSkillAvailableInCurrentEnv(skill.identifier),- skills: [...builtinMetas, ...dbMetas],- });-- return skillEngine.generate(pluginIds ?? []);+ // Precedence, name dedupe and the device-only builtin gate are the shared+ // rules; the browser scans no project directory and mounts no+ // agent-document bundles, so it supplies two of the four sources.+ return assembleSkillPool(+ { builtin: builtinMetas, db: dbMetas },+ {+ // The desktop app is itself the execution device.+ canExecuteOnDevice: isDesktop,+ enabledPluginIds: pluginIds,+ skillActivateMode,+ },+ );};