Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(daemon): discover local skills from ~/.agents/skills (MUL-3333) (#4244)
LinYushen0d0edac32fb2
diff --git a/apps/docs/content/docs/skills.ja.mdx b/apps/docs/content/docs/skills.ja.mdxindex 5e5089e687..2f424e0d66 100644--- a/apps/docs/content/docs/skills.ja.mdx+++ b/apps/docs/content/docs/skills.ja.mdx@@ -12,7 +12,7 @@ import { Callout } from "fumadocs-ui/components/callout";Multica は 2 つのスキルソースに対応しています。- **ワークスペーススキル** — Multica のクラウドに保存されます。エージェントに取り付けると、タスク実行時にあなたのデーモンへ同期されます。これが**チーム全体でスキルを共有する標準的な方法**です。-- **ローカルスキル** — あなたのマシン上のディレクトリに存在します(各 AI コーディングツールには慣例的なデフォルトパスがあります。例: Claude Code の `~/.claude/skills/`)。あなたが要求すると、[デーモン](/daemon-runtimes)がマシンをスキャンし、どれをワークスペースに取り込むかを手動で選びます。+- **ローカルスキル** — あなたのマシン上のディレクトリに存在します。あなたが要求すると、[デーモン](/daemon-runtimes)がマシンをスキャンし、どれをワークスペースに取り込むかを手動で選びます。デーモンは**2 つのルートを優先順位順に**確認します。まずランタイム自身のスキルディレクトリ(各 AI コーディングツールには慣例的なデフォルトパスがあります。例: Claude Code の `~/.claude/skills/`)、次にツール横断の汎用ディレクトリ `~/.agents/skills/`(Codex や Gemini CLI などのエコシステムが共有する場所)です。同じスキル名が両方に存在する場合は**プロバイダー専用ディレクトリが優先**されるため、汎用ルートは*追加の*スキルを表示するだけで、既存スキルの解決結果を変えることはありません。ほとんどの場合は**ワークスペーススキル**が望ましいでしょう。一度インポートすれば、すべてのチームメイトのエージェントが使えるからです。ローカルスキルは、まずローカルでテストしたい場合や、内容に機密性の高いローカル資料が含まれる場合に適しています。diff --git a/apps/docs/content/docs/skills.ko.mdx b/apps/docs/content/docs/skills.ko.mdxindex e72a80d62e..c7fde97df6 100644--- a/apps/docs/content/docs/skills.ko.mdx+++ b/apps/docs/content/docs/skills.ko.mdx@@ -12,7 +12,7 @@ import { Callout } from "fumadocs-ui/components/callout";Multica는 두 가지 스킬 소스를 지원합니다.- **워크스페이스 스킬** — Multica 클라우드에 저장됩니다. 에이전트에 연결되면 작업 실행 시점에 여러분의 데몬으로 동기화됩니다. 이것이 **팀 전체에서 스킬을 공유하는 표준 방식**입니다.-- **로컬 스킬** — 여러분의 기기에 있는 디렉터리에 존재합니다(각 AI 코딩 도구마다 관례적인 기본 경로가 있습니다. 예: Claude Code의 `~/.claude/skills/`). 여러분이 요청하면 [데몬](/daemon-runtimes)이 기기를 스캔하고, 어떤 스킬을 워크스페이스로 가져올지 직접 고릅니다.+- **로컬 스킬** — 여러분의 기기에 있는 디렉터리에 존재합니다. 여러분이 요청하면 [데몬](/daemon-runtimes)이 기기를 스캔하고, 어떤 스킬을 워크스페이스로 가져올지 직접 고릅니다. 데몬은 **두 개의 루트를 우선순위 순서로** 확인합니다. 먼저 런타임 자체의 스킬 디렉터리(각 AI 코딩 도구마다 관례적인 기본 경로가 있습니다. 예: Claude Code의 `~/.claude/skills/`), 그다음 도구 간 공용 디렉터리 `~/.agents/skills/`(Codex, Gemini CLI 등 생태계가 공유하는 위치)입니다. 동일한 스킬 이름이 양쪽에 모두 있으면 **프로바이더 전용 디렉터리가 우선**하므로, 공용 루트는 *추가* 스킬만 노출할 뿐 기존 스킬의 해석 결과를 절대 바꾸지 않습니다.대부분의 경우 **워크스페이스 스킬**을 원하게 됩니다. 한 번만 가져오면 모든 팀원의 에이전트가 사용할 수 있기 때문입니다. 로컬 스킬은 먼저 로컬에서 테스트하고 싶거나, 콘텐츠에 민감한 로컬 자료가 포함된 경우에 적합합니다.diff --git a/apps/docs/content/docs/skills.mdx b/apps/docs/content/docs/skills.mdxindex a4da42c854..8867d0e949 100644--- a/apps/docs/content/docs/skills.mdx+++ b/apps/docs/content/docs/skills.mdx@@ -12,7 +12,7 @@ A Skill is a **knowledge pack** for an [agent](/agents) — a `SKILL.md` plus opMultica supports two skill sources:- **Workspace skill** — stored in Multica's cloud. Once attached to an agent, it's synced down to your daemon at task execution time. This is the **standard way to share skills across a team**.-- **Local skill** — lives in a directory on your machine (each AI coding tool has a conventional default path, e.g. Claude Code's `~/.claude/skills/`). On your request, the [daemon](/daemon-runtimes) scans your machine, and you manually pick which ones to bring into the workspace.+- **Local skill** — lives in a directory on your machine. On your request, the [daemon](/daemon-runtimes) scans your machine, and you manually pick which ones to bring into the workspace. The daemon checks **two roots, in priority order**: first the runtime's own skill directory (each AI coding tool has a conventional default path, e.g. Claude Code's `~/.claude/skills/`), then the cross-tool universal directory `~/.agents/skills/` — a shared location used by ecosystems like Codex and Gemini CLI. When the same skill name exists in both, the **provider-specific directory wins**, so the universal root only ever surfaces *additional* skills and never changes what an existing skill resolves to.Most of the time you want **workspace skills**: import once, every teammate's agent can use it. Local skills are a fit when you want to test locally first, or when the content involves sensitive local material.diff --git a/apps/docs/content/docs/skills.zh.mdx b/apps/docs/content/docs/skills.zh.mdxindex bc88263f64..36043e5718 100644--- a/apps/docs/content/docs/skills.zh.mdx+++ b/apps/docs/content/docs/skills.zh.mdx@@ -12,7 +12,7 @@ Skill 是给 [智能体](/agents) 的**专业知识包**——一个 `SKILL.md`Multica 支持两种 Skill 来源:- **工作区 Skill(workspace skill)** —— 存在 Multica 云端。挂到智能体后,任务执行时自动同步到你本机的守护进程。这是**团队共享 Skill 的标准方式**。-- **本机 Skill(local skill)** —— 直接存在你本机的某个目录里(每款 AI 编程工具有约定的默认路径,比如 Claude Code 的 `~/.claude/skills/`)。[守护进程](/daemon-runtimes) 按你的请求扫描本机,发现后由你手动选入工作区。+- **本机 Skill(local skill)** —— 直接存在你本机的某个目录里。[守护进程](/daemon-runtimes) 按你的请求扫描本机,发现后由你手动选入工作区。守护进程会**按优先级扫描两个根目录**:先扫该运行时自己的 skill 目录(每款 AI 编程工具有约定的默认路径,比如 Claude Code 的 `~/.claude/skills/`),再扫跨工具通用目录 `~/.agents/skills/`——这是 Codex、Gemini CLI 等生态共用的位置。当同名 skill 在两处都存在时,**provider 专用目录优先**,所以通用根目录只会*额外*带出新的 skill,绝不会改变已有 skill 的解析结果。大多数情况用**工作区 Skill**:导入一次,团队所有成员的智能体都能用。本机 Skill 适合先在本地测试、或涉及敏感本地内容的场景。diff --git a/packages/core/types/agent.ts b/packages/core/types/agent.tsindex 1700aa593e..0c36e417cb 100644--- a/packages/core/types/agent.ts+++ b/packages/core/types/agent.ts@@ -725,6 +725,14 @@ export interface RuntimeLocalSkillSummary {description?: string;source_path: string;provider: string;+ /**+ * Which discovery root surfaced this skill: "provider" for the runtime's+ * own skill directory (e.g. ~/.claude/skills) or "universal" for the+ * cross-tool ~/.agents/skills fallback. Daemons that predate multi-root+ * discovery omit the field; treat `undefined` as unknown rather than+ * asserting either origin.+ */+ root?: "provider" | "universal";file_count: number;}diff --git a/server/internal/daemon/local_skills.go b/server/internal/daemon/local_skills.goindex dfb12d2ae1..4f7956abfc 100644--- a/server/internal/daemon/local_skills.go+++ b/server/internal/daemon/local_skills.go@@ -28,7 +28,17 @@ type runtimeLocalSkillSummary struct {Description string `json:"description,omitempty"`SourcePath string `json:"source_path"`Provider string `json:"provider"`- FileCount int `json:"file_count"`+ // Root classifies which discovery root surfaced this skill:+ // localSkillRootProvider ("provider") for the runtime's own skill+ // directory (e.g. ~/.claude/skills) or localSkillRootUniversal+ // ("universal") for the cross-tool ~/.agents/skills fallback. The UI+ // uses it to label a skill's origin and to hint, in the import dialog,+ // whether a skill came from a provider-specific or a shared location.+ // Older daemons that predate multi-root discovery omit the field; the+ // server treats an empty value as "unknown" rather than a provider/+ // universal assertion.+ Root string `json:"root,omitempty"`+ FileCount int `json:"file_count"`}type runtimeLocalSkillBundle struct {@@ -40,8 +50,39 @@ type runtimeLocalSkillBundle struct {Files []SkillFileData `json:"files,omitempty"`}-// localSkillRootForProvider tracks the user-level skill locations exposed by-// each runtime/provider. Keep these in sync with upstream docs / conventions:+// localSkillRoot is a single discovery location plus a classifier for where+// it came from. Roots are returned in priority order by+// localSkillRootsForProvider; the kind is surfaced to the UI on each+// discovered skill (see runtimeLocalSkillSummary.Root).+type localSkillRoot struct {+ path string+ kind string+}++const (+ // localSkillRootProvider marks a runtime's own skill directory (e.g.+ // ~/.claude/skills). These take priority over the universal root.+ localSkillRootProvider = "provider"+ // localSkillRootUniversal marks the cross-tool ~/.agents/skills root,+ // a convention shared by Codex, Gemini CLI, Augment and others as a+ // universal home-level skill store. It is always searched last so a+ // same-key skill in the provider directory keeps winning.+ localSkillRootUniversal = "universal"+)++// localSkillRootsForProvider returns the ordered user-level skill roots+// scanned for each runtime/provider. The slice is in priority order:+//+// 1. the runtime's provider-specific root (backward-compatible with the+// single-root behavior that predates ~/.agents/skills support), then+// 2. the cross-tool universal root ~/.agents/skills.+//+// Listing and import both walk the roots in this order and the first match of+// a given skill key wins, so adding the universal root never changes what an+// existing provider-root skill resolves to — it only surfaces additional,+// non-conflicting skills.+//+// Keep the provider roots in sync with upstream docs / conventions:// - GitHub Copilot: https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/add-skills// - OpenCode: https://opencode.ai/docs/skills// - OpenClaw: https://github.com/openclaw/openclaw/blob/main/docs/tools/skills.md@@ -52,43 +93,53 @@ type runtimeLocalSkillBundle struct {// - Antigravity: ~/.gemini/antigravity-cli/skills user-level skill root// (https://antigravity.google/docs/gcli-migration "Global skills")//+// The universal ~/.agents/skills root is documented as a cross-tool skill+// location by Codex (https://developers.openai.com/codex/skills) and Gemini+// CLI (https://geminicli.com/docs/cli/skills/), among others.+//// Longer-term this mapping would be better colocated with the provider// definitions under server/pkg/agent so adding a new runtime can't silently// miss the local-skills surface.-func localSkillRootForProvider(provider string) (string, bool, error) {+func localSkillRootsForProvider(provider string) ([]localSkillRoot, bool, error) {home, err := os.UserHomeDir()if err != nil {- return "", false, fmt.Errorf("resolve user home: %w", err)+ return nil, false, fmt.Errorf("resolve user home: %w", err)}+ var providerRoot stringswitch provider {case "claude", "codebuddy":- return filepath.Join(home, ".claude", "skills"), true, nil+ providerRoot = filepath.Join(home, ".claude", "skills")case "codex":codexHome := strings.TrimSpace(os.Getenv("CODEX_HOME"))if codexHome == "" {codexHome = filepath.Join(home, ".codex")}- return filepath.Join(codexHome, "skills"), true, nil+ providerRoot = filepath.Join(codexHome, "skills")case "copilot":- return filepath.Join(home, ".copilot", "skills"), true, nil+ providerRoot = filepath.Join(home, ".copilot", "skills")case "opencode":- return filepath.Join(home, ".config", "opencode", "skills"), true, nil+ providerRoot = filepath.Join(home, ".config", "opencode", "skills")case "openclaw":- return filepath.Join(home, ".openclaw", "skills"), true, nil+ providerRoot = filepath.Join(home, ".openclaw", "skills")case "pi":- return filepath.Join(home, ".pi", "agent", "skills"), true, nil+ providerRoot = filepath.Join(home, ".pi", "agent", "skills")case "cursor":- return filepath.Join(home, ".cursor", "skills"), true, nil+ providerRoot = filepath.Join(home, ".cursor", "skills")case "kiro":- return filepath.Join(home, ".kiro", "skills"), true, nil+ providerRoot = filepath.Join(home, ".kiro", "skills")case "antigravity":// agy inherits Gemini CLI's global skill root; see// https://antigravity.google/docs/gcli-migration ("Global skills").- return filepath.Join(home, ".gemini", "antigravity-cli", "skills"), true, nil+ providerRoot = filepath.Join(home, ".gemini", "antigravity-cli", "skills")default:- return "", false, nil+ return nil, false, nil}++ return []localSkillRoot{+ {path: providerRoot, kind: localSkillRootProvider},+ {path: filepath.Join(home, ".agents", "skills"), kind: localSkillRootUniversal},+ }, true, nil}func isIgnoredLocalSkillEntry(name string) bool {@@ -228,19 +279,12 @@ func collectLocalSkillFiles(skillDir string, includeContent bool) ([]SkillFileDa}func listRuntimeLocalSkills(provider string) ([]runtimeLocalSkillSummary, bool, error) {- root, supported, err := localSkillRootForProvider(provider)+ roots, supported, err := localSkillRootsForProvider(provider)if err != nil || !supported {return nil, supported, err}- if _, err := os.Stat(root); err != nil {- if os.IsNotExist(err) {- return []runtimeLocalSkillSummary{}, true, nil- }- return nil, true, err- }-- // Walk the runtime root with two extensions over filepath.WalkDir:+ // Walk each runtime root with two extensions over filepath.WalkDir:// - Follow symlinks at every level. Installers like lark-cli ship// each skill as a symlink into a shared ~/.agents/skills/<name>;// the previous WalkDir path silently dropped them via the@@ -250,9 +294,43 @@ func listRuntimeLocalSkills(provider string) ([]runtimeLocalSkillSummary, bool,// already accepts slash-delimited keys, so the list endpoint// must surface those nested skills too.skills := make([]runtimeLocalSkillSummary, 0)- visited := make(map[string]bool)- enumerateLocalSkills(provider, root, root, 0, visited, &skills)+ // Dedupe strictly by Key. Roots are visited in priority order+ // (provider-specific first, ~/.agents/skills last); the first+ // occurrence of a Key wins. This keeps backward compatibility provable:+ // every skill visible under the single-root behavior keeps its Key,+ // SourcePath and FileCount, and we only ever *add* non-conflicting Keys+ // discovered under the universal root.+ seenKeys := make(map[string]bool)+ for _, root := range roots {+ if _, err := os.Stat(root.path); err != nil {+ if os.IsNotExist(err) {+ continue+ }+ return nil, true, err+ }++ // Each root gets its OWN `visited` set. It must NOT be shared across+ // roots: a user can deliberately expose the same on-disk skill under+ // two names by symlinking, e.g. ~/.claude/skills/bar ->+ // ~/.agents/skills/foo. With per-root visited sets both `bar` (claude+ // root) and `foo` (agents root) are listed; a shared set would mark+ // the resolved real path visited from the first root and silently+ // drop the legitimate second entry.+ rootSkills := make([]runtimeLocalSkillSummary, 0)+ visited := make(map[string]bool)+ enumerateLocalSkills(provider, root.kind, root.path, root.path, 0, visited, &rootSkills)++ for _, s := range rootSkills {+ if seenKeys[s.Key] {+ continue+ }+ seenKeys[s.Key] = true+ skills = append(skills, s)+ }+ }+ // Sort once, after every root has been merged, so the result is stable+ // regardless of how many roots contributed.sort.Slice(skills, func(i, j int) bool {return skills[i].Key < skills[j].Key})@@ -270,7 +348,7 @@ func listRuntimeLocalSkills(provider string) ([]runtimeLocalSkillSummary, bool,// EvalSymlinks up front. Errors from EvalSymlinks just stop the descent on// that branch — most often it's a dangling link, which we want to ignore.func enumerateLocalSkills(- provider, walkRoot, currentDir string,+ provider, rootKind, walkRoot, currentDir string,depth int,visited map[string]bool,skills *[]runtimeLocalSkillSummary,@@ -334,6 +412,7 @@ func enumerateLocalSkills(Description: description,SourcePath: relativizeHomePath(path),Provider: provider,+ Root: rootKind,// `files` is the supporting bundle (collectLocalSkillFiles// intentionally excludes SKILL.md so the bundle's `Content`// field can carry it without duplication on import). For the@@ -345,12 +424,12 @@ func enumerateLocalSkills(}// No SKILL.md here — descend looking for nested skills.- enumerateLocalSkills(provider, walkRoot, path, depth+1, visited, skills)+ enumerateLocalSkills(provider, rootKind, walkRoot, path, depth+1, visited, skills)}}func loadRuntimeLocalSkillBundle(provider, skillKey string) (*runtimeLocalSkillBundle, bool, error) {- root, supported, err := localSkillRootForProvider(provider)+ roots, supported, err := localSkillRootsForProvider(provider)if err != nil || !supported {return nil, supported, err}@@ -360,38 +439,75 @@ func loadRuntimeLocalSkillBundle(provider, skillKey string) (*runtimeLocalSkillBreturn nil, true, err}- skillDir := filepath.Join(root, filepath.FromSlash(key))- info, err := os.Stat(skillDir)- if err != nil {- if os.IsNotExist(err) {- return nil, true, fmt.Errorf("local skill not found")+ // Walk the roots in the same priority order as listRuntimeLocalSkills so+ // import resolves to exactly the skill the list endpoint surfaced. The+ // guiding invariant is list/load agreement: a root "has" the skill at this+ // key only when it is a directory carrying a SKILL.md — the exact+ // condition listRuntimeLocalSkills registers on. Anything that is not a+ // valid skill at this key (no entry, not a directory, or a directory+ // without a SKILL.md) means "this root doesn't have it" and we fall+ // through to the next root. Only a genuine IO/permission fault is+ // returned, so we never silently substitute a different-content same-key+ // skill from a lower-priority root.+ for _, root := range roots {+ skillDir := filepath.Join(root.path, filepath.FromSlash(key))+ info, err := os.Stat(skillDir)+ if err != nil {+ // IsNotExist => this root simply lacks the skill, try the next.+ // Any other stat error (permission, IO) is returned as-is rather+ // than silently skipped, since skipping could load a DIFFERENT+ // same-key skill from a lower-priority root that does not match+ // what the user picked in the list (Eve review #1).+ if os.IsNotExist(err) {+ continue+ }+ return nil, true, err+ }+ if !info.IsDir() {+ // Not a directory: listRuntimeLocalSkills never surfaces a non-dir+ // as a skill, so this root has no skill at this key. Fall through+ // to the next root instead of erroring.+ continue}- return nil, true, err- }- if !info.IsDir() {- return nil, true, fmt.Errorf("local skill is not a directory")- }- content, err := readLocalSkillMainFile(skillDir)- if err != nil {- return nil, true, err- }- name, description := skill.ParseSkillFrontmatter(content)- if name == "" {- name = filepath.Base(skillDir)- }+ // A directory only counts as a skill when it actually contains a+ // SKILL.md. A same-key directory WITHOUT one (e.g. ~/.claude/skills/foo+ // that is just an empty/unrelated folder) is NOT this skill — list+ // would have descended past it — so it must not shadow a valid+ // ~/.agents/skills/foo. Treat a missing SKILL.md as "this root doesn't+ // have it" and continue; only a non-IsNotExist stat error on the+ // SKILL.md (permission, IO) is returned.+ mainPath := filepath.Join(skillDir, "SKILL.md")+ if _, err := os.Stat(mainPath); err != nil {+ if os.IsNotExist(err) {+ continue+ }+ return nil, true, err+ }- files, err := collectLocalSkillFiles(skillDir, true)- if err != nil {- return nil, true, err+ content, err := readLocalSkillMainFile(skillDir)+ if err != nil {+ return nil, true, err+ }+ name, description := skill.ParseSkillFrontmatter(content)+ if name == "" {+ name = filepath.Base(skillDir)+ }++ files, err := collectLocalSkillFiles(skillDir, true)+ if err != nil {+ return nil, true, err+ }++ return &runtimeLocalSkillBundle{+ Name: name,+ Description: description,+ Content: content,+ SourcePath: relativizeHomePath(skillDir),+ Provider: provider,+ Files: files,+ }, true, nil}- return &runtimeLocalSkillBundle{- Name: name,- Description: description,- Content: content,- SourcePath: relativizeHomePath(skillDir),- Provider: provider,- Files: files,- }, true, nil+ return nil, true, fmt.Errorf("local skill not found")}diff --git a/server/internal/daemon/local_skills_test.go b/server/internal/daemon/local_skills_test.goindex 6de9532f85..f31170840e 100644--- a/server/internal/daemon/local_skills_test.go+++ b/server/internal/daemon/local_skills_test.go@@ -327,3 +327,403 @@ func TestLoadRuntimeLocalSkillBundle_Cursor(t *testing.T) {t.Fatalf("source_path = %q", bundle.SourcePath)}}++// ---------------------------------------------------------------------------+// Multi-root discovery: provider root + universal ~/.agents/skills (MUL-3333)+// ---------------------------------------------------------------------------++// A skill that lives only in the universal ~/.agents/skills root (no provider+// directory at all) must be discovered and tagged Root="universal".+func TestListRuntimeLocalSkills_DiscoversUniversalAgentsRoot(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "universal-helper", map[string]string{+ "SKILL.md": "---\nname: Universal Helper\ndescription: Cross-tool skill\n---\n# Universal Helper\n",+ "docs/info.md": "info",+ })++ skills, supported, err := listRuntimeLocalSkills("claude")+ if err != nil {+ t.Fatalf("listRuntimeLocalSkills: %v", err)+ }+ if !supported {+ t.Fatal("claude should be supported")+ }+ if len(skills) != 1 {+ t.Fatalf("expected 1 skill, got %d (%v)", len(skills), skills)+ }+ if skills[0].Key != "universal-helper" {+ t.Fatalf("key = %q, want universal-helper", skills[0].Key)+ }+ if skills[0].Name != "Universal Helper" {+ t.Fatalf("name = %q, want Universal Helper", skills[0].Name)+ }+ if skills[0].Root != localSkillRootUniversal {+ t.Fatalf("root = %q, want %q", skills[0].Root, localSkillRootUniversal)+ }+ if skills[0].SourcePath != "~/.agents/skills/universal-helper" {+ t.Fatalf("source_path = %q", skills[0].SourcePath)+ }+ // 2 = supporting file (docs/info.md) + SKILL.md.+ if skills[0].FileCount != 2 {+ t.Fatalf("file_count = %d, want 2", skills[0].FileCount)+ }+}++// A skill discovered under ~/.agents/skills must be importable, not just+// listable — otherwise the import dialog shows a skill the load endpoint+// can't fetch.+func TestLoadRuntimeLocalSkillBundle_ImportsFromUniversalRoot(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "shared-skill", map[string]string{+ "SKILL.md": "---\nname: Shared Skill\ndescription: Imported from agents root\n---\n# Shared Skill\n",+ "examples/use.md": "usage",+ "scripts/run.sh": "echo hi",+ })++ bundle, supported, err := loadRuntimeLocalSkillBundle("claude", "shared-skill")+ if err != nil {+ t.Fatalf("loadRuntimeLocalSkillBundle: %v", err)+ }+ if !supported {+ t.Fatal("claude should be supported")+ }+ if bundle.Name != "Shared Skill" {+ t.Fatalf("name = %q, want Shared Skill", bundle.Name)+ }+ if len(bundle.Files) != 2 {+ t.Fatalf("expected 2 supporting files, got %d", len(bundle.Files))+ }+ if bundle.SourcePath != "~/.agents/skills/shared-skill" {+ t.Fatalf("source_path = %q", bundle.SourcePath)+ }+}++// When the same key exists in BOTH the provider root and the universal root,+// the provider root wins: its SourcePath, Root tag and content are preserved+// and the universal copy is dropped. This is the backward-compatibility+// guarantee — adding the universal root never changes what an existing+// provider-root key resolves to.+func TestLocalSkills_ProviderRootWinsOnKeyConflict(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ writeTestLocalSkill(t, filepath.Join(home, ".claude", "skills"), "dup", map[string]string{+ "SKILL.md": "---\nname: Provider Copy\n---\n# provider\n",+ })+ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "dup", map[string]string{+ "SKILL.md": "---\nname: Universal Copy\n---\n# universal\n",+ })++ skills, _, err := listRuntimeLocalSkills("claude")+ if err != nil {+ t.Fatalf("listRuntimeLocalSkills: %v", err)+ }+ if len(skills) != 1 {+ t.Fatalf("expected 1 deduped skill, got %d (%v)", len(skills), skills)+ }+ if skills[0].Name != "Provider Copy" {+ t.Fatalf("name = %q, want Provider Copy (provider root must win)", skills[0].Name)+ }+ if skills[0].Root != localSkillRootProvider {+ t.Fatalf("root = %q, want %q", skills[0].Root, localSkillRootProvider)+ }+ if skills[0].SourcePath != "~/.claude/skills/dup" {+ t.Fatalf("source_path = %q, want provider path", skills[0].SourcePath)+ }++ // Load must resolve to the provider copy too, matching the list.+ bundle, _, err := loadRuntimeLocalSkillBundle("claude", "dup")+ if err != nil {+ t.Fatalf("loadRuntimeLocalSkillBundle: %v", err)+ }+ if bundle.Name != "Provider Copy" {+ t.Fatalf("bundle name = %q, want Provider Copy", bundle.Name)+ }+ if bundle.SourcePath != "~/.claude/skills/dup" {+ t.Fatalf("bundle source_path = %q, want provider path", bundle.SourcePath)+ }+}++// Both roots contribute their non-conflicting skills, merged and sorted once.+func TestListRuntimeLocalSkills_MergesBothRoots(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ writeTestLocalSkill(t, filepath.Join(home, ".claude", "skills"), "provider-only", map[string]string{+ "SKILL.md": "---\nname: Provider Only\n---\n",+ })+ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "universal-only", map[string]string{+ "SKILL.md": "---\nname: Universal Only\n---\n",+ })++ skills, _, err := listRuntimeLocalSkills("claude")+ if err != nil {+ t.Fatalf("listRuntimeLocalSkills: %v", err)+ }+ keys := make([]string, 0, len(skills))+ roots := make(map[string]string)+ for _, s := range skills {+ keys = append(keys, s.Key)+ roots[s.Key] = s.Root+ }+ // Sorted once after merge: "provider-only" < "universal-only".+ wantKeys := []string{"provider-only", "universal-only"}+ if !reflect.DeepEqual(keys, wantKeys) {+ t.Fatalf("keys = %v, want %v", keys, wantKeys)+ }+ if roots["provider-only"] != localSkillRootProvider {+ t.Fatalf("provider-only root = %q", roots["provider-only"])+ }+ if roots["universal-only"] != localSkillRootUniversal {+ t.Fatalf("universal-only root = %q", roots["universal-only"])+ }+}++// A missing universal root is not an error: discovery still returns the+// provider-root skills. (Mirror of the original single-root "missing root+// returns empty" guarantee, now per-root.)+func TestListRuntimeLocalSkills_MissingUniversalRootIsNotAnError(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ writeTestLocalSkill(t, filepath.Join(home, ".claude", "skills"), "only-provider", map[string]string{+ "SKILL.md": "---\nname: Only Provider\n---\n",+ })+ // No ~/.agents/skills created.++ skills, supported, err := listRuntimeLocalSkills("claude")+ if err != nil {+ t.Fatalf("listRuntimeLocalSkills: %v", err)+ }+ if !supported {+ t.Fatal("claude should be supported")+ }+ if len(skills) != 1 || skills[0].Key != "only-provider" {+ t.Fatalf("expected only-provider, got %v", skills)+ }+}++// Both roots missing → empty list, no error.+func TestListRuntimeLocalSkills_BothRootsMissing(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ skills, supported, err := listRuntimeLocalSkills("claude")+ if err != nil {+ t.Fatalf("listRuntimeLocalSkills: %v", err)+ }+ if !supported {+ t.Fatal("claude should be supported")+ }+ if len(skills) != 0 {+ t.Fatalf("expected empty, got %v", skills)+ }+}++// Nested layouts (a skill two levels deep) work in the universal root too.+func TestListRuntimeLocalSkills_NestedSkillInUniversalRoot(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "release/reporter", map[string]string{+ "SKILL.md": "---\nname: Release Reporter\n---\n",+ })++ skills, _, err := listRuntimeLocalSkills("opencode")+ if err != nil {+ t.Fatalf("listRuntimeLocalSkills: %v", err)+ }+ if len(skills) != 1 || skills[0].Key != "release/reporter" {+ t.Fatalf("expected release/reporter, got %v", skills)+ }+ if skills[0].Root != localSkillRootUniversal {+ t.Fatalf("root = %q, want %q", skills[0].Root, localSkillRootUniversal)+ }++ bundle, _, err := loadRuntimeLocalSkillBundle("opencode", "release/reporter")+ if err != nil {+ t.Fatalf("loadRuntimeLocalSkillBundle: %v", err)+ }+ if bundle.Name != "Release Reporter" {+ t.Fatalf("bundle name = %q", bundle.Name)+ }+}++// loadRuntimeLocalSkillBundle falls through to the universal root only when+// the provider root genuinely lacks the key (IsNotExist).+func TestLoadRuntimeLocalSkillBundle_FallsThroughToUniversalOnNotExist(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ // Provider root exists but does NOT contain "only-universal".+ writeTestLocalSkill(t, filepath.Join(home, ".claude", "skills"), "something-else", map[string]string{+ "SKILL.md": "---\nname: Something Else\n---\n",+ })+ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "only-universal", map[string]string{+ "SKILL.md": "---\nname: Only Universal\n---\n# only universal\n",+ })++ bundle, _, err := loadRuntimeLocalSkillBundle("claude", "only-universal")+ if err != nil {+ t.Fatalf("loadRuntimeLocalSkillBundle: %v", err)+ }+ if bundle.Name != "Only Universal" {+ t.Fatalf("name = %q, want Only Universal", bundle.Name)+ }+ if bundle.SourcePath != "~/.agents/skills/only-universal" {+ t.Fatalf("source_path = %q", bundle.SourcePath)+ }+}++// When the provider root HAS the key but reading its SKILL.md fails for a+// reason other than IsNotExist, loadRuntimeLocalSkillBundle must return that+// error instead of silently loading a different same-key skill from the+// universal root. Here we make ~/.claude/skills/clash/SKILL.md a directory so+// the read fails ("is a directory") while the dir itself exists.+func TestLoadRuntimeLocalSkillBundle_DoesNotMaskReadErrorWithUniversalFallback(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ clashDir := filepath.Join(home, ".claude", "skills", "clash")+ if err := os.MkdirAll(filepath.Join(clashDir, "SKILL.md"), 0o755); err != nil {+ t.Fatalf("mkdir SKILL.md-as-dir: %v", err)+ }+ // A valid same-key skill in the universal root that must NOT be used.+ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "clash", map[string]string{+ "SKILL.md": "---\nname: Universal Clash\n---\n",+ })++ bundle, _, err := loadRuntimeLocalSkillBundle("claude", "clash")+ if err == nil {+ t.Fatalf("expected an error, got bundle %+v", bundle)+ }+ if bundle != nil {+ t.Fatalf("expected nil bundle on error, got %+v", bundle)+ }+}++// A user can deliberately expose one on-disk skill under two names by+// symlinking ~/.claude/skills/bar -> ~/.agents/skills/foo. Because each root+// keeps its OWN `visited` set, the list returns both `bar` (from the claude+// root) and `foo` (from the agents root). A shared visited set would drop one.+func TestListRuntimeLocalSkills_PerRootVisitedAllowsCrossRootSymlinkAlias(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ target := writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "foo", map[string]string{+ "SKILL.md": "---\nname: Foo\n---\n",+ })++ claudeRoot := filepath.Join(home, ".claude", "skills")+ if err := os.MkdirAll(claudeRoot, 0o755); err != nil {+ t.Fatalf("mkdir claude root: %v", err)+ }+ if err := os.Symlink(target, filepath.Join(claudeRoot, "bar")); err != nil {+ t.Fatalf("symlink: %v", err)+ }++ skills, _, err := listRuntimeLocalSkills("claude")+ if err != nil {+ t.Fatalf("listRuntimeLocalSkills: %v", err)+ }+ keys := make([]string, 0, len(skills))+ roots := make(map[string]string)+ for _, s := range skills {+ keys = append(keys, s.Key)+ roots[s.Key] = s.Root+ }+ wantKeys := []string{"bar", "foo"}+ if !reflect.DeepEqual(keys, wantKeys) {+ t.Fatalf("keys = %v, want %v (per-root visited must not collapse the alias)", keys, wantKeys)+ }+ if roots["bar"] != localSkillRootProvider {+ t.Fatalf("bar root = %q, want provider", roots["bar"])+ }+ if roots["foo"] != localSkillRootUniversal {+ t.Fatalf("foo root = %q, want universal", roots["foo"])+ }+}++// Regression (大彪): a provider-root directory that shares a skill's key but+// contains NO SKILL.md must not shadow a valid universal-root skill at the+// same key. listRuntimeLocalSkills descends past the invalid provider dir and+// surfaces the universal skill, so loadRuntimeLocalSkillBundle MUST resolve to+// that same universal skill — not error out on the invalid provider dir.+// Before the fix, load only fell through on os.IsNotExist for the skill+// directory, so an existing-but-invalid provider dir made list and load+// disagree.+func TestLoadRuntimeLocalSkillBundle_ProviderDirWithoutSkillMdFallsThrough(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ // Provider root has a same-key directory but NO SKILL.md (just a stray+ // file), so it is NOT a valid skill.+ writeTestLocalSkill(t, filepath.Join(home, ".claude", "skills"), "shadowed", map[string]string{+ "notes.md": "not a skill — no SKILL.md here",+ })+ // Universal root has the real skill at the same key.+ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "shadowed", map[string]string{+ "SKILL.md": "---\nname: Real Shadowed\ndescription: The valid one\n---\n# Real Shadowed\n",+ "docs/info.md": "info",+ })++ // list must surface exactly the universal skill at key "shadowed".+ skills, _, err := listRuntimeLocalSkills("claude")+ if err != nil {+ t.Fatalf("listRuntimeLocalSkills: %v", err)+ }+ if len(skills) != 1 {+ t.Fatalf("expected 1 skill, got %d (%v)", len(skills), skills)+ }+ if skills[0].Key != "shadowed" || skills[0].Root != localSkillRootUniversal {+ t.Fatalf("list surfaced %+v, want key=shadowed root=universal", skills[0])+ }+ if skills[0].SourcePath != "~/.agents/skills/shadowed" {+ t.Fatalf("list source_path = %q, want ~/.agents/skills/shadowed", skills[0].SourcePath)+ }++ // load must resolve to the SAME universal skill list showed — not error on+ // the invalid provider dir.+ bundle, _, err := loadRuntimeLocalSkillBundle("claude", "shadowed")+ if err != nil {+ t.Fatalf("loadRuntimeLocalSkillBundle: %v (load disagreed with list)", err)+ }+ if bundle.Name != "Real Shadowed" {+ t.Fatalf("bundle name = %q, want Real Shadowed", bundle.Name)+ }+ if bundle.SourcePath != "~/.agents/skills/shadowed" {+ t.Fatalf("bundle source_path = %q, want ~/.agents/skills/shadowed", bundle.SourcePath)+ }+}++// A provider-root entry that exists at the key but is NOT a directory (a plain+// file) likewise must not shadow a valid universal skill — list never surfaces+// a non-dir, so load must fall through too.+func TestLoadRuntimeLocalSkillBundle_ProviderNonDirFallsThrough(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)++ claudeRoot := filepath.Join(home, ".claude", "skills")+ if err := os.MkdirAll(claudeRoot, 0o755); err != nil {+ t.Fatalf("mkdir claude root: %v", err)+ }+ // A plain file where the skill dir would be.+ if err := os.WriteFile(filepath.Join(claudeRoot, "filish"), []byte("x"), 0o644); err != nil {+ t.Fatalf("write file: %v", err)+ }+ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "filish", map[string]string{+ "SKILL.md": "---\nname: Filish\n---\n# Filish\n",+ })++ bundle, _, err := loadRuntimeLocalSkillBundle("claude", "filish")+ if err != nil {+ t.Fatalf("loadRuntimeLocalSkillBundle: %v", err)+ }+ if bundle.Name != "Filish" || bundle.SourcePath != "~/.agents/skills/filish" {+ t.Fatalf("bundle = %+v, want universal Filish", bundle)+ }+}diff --git a/server/internal/handler/runtime_local_skills.go b/server/internal/handler/runtime_local_skills.goindex 6aa6bc7279..ceabc0c6ae 100644--- a/server/internal/handler/runtime_local_skills.go+++ b/server/internal/handler/runtime_local_skills.go@@ -177,7 +177,13 @@ type RuntimeLocalSkillSummary struct {Description string `json:"description,omitempty"`SourcePath string `json:"source_path"`Provider string `json:"provider"`- FileCount int `json:"file_count"`+ // Root classifies the discovery root the daemon found this skill under:+ // "provider" (the runtime's own skill directory, e.g. ~/.claude/skills)+ // or "universal" (the cross-tool ~/.agents/skills fallback). Daemons+ // that predate multi-root discovery omit it; an empty value means+ // "unknown" and the UI should not assert either origin.+ Root string `json:"root,omitempty"`+ FileCount int `json:"file_count"`}type RuntimeLocalSkillListRequest struct {