From 105d6ee975fb0f59a1090b53433d0a6dde48a158 Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Thu, 26 Nov 2026 16:14:42 +0100 Subject: [PATCH] ui: list the skills at hand in the Library: the machine's folders and MCP servers A Skills tab lists the skills found in ~/.agents/skills and ~/.claude/skills on the machine llama-server runs on, read through llama-server's file tools, next to the skills MCP servers publish, which reach it through the new skillSources point. A row opens the skill's SKILL.md. Assisted-by: Claude (Opus 5.5 Medium) --- ui/apps/chat/README.md | 4 +- .../components/app/dialogs/DialogSkill.svelte | 79 ++++++++++ .../src/lib/components/app/dialogs/index.ts | 8 + .../app/library/LibrarySkillRow.svelte | 37 +++++ .../app/library/LibrarySkills.svelte | 146 ++++++++++++++++++ .../src/lib/components/app/library/index.ts | 7 +- .../chat/src/lib/constants/icons.constants.ts | 4 + ui/apps/chat/src/lib/constants/index.ts | 1 + .../src/lib/constants/library.constants.ts | 3 +- .../src/lib/constants/skills.constants.ts | 25 +++ ui/apps/chat/src/lib/enums/library.enums.ts | 3 +- ui/apps/chat/src/lib/extensions/index.ts | 1 + ui/apps/chat/src/lib/extensions/mcp/index.ts | 2 + .../src/lib/extensions/mcp/skills/icon.ts | 4 +- .../src/lib/extensions/mcp/skills/source.ts | 65 ++++++++ .../chat/src/lib/extensions/points/skills.ts | 29 ++++ ui/apps/chat/src/lib/extensions/types.ts | 3 + .../src/lib/services/local-skills.service.ts | 84 ++++++++++ ui/apps/chat/src/lib/stores/index.ts | 3 + ui/apps/chat/src/lib/stores/skills.svelte.ts | 87 +++++++++++ ui/apps/chat/src/lib/utils/index.ts | 3 + ui/apps/chat/src/lib/utils/skill-manifest.ts | 93 +++++++++++ ui/apps/chat/src/routes/library/+page.svelte | 17 +- .../tests/unit/local-skills-service.test.ts | 107 +++++++++++++ .../chat/tests/unit/mcp-skill-source.test.ts | 125 +++++++++++++++ .../chat/tests/unit/skill-manifest.test.ts | 83 ++++++++++ ui/apps/chat/tests/unit/skills-store.test.ts | 99 ++++++++++++ 27 files changed, 1112 insertions(+), 10 deletions(-) create mode 100644 ui/apps/chat/src/lib/components/app/dialogs/DialogSkill.svelte create mode 100644 ui/apps/chat/src/lib/components/app/library/LibrarySkillRow.svelte create mode 100644 ui/apps/chat/src/lib/components/app/library/LibrarySkills.svelte create mode 100644 ui/apps/chat/src/lib/constants/skills.constants.ts create mode 100644 ui/apps/chat/src/lib/extensions/mcp/skills/source.ts create mode 100644 ui/apps/chat/src/lib/extensions/points/skills.ts create mode 100644 ui/apps/chat/src/lib/services/local-skills.service.ts create mode 100644 ui/apps/chat/src/lib/stores/skills.svelte.ts create mode 100644 ui/apps/chat/src/lib/utils/skill-manifest.ts create mode 100644 ui/apps/chat/tests/unit/local-skills-service.test.ts create mode 100644 ui/apps/chat/tests/unit/mcp-skill-source.test.ts create mode 100644 ui/apps/chat/tests/unit/skill-manifest.test.ts create mode 100644 ui/apps/chat/tests/unit/skills-store.test.ts diff --git a/ui/apps/chat/README.md b/ui/apps/chat/README.md index 19f0985b402d..ef8230b33324 100644 --- a/ui/apps/chat/README.md +++ b/ui/apps/chat/README.md @@ -157,10 +157,12 @@ sequenceDiagram ### Extensions (`src/lib/extensions/`) -An extension is a feature the app is composed with and that can be switched off. The registry (`registry.svelte.ts`) knows the built-in extensions (`builtin.ts`), activates the ones that are on at startup, and holds what they add to each extension point (`points/`): tools, flow hooks, settings actions, slash commands, pickers, pending attachments, message and attachment renderers, and sources of prompts. +An extension is a feature the app is composed with and that can be switched off. The registry (`registry.svelte.ts`) knows the built-in extensions (`builtin.ts`), activates the ones that are on at startup, and holds what they add to each extension point (`points/`): tools, flow hooks, settings actions, slash commands, pickers, pending attachments, message and attachment renderers, and sources of prompts and of skills. A prompt is one kind of item whatever it comes from. The library (`promptsStore`, the Library page) is the app's own source of prompts, and an extension adds another through `promptSources`: MCP lists the prompts of its servers. `/prompt` and the System message list in the chat form's + menu show the prompts of every source together, each with where it comes from, and either sends a prompt with a message or makes it the chat's system message. +Skills are listed the same way, to browse and read: the Library's Skills tab shows the skills found in `~/.agents/skills` and `~/.claude/skills` on the machine llama-server runs on, read through llama-server's file tools (`skillsStore`, `LocalSkillsService`), and an extension adds another source through `skillSources`: MCP lists the skills its servers publish. + The core never imports an extension's own code; an extension may import the core. ESLint enforces this: a file outside `src/lib/extensions//` cannot import from that folder. Extensions are switched on and off in Settings, in the Extensions section. A switch takes effect at once: the extension's contributions go away and its cleanups run (MCP closes its connections). The choice is kept in localStorage and read at startup. diff --git a/ui/apps/chat/src/lib/components/app/dialogs/DialogSkill.svelte b/ui/apps/chat/src/lib/components/app/dialogs/DialogSkill.svelte new file mode 100644 index 000000000000..898f4572d209 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/dialogs/DialogSkill.svelte @@ -0,0 +1,79 @@ + + + + + + + {entry?.name} + + {#if entry} + {entry.origin} + {/if} + + + {entry?.description} + + +
+ {#if error} + + {:else if instructions === null} +
+ {#each SKELETON_WIDTH_CLASSES as width (width)} + + {/each} +
+ {:else} + + {/if} +
+
+
diff --git a/ui/apps/chat/src/lib/components/app/dialogs/index.ts b/ui/apps/chat/src/lib/components/app/dialogs/index.ts index adb66509415d..c3da04a402ae 100644 --- a/ui/apps/chat/src/lib/components/app/dialogs/index.ts +++ b/ui/apps/chat/src/lib/components/app/dialogs/index.ts @@ -139,6 +139,14 @@ export { default as DialogConversationRename } from './DialogConversationRename. */ export { default as DialogPromptUpdate } from './DialogPromptUpdate.svelte'; +/** + * **DialogSkill** - Read a skill's SKILL.md + * + * Opened from a row of the Library's Skills tab: the skill's name, where it comes + * from and its description, then its instructions, read when the dialog opens. + */ +export { default as DialogSkill } from './DialogSkill.svelte'; + /** * **DialogPrompt** - Name, describe and write a library prompt * diff --git a/ui/apps/chat/src/lib/components/app/library/LibrarySkillRow.svelte b/ui/apps/chat/src/lib/components/app/library/LibrarySkillRow.svelte new file mode 100644 index 000000000000..bad64a59bc3c --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/library/LibrarySkillRow.svelte @@ -0,0 +1,37 @@ + + + + diff --git a/ui/apps/chat/src/lib/components/app/library/LibrarySkills.svelte b/ui/apps/chat/src/lib/components/app/library/LibrarySkills.svelte new file mode 100644 index 000000000000..189eb9368402 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/library/LibrarySkills.svelte @@ -0,0 +1,146 @@ + + + +{#if (isLoading || toolsStore.loading) && items.length === 0} +
+ {#each { length: SKILL_ROW_SKELETONS } as _, index (index)} +
+ + +
+ + + +
+
+ {/each} +
+{:else if items.length === 0} + + + + + + + No skills found + + + {#if skillsStore.canReadLocalSkills} + Skills are folders with a SKILL.md, looked for in {LOCAL_SKILL_FOLDERS.join(' and ')}. The + skills of MCP servers are listed here too. + {:else} + Skills in {LOCAL_SKILL_FOLDERS.join(' and ')} are listed when llama-server runs with its tools + on, and the skills of MCP servers when MCP is enabled. + {/if} + + + +{:else if shown.length === 0} + + + + + + + No skills match + + Try another search. + + +{:else} + +{/if} + + opened?.source.read(entry) ?? Promise.resolve('')} +/> diff --git a/ui/apps/chat/src/lib/components/app/library/index.ts b/ui/apps/chat/src/lib/components/app/library/index.ts index b47bc2298111..5da67f5b33d8 100644 --- a/ui/apps/chat/src/lib/components/app/library/index.ts +++ b/ui/apps/chat/src/lib/components/app/library/index.ts @@ -2,11 +2,14 @@ * LIBRARY * * The Library page, in tabs: the prompts kept in the app, as cards that are sent - * in a chat or used as its system message, and the files of every conversation - * in a grid, each leading back to the message it was sent in. + * in a chat or used as its system message, the files of every conversation in a + * grid, each leading back to the message it was sent in, and the skills found on + * the machine and on MCP servers. */ export { default as LibraryAttachments } from './LibraryAttachments.svelte'; export { default as LibraryAttachmentTile } from './LibraryAttachmentTile.svelte'; export { default as LibraryPromptCard } from './LibraryPromptCard.svelte'; export { default as LibraryPrompts } from './LibraryPrompts.svelte'; +export { default as LibrarySkillRow } from './LibrarySkillRow.svelte'; +export { default as LibrarySkills } from './LibrarySkills.svelte'; diff --git a/ui/apps/chat/src/lib/constants/icons.constants.ts b/ui/apps/chat/src/lib/constants/icons.constants.ts index 344b6a4e7c7b..6f8a90a4b78b 100644 --- a/ui/apps/chat/src/lib/constants/icons.constants.ts +++ b/ui/apps/chat/src/lib/constants/icons.constants.ts @@ -11,6 +11,7 @@ import FileIcon from '@lucide/svelte/icons/file'; // not a microphone: that one is for recording and dictation import AudioIcon from '@lucide/svelte/icons/file-headphone'; import FileTextIcon from '@lucide/svelte/icons/file-text'; +import SkillIcon from '@lucide/svelte/icons/graduation-cap'; import ImageIcon from '@lucide/svelte/icons/image'; import LibraryIcon from '@lucide/svelte/icons/library'; import LoadingIcon from '@lucide/svelte/icons/loader-2'; @@ -63,6 +64,9 @@ export const LIBRARY_ICON = LibraryIcon; /** A prompt, wherever it comes from. */ export const PROMPT_ICON = PromptIcon; +/** The one icon for skills, wherever the app shows them. */ +export const SKILL_ICON = SkillIcon; + /** Boolean flag a modality drives on the ModelModalities type. */ export type ModalityKey = (typeof MODALITY_FLAG_KEYS)[keyof typeof MODALITY_FLAG_KEYS]; diff --git a/ui/apps/chat/src/lib/constants/index.ts b/ui/apps/chat/src/lib/constants/index.ts index e9be77b3973c..7bf7c14dccc8 100644 --- a/ui/apps/chat/src/lib/constants/index.ts +++ b/ui/apps/chat/src/lib/constants/index.ts @@ -75,5 +75,6 @@ export * from './get-datetime'; export * from './browser-info'; export * from './search-chats'; export * from './library.constants'; +export * from './skills.constants'; export * from './voice.constants'; export * from './sheet.constants'; diff --git a/ui/apps/chat/src/lib/constants/library.constants.ts b/ui/apps/chat/src/lib/constants/library.constants.ts index 6704e29a44cd..7fa7a2146aec 100644 --- a/ui/apps/chat/src/lib/constants/library.constants.ts +++ b/ui/apps/chat/src/lib/constants/library.constants.ts @@ -9,7 +9,8 @@ import type { Component } from 'svelte'; /** The Library's tabs, in order. */ export const LIBRARY_TABS: { label: string; search: string; value: LibraryTab }[] = [ { label: 'Prompts', search: 'Search prompts', value: LibraryTab.PROMPTS }, - { label: 'Attachments', search: 'Search attachments', value: LibraryTab.ATTACHMENTS } + { label: 'Attachments', search: 'Search attachments', value: LibraryTab.ATTACHMENTS }, + { label: 'Skills', search: 'Search skills', value: LibraryTab.SKILLS } ]; /** The mark of a file in the Library's attachments, by its kind. */ diff --git a/ui/apps/chat/src/lib/constants/skills.constants.ts b/ui/apps/chat/src/lib/constants/skills.constants.ts new file mode 100644 index 000000000000..75f3d40b8412 --- /dev/null +++ b/ui/apps/chat/src/lib/constants/skills.constants.ts @@ -0,0 +1,25 @@ +/** The file that names, describes and holds a skill. */ +export const SKILL_MANIFEST_NAME = 'SKILL.md'; + +/** + * The folders skills are looked for in, on the machine llama-server runs on, in + * order: when two hold a skill of the same name, the first one's is listed. + * `.agents/skills` is the shared folder of agents, `.claude/skills` the one + * Claude Code reads. + */ +export const LOCAL_SKILL_FOLDERS = ['~/.agents/skills', '~/.claude/skills'] as const; + +/** Every SKILL.md of a skills folder: a skill is a folder in it, with that file. */ +export const LOCAL_SKILLS_GLOB = `**/${SKILL_MANIFEST_NAME}`; + +/** A skills folder, a skill's own folder, its SKILL.md. */ +export const LOCAL_SKILLS_MAX_DEPTH = 2; + +/** Skills listed from one folder at most. */ +export const LOCAL_SKILLS_LIMIT = 200; + +/** Lines of a SKILL.md read for the list: enough to hold its frontmatter. */ +export const LOCAL_SKILL_FRONTMATTER_LINES = 40; + +/** Id of the machine's folders as a source of skills. */ +export const LOCAL_SKILLS_SOURCE_ID = 'local'; diff --git a/ui/apps/chat/src/lib/enums/library.enums.ts b/ui/apps/chat/src/lib/enums/library.enums.ts index 205ccbb04368..ecf8c072d8f8 100644 --- a/ui/apps/chat/src/lib/enums/library.enums.ts +++ b/ui/apps/chat/src/lib/enums/library.enums.ts @@ -1,5 +1,6 @@ /** The part of the Library a tab shows. */ export enum LibraryTab { ATTACHMENTS = 'attachments', - PROMPTS = 'prompts' + PROMPTS = 'prompts', + SKILLS = 'skills' } diff --git a/ui/apps/chat/src/lib/extensions/index.ts b/ui/apps/chat/src/lib/extensions/index.ts index eac34f5ae218..3912d7fb827a 100644 --- a/ui/apps/chat/src/lib/extensions/index.ts +++ b/ui/apps/chat/src/lib/extensions/index.ts @@ -24,6 +24,7 @@ export type { MessageRendererProps } from './points/renderers'; export type { SettingsAction, SettingsActionDialog } from './points/settings'; +export type { SkillEntry, SkillSource } from './points/skills'; export type { FlowHook, FlowInfo, diff --git a/ui/apps/chat/src/lib/extensions/mcp/index.ts b/ui/apps/chat/src/lib/extensions/mcp/index.ts index 823b48f9b96b..64e05a1c0817 100644 --- a/ui/apps/chat/src/lib/extensions/mcp/index.ts +++ b/ui/apps/chat/src/lib/extensions/mcp/index.ts @@ -14,6 +14,7 @@ import { contributePrompts } from './prompts'; import { contributeRenderers } from './renderers'; import { contributeSettings } from './settings'; import { contributeSignIn } from './sign-in'; +import { contributeSkillSource } from './skills/source'; import { contributeStartup } from './startup.svelte'; import { contributeTools } from './tools'; @@ -24,6 +25,7 @@ const mcp: Extension = { contributeRenderers(ctx); contributeSettings(ctx); contributeSignIn(ctx); + contributeSkillSource(ctx); contributeStartup(ctx); contributeTools(ctx); } diff --git a/ui/apps/chat/src/lib/extensions/mcp/skills/icon.ts b/ui/apps/chat/src/lib/extensions/mcp/skills/icon.ts index e8407a7822b1..cfc3065c5a0d 100644 --- a/ui/apps/chat/src/lib/extensions/mcp/skills/icon.ts +++ b/ui/apps/chat/src/lib/extensions/mcp/skills/icon.ts @@ -1,2 +1,2 @@ -/** The one icon for skills, wherever the app shows them. */ -export { default as MCP_SKILL_ICON } from '@lucide/svelte/icons/graduation-cap'; +/** The app's one icon for skills. */ +export { SKILL_ICON as MCP_SKILL_ICON } from '#lib/constants/index.ts'; diff --git a/ui/apps/chat/src/lib/extensions/mcp/skills/source.ts b/ui/apps/chat/src/lib/extensions/mcp/skills/source.ts new file mode 100644 index 000000000000..0ace5fb3408e --- /dev/null +++ b/ui/apps/chat/src/lib/extensions/mcp/skills/source.ts @@ -0,0 +1,65 @@ +/** + * MCP servers as a source of skills: the skills they publish are listed in the + * Library with the ones found on the machine, each under its server's name. + */ + +import type { SkillEntry } from '../../points/skills'; +import type { ExtensionContext } from '../../types'; +import McpLogo from '../components/McpLogo.svelte'; +import { mcpStore } from '../stores/index.svelte'; +import { skillServersInUse } from '../tools'; +import type { Skill } from '@modelcontextprotocol/client/ext/skills'; + +const MCP_SKILLS_SOURCE_ID = 'mcp'; +/** Between the server id and the URI in an entry's id: a URI alone does not say which skill. */ +const ENTRY_ID_SEPARATOR = ' '; + +export function contributeSkillSource(ctx: ExtensionContext): void { + // the skills behind the entries handed out, by entry id + let listed: Record = {}; + + ctx.contribute('skillSources', { + icon: McpLogo, + id: MCP_SKILLS_SOURCE_ID, + + async list(): Promise { + listed = {}; + + if (!(await mcpStore.ensureInitialized())) return []; + + // in the order of the servers; a server that fails to list leaves the others' skills + const serverIds = skillServersInUse(); + const listings = await Promise.allSettled( + serverIds.map((serverId) => mcpStore.skills.list(serverId)) + ); + + return listings.flatMap((listing, index) => { + if (listing.status === 'rejected') return []; + + const serverId = serverIds[index]; + + return listing.value.map((skill): SkillEntry => { + const id = `${serverId}${ENTRY_ID_SEPARATOR}${skill.uri}`; + + listed[id] = { serverId, skill }; + + return { + description: skill.frontmatter.description, + id, + name: skill.frontmatter.name, + origin: mcpStore.getServerDisplayName(serverId) + }; + }); + }); + }, + + // a verified read, as the server card's Read SKILL.md does: looking at a skill is not loading it + async read(entry): Promise { + const item = listed[entry.id]; + + if (!item) throw new Error(`The skill "${entry.name}" is no longer listed`); + + return (await mcpStore.skills.read(item.serverId, item.skill)).text ?? ''; + } + }); +} diff --git a/ui/apps/chat/src/lib/extensions/points/skills.ts b/ui/apps/chat/src/lib/extensions/points/skills.ts new file mode 100644 index 000000000000..d0504522e1de --- /dev/null +++ b/ui/apps/chat/src/lib/extensions/points/skills.ts @@ -0,0 +1,29 @@ +/** + * The skill sources point. A skill is one kind of item whatever it comes from: + * the skills folders of the machine are the app's own source, and an extension + * adds another, such as the skills MCP servers publish. The Library lists them + * together. + */ + +import type { Component } from 'svelte'; + +/** A skill as the Library lists it. */ +export interface SkillEntry { + /** Stable identity within its source. */ + id: string; + name: string; + description: string; + /** Where the skill comes from, on its badge: a folder, or an MCP server's name. */ + origin: string; +} + +/** A place skills come from. */ +export interface SkillSource { + id: string; + /** Drawn on the tile of each of the source's skills. */ + icon: Component<{ class?: string }>; + /** The skills on offer. Called each time the list shows. */ + list(): Promise; + /** The text of the skill's SKILL.md, for the user to read. */ + read(entry: SkillEntry): Promise; +} diff --git a/ui/apps/chat/src/lib/extensions/types.ts b/ui/apps/chat/src/lib/extensions/types.ts index 2d9077884dd9..d2e3df136f32 100644 --- a/ui/apps/chat/src/lib/extensions/types.ts +++ b/ui/apps/chat/src/lib/extensions/types.ts @@ -11,6 +11,7 @@ import type { ModelDownloadAuth, ModelNotice } from './points/models'; import type { PromptSource } from './points/prompts'; import type { AttachmentRenderer, MessageRenderer } from './points/renderers'; import type { SettingsAction } from './points/settings'; +import type { SkillSource } from './points/skills'; import type { FlowHook, ToolProvider } from './points/tools'; /** What the app knows about an extension before its code is loaded. */ @@ -78,6 +79,8 @@ export interface ExtensionPoints { messageRenderers: MessageRenderer; /** A connector's sign-in for the servers of its service. */ serverAuth: ServerAuth; + /** Skills from somewhere other than the machine's folders, listed with those in the Library. */ + skillSources: SkillSource; /** Actions under the extension's settings, each opening what it manages from Settings. */ settingsActions: SettingsAction; /** Tools the model can call, listed and run by the extension. */ diff --git a/ui/apps/chat/src/lib/services/local-skills.service.ts b/ui/apps/chat/src/lib/services/local-skills.service.ts new file mode 100644 index 000000000000..e8610e7c4cfe --- /dev/null +++ b/ui/apps/chat/src/lib/services/local-skills.service.ts @@ -0,0 +1,84 @@ +/** + * LocalSkillsService - Skills in the folders of the machine llama-server runs on + * + * A page cannot read a folder, so the skills are found and read through + * llama-server's file tools (`file_glob_search`, `read_file`), which take `~` + * for the home folder. Read-only. No state. + */ + +import { + LOCAL_SKILL_FRONTMATTER_LINES, + LOCAL_SKILLS_GLOB, + LOCAL_SKILLS_LIMIT, + LOCAL_SKILLS_MAX_DEPTH, + PATH_SEPARATOR +} from '#lib/constants/index.ts'; +import { BuiltInTool, GlobSearchType, ToolResponseField } from '#lib/enums/index.ts'; +import { ToolsService } from '#lib/services/tools.service.ts'; +import type { GlobEntry } from '#lib/types/index.ts'; +import { joinPath, parseSkillFrontmatter } from '#lib/utils/index.ts'; + +/** A skill found in a folder. */ +export interface LocalSkill { + description: string; + /** The skills folder it was found in, as the app names it, e.g. `~/.agents/skills`. */ + folder: string; + name: string; + /** Where its SKILL.md is on the machine. */ + path: string; +} + +export class LocalSkillsService { + /** + * The skills of one folder. A folder that is not there has none; a skill whose + * SKILL.md cannot be read is left out. + */ + static async list(folder: string): Promise { + const found = await ToolsService.executeToolRaw(BuiltInTool.SERVER_FILE_GLOB_SEARCH, { + include: LOCAL_SKILLS_GLOB, + limit: LOCAL_SKILLS_LIMIT, + max_depth: LOCAL_SKILLS_MAX_DEPTH, + path: folder, + type: GlobSearchType.FILE + }); + + if (ToolResponseField.ERROR in found) return []; + + const base = typeof found.base === 'string' ? found.base : folder; + const manifests = Array.isArray(found.entries) ? (found.entries as GlobEntry[]) : []; + const skills = await Promise.allSettled( + manifests.map(async (manifest): Promise => { + const path = joinPath(base, manifest.path); + const frontmatter = parseSkillFrontmatter( + await LocalSkillsService.readLines(path, LOCAL_SKILL_FRONTMATTER_LINES) + ); + + return { + description: frontmatter.description ?? '', + folder, + // a SKILL.md that does not name its skill is known by its folder + name: frontmatter.name ?? manifest.path.split(PATH_SEPARATOR)[0], + path + }; + }) + ); + + return skills.flatMap((skill) => (skill.status === 'fulfilled' ? [skill.value] : [])); + } + + /** The whole SKILL.md of a skill. */ + static read(skill: Pick): Promise { + return LocalSkillsService.readLines(skill.path); + } + + private static async readLines(path: string, lines?: number): Promise { + const result = await ToolsService.executeToolRaw(BuiltInTool.SERVER_READ_FILE, { + path, + ...(lines === undefined ? {} : { end_line: lines }) + }); + + if (ToolResponseField.ERROR in result) throw new Error(String(result[ToolResponseField.ERROR])); + + return String(result[ToolResponseField.PLAIN_TEXT] ?? ''); + } +} diff --git a/ui/apps/chat/src/lib/stores/index.ts b/ui/apps/chat/src/lib/stores/index.ts index be73c1f63a32..dbbadf9ecbe1 100644 --- a/ui/apps/chat/src/lib/stores/index.ts +++ b/ui/apps/chat/src/lib/stores/index.ts @@ -53,6 +53,9 @@ export { libraryAttachmentsStore } from './library-attachments.svelte'; // PROMPTS (the library's prompts, and every source of prompts) export { promptsStore } from './prompts.svelte'; +// SKILLS (every source of skills: the machine's folders, and what extensions add) +export { skillsStore } from './skills.svelte'; + // SERVER export { serverStore } from './llama-server.svelte'; diff --git a/ui/apps/chat/src/lib/stores/skills.svelte.ts b/ui/apps/chat/src/lib/stores/skills.svelte.ts new file mode 100644 index 000000000000..0a013e63370b --- /dev/null +++ b/ui/apps/chat/src/lib/stores/skills.svelte.ts @@ -0,0 +1,87 @@ +/** + * skillsStore - Every source of skills + * + * The skills folders of the machine llama-server runs on are the app's own + * source; `sources` lists it with the ones extensions add, such as the skills + * MCP servers publish. Nothing is kept: a list is read when it shows. + */ + +import { LOCAL_SKILL_FOLDERS, LOCAL_SKILLS_SOURCE_ID, SKILL_ICON } from '#lib/constants/index.ts'; +import { BuiltInTool } from '#lib/enums/index.ts'; +import { extensions, type SkillEntry, type SkillSource } from '#lib/extensions/index.ts'; +import { type LocalSkill, LocalSkillsService } from '#lib/services/local-skills.service.ts'; +import { toolsStore } from '#lib/stores/tools.svelte.ts'; + +/** What reading the skills folders takes of llama-server. */ +const LOCAL_SKILL_TOOLS: readonly string[] = [ + BuiltInTool.SERVER_FILE_GLOB_SEARCH, + BuiltInTool.SERVER_READ_FILE +]; + +class SkillsStore { + // the skills behind the entries handed out, by entry id + private listed = new Map(); + + /** The machine's skills folders as a source of skills, the first of `sources`. */ + private readonly localSource: SkillSource = { + icon: SKILL_ICON, + id: LOCAL_SKILLS_SOURCE_ID, + list: async () => { + this.listed = new Map(); + + if (!this.canReadLocalSkills) return []; + + const folders = await Promise.allSettled( + LOCAL_SKILL_FOLDERS.map((folder) => LocalSkillsService.list(folder)) + ); + + for (const folder of folders) { + if (folder.status === 'rejected') { + console.error('Failed to list a skills folder:', folder.reason); + + continue; + } + + // a name found in an earlier folder is that folder's skill + for (const skill of folder.value) { + if (!this.listed.has(skill.name)) this.listed.set(skill.name, skill); + } + } + + return [...this.listed.values()] + .sort((a, b) => a.name.localeCompare(b.name)) + .map( + (skill): SkillEntry => ({ + description: skill.description, + id: skill.name, + name: skill.name, + origin: skill.folder + }) + ); + }, + read: async (entry) => { + const skill = this.listed.get(entry.id); + + if (!skill) throw new Error(`The skill "${entry.name}" is no longer listed`); + + return LocalSkillsService.read(skill); + } + }; + + /** + * Whether the skills folders can be read: llama-server has to offer its file + * tools, which it does when it is started with tools on. + */ + get canReadLocalSkills(): boolean { + const offered = toolsStore.serverTools.map((tool) => tool.function.name); + + return LOCAL_SKILL_TOOLS.every((tool) => offered.includes(tool)); + } + + /** Where skills come from: the machine's folders, then what extensions add, such as MCP servers. */ + get sources(): SkillSource[] { + return [this.localSource, ...extensions.contributions('skillSources')]; + } +} + +export const skillsStore = new SkillsStore(); diff --git a/ui/apps/chat/src/lib/utils/index.ts b/ui/apps/chat/src/lib/utils/index.ts index 312502d0f7c8..f1d4ba10eb2f 100644 --- a/ui/apps/chat/src/lib/utils/index.ts +++ b/ui/apps/chat/src/lib/utils/index.ts @@ -261,6 +261,9 @@ export { type LibraryAttachment } from './library-attachments'; +// A SKILL.md: what it says about its skill, and its instructions +export { parseSkillFrontmatter, skillInstructions, type SkillFrontmatter } from './skill-manifest'; + // A jump to a message of the open conversation export { findMessageRowId, diff --git a/ui/apps/chat/src/lib/utils/skill-manifest.ts b/ui/apps/chat/src/lib/utils/skill-manifest.ts new file mode 100644 index 000000000000..c36aff821914 --- /dev/null +++ b/ui/apps/chat/src/lib/utils/skill-manifest.ts @@ -0,0 +1,93 @@ +/** + * Reading a SKILL.md: the frontmatter that names and describes the skill, and + * the instructions after it. Only `name` and `description` are read: nothing in + * a frontmatter changes what the app or the model may do. + */ + +/** What a SKILL.md says about itself. */ +export interface SkillFrontmatter { + description?: string; + name?: string; +} + +const FRONTMATTER_FENCE = '---'; +const KEY_SEPARATOR = ':'; +const LINE_BREAK = '\n'; +const CARRIAGE_RETURN = '\r'; +/** A value that starts with one of these goes on in the indented lines below it. */ +const BLOCK_SCALAR_MARKS = ['>', '|']; +const QUOTES = ['"', "'"]; +const READ_KEYS: readonly (keyof SkillFrontmatter)[] = ['description', 'name']; + +/** The lines of the frontmatter, and the line the instructions start at. Without a frontmatter, none and 0. */ +function frontmatterOf(lines: string[]): { end: number; frontmatter: string[] } { + if (lines[0]?.trim() !== FRONTMATTER_FENCE) return { end: 0, frontmatter: [] }; + + const close = lines.findIndex((line, index) => index > 0 && line.trim() === FRONTMATTER_FENCE); + + // a fence that never closes is not a frontmatter + return close < 0 + ? { end: 0, frontmatter: [] } + : { end: close + 1, frontmatter: lines.slice(1, close) }; +} + +function linesOf(text: string): string[] { + return text + .split(LINE_BREAK) + .map((line) => (line.endsWith(CARRIAGE_RETURN) ? line.slice(0, -1) : line)); +} + +function isIndented(line: string): boolean { + return line !== line.trimStart(); +} + +function unquote(value: string): string { + const quote = QUOTES.find( + (mark) => value.length > 1 && value.startsWith(mark) && value.endsWith(mark) + ); + + return quote ? value.slice(1, -1) : value; +} + +/** + * The name and description a SKILL.md gives in its frontmatter. A value can be + * plain, quoted, or a block that goes on in the indented lines below; either + * way it is read as one line of text. + */ +export function parseSkillFrontmatter(text: string): SkillFrontmatter { + const { frontmatter } = frontmatterOf(linesOf(text)); + const result: SkillFrontmatter = {}; + + for (const [index, line] of frontmatter.entries()) { + const separator = line.indexOf(KEY_SEPARATOR); + + if (separator < 0 || isIndented(line)) continue; + + const key = READ_KEYS.find((name) => name === line.slice(0, separator).trim()); + + if (!key) continue; + + const first = line.slice(separator + 1).trim(); + const below: string[] = []; + + for (const next of frontmatter.slice(index + 1)) { + if (next.trim() && !isIndented(next)) break; + + if (next.trim()) below.push(next.trim()); + } + + const isBlock = BLOCK_SCALAR_MARKS.some((mark) => first.startsWith(mark)); + const value = [...(isBlock ? [] : [first]), ...below].filter(Boolean).join(' '); + + if (value) result[key] = isBlock ? value : unquote(value); + } + + return result; +} + +/** The instructions of a SKILL.md: its text without the frontmatter. */ +export function skillInstructions(text: string): string { + const lines = linesOf(text); + + return lines.slice(frontmatterOf(lines).end).join(LINE_BREAK).trim(); +} diff --git a/ui/apps/chat/src/routes/library/+page.svelte b/ui/apps/chat/src/routes/library/+page.svelte index d1e9fdb3913f..34f613ad39c3 100644 --- a/ui/apps/chat/src/routes/library/+page.svelte +++ b/ui/apps/chat/src/routes/library/+page.svelte @@ -2,7 +2,12 @@ import { Button } from '@ggml-org/llama-ui/ui/button'; import * as Tabs from '@ggml-org/llama-ui/ui/tabs'; import { Plus } from '@lucide/svelte'; - import { LibraryAttachments, LibraryPrompts, SearchInput } from '#lib/components/app/index.ts'; + import { + LibraryAttachments, + LibraryPrompts, + LibrarySkills, + SearchInput + } from '#lib/components/app/index.ts'; import { APP_NAME, LIBRARY_TABS } from '#lib/constants/index.ts'; import { LibraryTab } from '#lib/enums/index.ts'; @@ -25,7 +30,7 @@

Library

- The prompts you reuse and the files of your chats, in one place. + The prompts you reuse, the files of your chats and the skills at hand, in one place.

@@ -59,11 +64,17 @@ + while it is: the files and the skills are read when their tab opens --> {#if tab === LibraryTab.ATTACHMENTS} {/if} + + + {#if tab === LibraryTab.SKILLS} + + {/if} + diff --git a/ui/apps/chat/tests/unit/local-skills-service.test.ts b/ui/apps/chat/tests/unit/local-skills-service.test.ts new file mode 100644 index 000000000000..b38e16eefb84 --- /dev/null +++ b/ui/apps/chat/tests/unit/local-skills-service.test.ts @@ -0,0 +1,107 @@ +// The skills of a folder are found and read through llama-server's file tools: one +// search for the SKILL.md files, then the top of each for its name and description. + +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +vi.mock('#lib/services/tools.service.ts', () => ({ + ToolsService: { executeToolRaw: vi.fn() } +})); + +import { LOCAL_SKILL_FRONTMATTER_LINES, LOCAL_SKILLS_GLOB } from '#lib/constants/index.ts'; +import { BuiltInTool, GlobSearchType } from '#lib/enums/index.ts'; +import { LocalSkillsService } from '#lib/services/local-skills.service.ts'; +import { ToolsService } from '#lib/services/tools.service.ts'; + +const executeToolRaw = vi.mocked(ToolsService.executeToolRaw); +const FOLDER = '~/.agents/skills'; +const BASE = '/home/me/.agents/skills'; +const FILES: Record = { + [`${BASE}/animate/SKILL.md`]: + '---\nname: animate\ndescription: Build an animation.\n---\n\n# Animations', + [`${BASE}/unnamed/SKILL.md`]: '# No frontmatter here' +}; + +/** llama-server's file tools over a folder with the files above. */ +function serveFolder(entries = Object.keys(FILES)) { + executeToolRaw.mockImplementation(async (tool, params) => { + if (tool === BuiltInTool.SERVER_FILE_GLOB_SEARCH) { + return { + base: BASE, + entries: entries.map((path) => ({ path: path.slice(BASE.length + 1), type: 'file' })) + }; + } + + const text = FILES[String(params.path)]; + + return text === undefined ? { error: 'file not found' } : { plain_text_response: text }; + }); +} + +describe('LocalSkillsService', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('finds the SKILL.md files of a folder and reads the top of each', async () => { + serveFolder(); + + const skills = await LocalSkillsService.list(FOLDER); + + expect(executeToolRaw).toHaveBeenCalledWith( + BuiltInTool.SERVER_FILE_GLOB_SEARCH, + expect.objectContaining({ + include: LOCAL_SKILLS_GLOB, + path: FOLDER, + type: GlobSearchType.FILE + }) + ); + expect(executeToolRaw).toHaveBeenCalledWith(BuiltInTool.SERVER_READ_FILE, { + end_line: LOCAL_SKILL_FRONTMATTER_LINES, + path: `${BASE}/animate/SKILL.md` + }); + expect(skills).toEqual([ + { + description: 'Build an animation.', + folder: FOLDER, + name: 'animate', + path: `${BASE}/animate/SKILL.md` + }, + // known by its folder when the SKILL.md does not name it + { description: '', folder: FOLDER, name: 'unnamed', path: `${BASE}/unnamed/SKILL.md` } + ]); + }); + + it('has no skills for a folder that is not there', async () => { + executeToolRaw.mockResolvedValue({ error: 'path does not exist or is not a directory' }); + + expect(await LocalSkillsService.list('~/.claude/skills')).toEqual([]); + expect(executeToolRaw).toHaveBeenCalledOnce(); + }); + + it('leaves out a skill whose SKILL.md cannot be read', async () => { + serveFolder([...Object.keys(FILES), `${BASE}/broken/SKILL.md`]); + + const skills = await LocalSkillsService.list(FOLDER); + + expect(skills.map((skill) => skill.name)).toEqual(['animate', 'unnamed']); + }); + + it('reads the whole SKILL.md of a skill', async () => { + serveFolder(); + + const text = await LocalSkillsService.read({ path: `${BASE}/animate/SKILL.md` }); + + expect(text).toContain('# Animations'); + expect(executeToolRaw).toHaveBeenLastCalledWith(BuiltInTool.SERVER_READ_FILE, { + path: `${BASE}/animate/SKILL.md` + }); + }); + + it('says why a SKILL.md could not be read', async () => { + serveFolder(); + + await expect(LocalSkillsService.read({ path: `${BASE}/gone/SKILL.md` })).rejects.toThrow( + 'file not found' + ); + }); +}); diff --git a/ui/apps/chat/tests/unit/mcp-skill-source.test.ts b/ui/apps/chat/tests/unit/mcp-skill-source.test.ts new file mode 100644 index 000000000000..995b2c26e656 --- /dev/null +++ b/ui/apps/chat/tests/unit/mcp-skill-source.test.ts @@ -0,0 +1,125 @@ +// MCP servers are a source of skills through the skillSources extension point: the +// skills they publish are listed with their server, and one's SKILL.md is read +// verified, without loading it for the model. + +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +vi.mock('#lib/extensions/mcp/stores/index.svelte.ts', () => ({ + mcpStore: { + ensureInitialized: vi.fn(), + getServerDisplayName: vi.fn(), + skills: { list: vi.fn(), read: vi.fn() } + } +})); +vi.mock('#lib/extensions/mcp/tools.ts', () => ({ skillServersInUse: vi.fn() })); +vi.mock('#lib/extensions/mcp/components/McpLogo.svelte', () => ({ default: () => {} })); + +import type { Skill } from '@modelcontextprotocol/client/ext/skills'; +import type { ExtensionContext, SkillSource } from '#lib/extensions/index.ts'; +import { contributeSkillSource } from '#lib/extensions/mcp/skills/source.ts'; +import { mcpStore } from '#lib/extensions/mcp/stores/index.svelte.ts'; +import { skillServersInUse } from '#lib/extensions/mcp/tools.ts'; + +function skill(name: string, uri: string): Skill { + return { frontmatter: { description: `What ${name} is for`, name }, resources: [], uri } as Skill; +} + +const HF_MEM = skill('hf-mem', 'skill://hf-mem'); +const HF_CLI = skill('hf-cli', 'skill://hf-cli'); +// the same URI on another server is another skill +const OTHER = skill('hf-mem', 'skill://hf-mem'); + +function activate(): SkillSource { + let source: SkillSource | undefined; + + const ctx: ExtensionContext = { + contribute: (point, contribution) => { + if (point === 'skillSources') source = contribution as SkillSource; + }, + onDeactivate: () => {} + }; + + contributeSkillSource(ctx); + + if (!source) throw new Error('no source contributed'); + + return source; +} + +describe('MCP as a source of skills', () => { + beforeEach(() => { + vi.clearAllMocks(); + vi.mocked(mcpStore.ensureInitialized).mockResolvedValue(true); + vi.mocked(skillServersInUse).mockReturnValue(['hf', 'docs']); + vi.mocked(mcpStore.getServerDisplayName).mockImplementation((id) => + id === 'hf' ? 'Hugging Face' : 'Docs' + ); + vi.mocked(mcpStore.skills.list).mockImplementation(async (serverId) => + serverId === 'hf' ? [HF_MEM, HF_CLI] : [OTHER] + ); + }); + + it('lists the skills of the servers in use, in their order, each under its server', async () => { + expect(await activate().list()).toEqual([ + { + description: 'What hf-mem is for', + id: 'hf skill://hf-mem', + name: 'hf-mem', + origin: 'Hugging Face' + }, + { + description: 'What hf-cli is for', + id: 'hf skill://hf-cli', + name: 'hf-cli', + origin: 'Hugging Face' + }, + { + description: 'What hf-mem is for', + id: 'docs skill://hf-mem', + name: 'hf-mem', + origin: 'Docs' + } + ]); + }); + + it('keeps the skills of the other servers when one fails to list', async () => { + vi.mocked(mcpStore.skills.list).mockImplementation(async (serverId) => { + if (serverId === 'hf') throw new Error('server went away'); + + return [OTHER]; + }); + + expect((await activate().list()).map((entry) => entry.origin)).toEqual(['Docs']); + }); + + it('lists nothing when MCP could not initialize', async () => { + vi.mocked(mcpStore.ensureInitialized).mockResolvedValue(false); + + expect(await activate().list()).toEqual([]); + expect(mcpStore.skills.list).not.toHaveBeenCalled(); + }); + + it('reads the SKILL.md of a listed skill from its own server', async () => { + vi.mocked(mcpStore.skills.read).mockResolvedValue({ + text: '# hf-mem', + uri: 'skill://hf-mem/SKILL.md' + } as Awaited>); + + const source = activate(); + const entries = await source.list(); + + expect(await source.read(entries[2])).toBe('# hf-mem'); + expect(mcpStore.skills.read).toHaveBeenCalledWith('docs', OTHER); + }); + + it('refuses to read a skill it did not list', async () => { + const source = activate(); + + await source.list(); + + await expect( + source.read({ description: '', id: 'hf skill://unknown', name: 'unknown', origin: 'HF' }) + ).rejects.toThrow('no longer listed'); + expect(mcpStore.skills.read).not.toHaveBeenCalled(); + }); +}); diff --git a/ui/apps/chat/tests/unit/skill-manifest.test.ts b/ui/apps/chat/tests/unit/skill-manifest.test.ts new file mode 100644 index 000000000000..30534bfa0918 --- /dev/null +++ b/ui/apps/chat/tests/unit/skill-manifest.test.ts @@ -0,0 +1,83 @@ +// A SKILL.md names and describes its skill in a frontmatter, which the Library reads +// to list the skill; the instructions after it are what a reader opens. + +import { parseSkillFrontmatter, skillInstructions } from '#lib/utils/skill-manifest.ts'; +import { describe, expect, it } from 'vitest'; + +describe('the frontmatter of a SKILL.md', () => { + it('gives the name and a description written on one line', () => { + const text = + '---\nname: animate\ndescription: Build an animation from scratch: curve, duration, exit.\n---\n\n# Animations'; + + expect(parseSkillFrontmatter(text)).toEqual({ + description: 'Build an animation from scratch: curve, duration, exit.', + name: 'animate' + }); + }); + + it('reads a folded or literal description as one line', () => { + const folded = + '---\nname: gh-stack\ndescription: >\n Manages stacked PRs\n and splits work.\n\n Use for stacks.\nmetadata:\n author: github\n---\n'; + const literal = '---\ndescription: |-\n First line\n second line\nname: notes\n---\n'; + + expect(parseSkillFrontmatter(folded)).toEqual({ + description: 'Manages stacked PRs and splits work. Use for stacks.', + name: 'gh-stack' + }); + expect(parseSkillFrontmatter(literal)).toEqual({ + description: 'First line second line', + name: 'notes' + }); + }); + + it('reads a plain value that goes on in the indented lines below', () => { + const text = '---\nname: wide\ndescription: Starts here\n and goes on.\n---\n'; + + expect(parseSkillFrontmatter(text).description).toBe('Starts here and goes on.'); + }); + + it('takes the quotes off a quoted value', () => { + const text = '---\nname: "quoted: name"\ndescription: \'It is quoted\'\n---\n'; + + expect(parseSkillFrontmatter(text)).toEqual({ + description: 'It is quoted', + name: 'quoted: name' + }); + }); + + it('reads only its own keys, never one nested under another', () => { + const text = + '---\nmetadata:\n name: inner\n description: not this\nallowed-tools: Bash\nname: outer\n---\n'; + + expect(parseSkillFrontmatter(text)).toEqual({ name: 'outer' }); + }); + + it('reads Windows line ends', () => { + expect( + parseSkillFrontmatter('---\r\nname: crlf\r\ndescription: Ends in CR LF\r\n---\r\n') + ).toEqual({ + description: 'Ends in CR LF', + name: 'crlf' + }); + }); + + it('gives nothing without a frontmatter, or with one that never closes', () => { + expect(parseSkillFrontmatter('# Just instructions\nname: not a key')).toEqual({}); + expect(parseSkillFrontmatter('---\nname: open\n\n# No closing fence')).toEqual({}); + expect(parseSkillFrontmatter('')).toEqual({}); + }); +}); + +describe('the instructions of a SKILL.md', () => { + it('are the text after the frontmatter', () => { + expect(skillInstructions('---\nname: animate\n---\n\n# Animations\n\nDo it well.\n')).toBe( + '# Animations\n\nDo it well.' + ); + }); + + it('are the whole text when there is no frontmatter', () => { + expect(skillInstructions('# Animations\n\n---\n\nA rule is not a fence.')).toBe( + '# Animations\n\n---\n\nA rule is not a fence.' + ); + }); +}); diff --git a/ui/apps/chat/tests/unit/skills-store.test.ts b/ui/apps/chat/tests/unit/skills-store.test.ts new file mode 100644 index 000000000000..e7795f4ca8b9 --- /dev/null +++ b/ui/apps/chat/tests/unit/skills-store.test.ts @@ -0,0 +1,99 @@ +// The machine's skills folders are one source of skills, listed before the ones +// extensions add: read only when llama-server offers its file tools, one skill per +// name, the first folder's when two folders hold the same name. + +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +vi.mock('#lib/services/local-skills.service.ts', () => ({ + LocalSkillsService: { list: vi.fn(), read: vi.fn() } +})); + +const offeredTools = vi.hoisted(() => ({ names: [] as string[] })); + +vi.mock('#lib/stores/tools.svelte.ts', () => ({ + toolsStore: { + get serverTools() { + return offeredTools.names.map((name) => ({ function: { name } })); + } + } +})); + +import { LOCAL_SKILL_FOLDERS, LOCAL_SKILLS_SOURCE_ID } from '#lib/constants/index.ts'; +import { BuiltInTool } from '#lib/enums/index.ts'; +import { type LocalSkill, LocalSkillsService } from '#lib/services/local-skills.service.ts'; +import { skillsStore } from '#lib/stores/skills.svelte.ts'; + +const list = vi.mocked(LocalSkillsService.list); +const read = vi.mocked(LocalSkillsService.read); +const [AGENTS, CLAUDE] = LOCAL_SKILL_FOLDERS; + +function skill(name: string, folder: string, description = `${name} of ${folder}`): LocalSkill { + return { description, folder, name, path: `${folder}/${name}/SKILL.md` }; +} + +describe('skillsStore', () => { + const [local] = skillsStore.sources; + + beforeEach(() => { + vi.clearAllMocks(); + offeredTools.names = [BuiltInTool.SERVER_FILE_GLOB_SEARCH, BuiltInTool.SERVER_READ_FILE]; + list.mockImplementation(async (folder) => + folder === AGENTS + ? [skill('write-swift', AGENTS), skill('animate', AGENTS)] + : [skill('animate', CLAUDE), skill('prototype', CLAUDE)] + ); + }); + + it('lists the folders of the machine first, by name, each skill under its folder', async () => { + expect(local.id).toBe(LOCAL_SKILLS_SOURCE_ID); + expect(await local.list()).toEqual([ + // in both folders: the first folder's + { description: `animate of ${AGENTS}`, id: 'animate', name: 'animate', origin: AGENTS }, + { description: `prototype of ${CLAUDE}`, id: 'prototype', name: 'prototype', origin: CLAUDE }, + { + description: `write-swift of ${AGENTS}`, + id: 'write-swift', + name: 'write-swift', + origin: AGENTS + } + ]); + expect(list.mock.calls.map(([folder]) => folder)).toEqual([...LOCAL_SKILL_FOLDERS]); + }); + + it('lists nothing, and asks for nothing, when llama-server offers no file tools', async () => { + offeredTools.names = [BuiltInTool.SERVER_READ_FILE]; + + expect(skillsStore.canReadLocalSkills).toBe(false); + expect(await local.list()).toEqual([]); + expect(list).not.toHaveBeenCalled(); + }); + + it('keeps the skills of the other folders when one cannot be listed', async () => { + vi.spyOn(console, 'error').mockImplementation(() => {}); + list.mockImplementation(async (folder) => { + if (folder === AGENTS) throw new Error('llama-server is not reachable'); + + return [skill('prototype', CLAUDE)]; + }); + + expect((await local.list()).map((entry) => entry.name)).toEqual(['prototype']); + }); + + it('reads the SKILL.md of a listed skill from the folder it was listed from', async () => { + read.mockResolvedValue('# Animations'); + + const [animate] = await local.list(); + + expect(await local.read(animate)).toBe('# Animations'); + expect(read).toHaveBeenCalledWith(skill('animate', AGENTS)); + }); + + it('refuses to read a skill it did not list', async () => { + await local.list(); + + await expect( + local.read({ description: '', id: 'unknown', name: 'unknown', origin: AGENTS }) + ).rejects.toThrow('no longer listed'); + expect(read).not.toHaveBeenCalled(); + }); +});