/** * Skill 注册表(有状态、带热载) * * 职责: * 1. 启动时扫描 project + user 两层 skills 目录,构建内存索引 * 2. 提供 CRUD(list / get / create / update / delete / toggle) * 3. 通过 chokidar 监听两层目录的变更,去抖 200ms 后增量重载并 emit resource:changed * 4. 暴露 listSkillSlashCommands() 供 chat-meta 列入 / 命令补全 * * 覆盖语义:项目级与用户级同名时,项目级 wins;两个版本都保留在 records 中, * getSkill(name) 默认返回 winning(project),getSkill(name, 'user') 可显式取被遮蔽的那份。 */ import type { ResourceScope } from '../types.js'; import { type ParsedSkill, type SkillFrontmatter } from './loader.js'; /** 公开的 skill 摘要(list 用),不含完整 markdown,避免大量 IO。 */ export interface SkillSummary { name: string; scope: ResourceScope; status: 'loaded' | 'disabled' | 'error'; description?: string; version?: string; enabled: boolean; allowedTools?: string[]; /** 被同名项目级 skill 遮蔽时为 true(仅 user 层条目可能为 true)。 */ shadowed: boolean; error?: string; lastReloadAt?: string; scriptsCount: number; assetsCount: number; } /** Slash 命令补全条目。 */ export interface SkillSlashCommand { /** 形如 "/skill:my-skill",前端按字面拼接展示。 */ command: string; description: string; /** 触发后注入到对话的内容(SKILL.md 正文,可能含 frontmatter 提示)。 */ payload: string; /** 来源 skill 名,便于点击跳转编辑。 */ skill: string; scope: ResourceScope; } declare class SkillRegistry { /** key = `${scope}:${name}`,避免 project/user 同名互相覆盖记录。 */ private records; private watchers; private debounceTimer; private initialized; private lastReloadAt; /** 启动:确保目录存在、首次扫描、启动 watcher。多次调用幂等。 */ init(): void; /** 关闭 watcher、清空缓存。 */ dispose(): Promise; /** 全量重载(启动、手动 reload、目录批量变更时使用)。 */ fullReload(_reason: string): void; /** 启动文件监听。两层目录都监听;不存在的目录会被 chokidar 忍受。 */ private startWatchers; private scheduleReload; /** 列出所有 skill 摘要(含 user 被遮蔽的那一份)。 */ list(): SkillSummary[]; /** * 获取单个 skill 的完整内容。 * 不指定 scope 时返回 winning 版本(project 优先),便于编辑器载入。 */ get(name: string, scope?: ResourceScope): ParsedSkill | null; /** * 创建新 skill。 * 默认写到 project;若同名已存在于该 scope 抛错。 */ create(input: { name: string; scope?: ResourceScope; frontmatter: Omit & { extra?: Record; }; body: string; }): ParsedSkill; /** * 更新 skill:直接覆盖 SKILL.md。 * 若 scope 未指定,按 project>user 顺序定位现有版本。 */ update(input: { name: string; scope?: ResourceScope; frontmatter: Partial> & { extra?: Record; }; body?: string; }): ParsedSkill; /** 删除 skill 目录。 */ delete(name: string, scope?: ResourceScope): void; /** 启用 / 禁用:改写 frontmatter.enabled。 */ toggle(name: string, enabled: boolean, scope?: ResourceScope): ParsedSkill; /** 暴露给 chat-meta 的 slash 命令清单(仅 enabled 且 winning 版本)。 */ listSlashCommands(): SkillSlashCommand[]; /** 测试用:判断是否已 init。 */ isInitialized(): boolean; } /** 单例实例。所有模块共享同一份 registry。 */ export declare const skillRegistry: SkillRegistry; export {}; //# sourceMappingURL=registry.d.ts.map