From 6c3b2cfb39664dc7a90f9fa336b740375ceacc3d Mon Sep 17 00:00:00 2001 From: Dhilip Subramanian <49802211+sdhilip200@users.noreply.github.com> Date: Thu, 30 Jul 2026 11:11:53 +1200 Subject: [PATCH] fix(skills): preserve symlinked agent coverage (#8329) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings → Orchestration → Agent coverage decided whether each detected agent had the orchestration skill by matching a skill's single `rootPath` against a hand-maintained table of path segments. Skill discovery dedups by canonical file path, so when one provider home is a symlink onto another agent's skills directory — which `npx skills add --global` does — the two collapse into one row and the absorbed roots survive only in `rootPaths`, which the old matcher ignored. With `~/.grok/skills` symlinked onto `~/.claude/skills`, Claude read Ready and Grok read Missing even though Grok loads the same files. Now classifies every entry in `rootPaths` and resolves each root through the `SkillDiscoverySource` the scanner already returns, accepting it when `sourceKind` is not `repo` and `owner` is either the agent's owner or `null`. Deletes `ORCHESTRATION_SKILL_LOCATIONS` and `ORCHESTRATION_SKILL_LOCATION_IDS_BY_AGENT` — a renderer-side mirror of `buildSkillDiscoverySources` that had to be hand-edited for every new provider root, which is what caused this class of bug. No discovery roots change here; those landed in #8510. Fixed during review: - Restored the required `{ kind: 'local' }` argument to `useDetectedAgents`. Dropping it failed typecheck (TS2554) and pinned `detectedIds` to null, leaving the widget on "Checking installed agents and skill paths…" forever. It also reverted the remote-host scoping from #9790. - Stopped a duplicate repo root from shadowing an owning home root. `SkillDiscoverySource.path` is not unique: when the scan cwd is the home directory, `~/.claude/skills` is scanned as both a home root and a repo root, and a path-keyed Map is last-write-wins — so every agent read Missing while the panel above said Installed. Guaranteed in Settings on a WSL project. - Carried OMP coverage in the owner-based shape so #6422's coverage-table hunks could be dropped on merge. Behavior note: an orchestration skill inside an enabled Claude plugin now counts for Claude. That is a deliberate consequence of trusting the scanner's ownership data, matches how the Codex plugin cache was already treated, and is pinned by a test. Refs #8256 Co-authored-by: sdhilip200 <49802211+sdhilip200@users.noreply.github.com> --- src/main/skills/discovery.test.ts | 44 +++ .../settings/OrchestrationPane.test.tsx | 11 + .../components/settings/OrchestrationPane.tsx | 2 + .../OrchestrationSkillAgentCoverage.test.tsx | 28 +- .../OrchestrationSkillAgentCoverage.tsx | 7 +- .../src/hooks/useInstalledAgentSkills.ts | 7 + .../lib/orchestration-skill-coverage.test.ts | 339 +++++++++++++----- .../src/lib/orchestration-skill-coverage.ts | 181 ++-------- 8 files changed, 379 insertions(+), 240 deletions(-) diff --git a/src/main/skills/discovery.test.ts b/src/main/skills/discovery.test.ts index 13aec60bf..9f94e9f83 100644 --- a/src/main/skills/discovery.test.ts +++ b/src/main/skills/discovery.test.ts @@ -3,6 +3,7 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { describe, expect, it } from 'vitest' import { buildSkillDiscoverySources, discoverSkills } from './discovery' +import { TUI_AGENT_CONFIG } from '../../shared/tui-agent-config' import type { Repo } from '../../shared/types' function makeRepo(path: string, connectionId: string | null = null): Repo { @@ -139,6 +140,49 @@ describe('skill discovery', () => { ) }) + it('keys every deduped root to an owning source so per-agent coverage resolves', async () => { + const root = await mkdtemp(join(tmpdir(), 'orca-skills-')) + const home = join(root, 'home') + const claudeSkills = join(home, '.claude', 'skills') + await mkdir(join(claudeSkills, 'orchestration'), { recursive: true }) + await writeFile(join(claudeSkills, 'orchestration', 'SKILL.md'), '# orchestration') + // `npx skills add --global` links a provider home onto an existing install. + await mkdir(join(home, '.grok'), { recursive: true }) + await symlink(claudeSkills, join(home, '.grok', 'skills'), 'dir') + + const result = await discoverSkills({ homeDir: home, repos: [], includeCwd: false }) + + const skill = result.skills.find((entry) => entry.name === 'orchestration') + // Why: renderer coverage looks each rootPath up in `sources` by path, so a + // root with no matching source silently drops that agent back to uncovered. + const owners = skill?.rootPaths + ?.map((rootPath) => result.sources.find((source) => source.path === rootPath)) + .map((source) => source?.owner) + expect(owners?.slice().sort()).toEqual(['claude', 'grok']) + }) + + it('names every source owner after a real agent id', () => { + // Why: renderer coverage joins `owner` to a TuiAgent id by string equality, and + // AgentType widens to string — a typo here reads Missing forever, type-clean. + const owners = buildSkillDiscoverySources({ + homeDir: '/home/test', + repos: [], + includeCwd: false + }).flatMap((source) => (source.owner === null ? [] : [source.owner])) + + expect(owners.filter((owner) => !(owner in TUI_AGENT_CONFIG))).toEqual([]) + }) + + it('scans a home-equal workspace path as both a home and a repo root', () => { + // Why: coverage must tolerate several sources per path. Deduping these would + // make the renderer's duplicate-root regression test assert a dead shape. + const paths = buildSkillDiscoverySources({ homeDir: '/home/test', cwd: '/home/test' }) + .filter((source) => source.path === join('/home/test', '.claude', 'skills')) + .map((source) => source.sourceKind) + + expect(paths.slice().sort()).toEqual(['home', 'repo']) + }) + it('does not add SSH-backed repository paths to local scan roots', () => { const roots = buildSkillDiscoverySources({ homeDir: '/home/test', diff --git a/src/renderer/src/components/settings/OrchestrationPane.test.tsx b/src/renderer/src/components/settings/OrchestrationPane.test.tsx index 02da99134..e742f3cde 100644 --- a/src/renderer/src/components/settings/OrchestrationPane.test.tsx +++ b/src/renderer/src/components/settings/OrchestrationPane.test.tsx @@ -70,6 +70,17 @@ vi.mock('@/hooks/useInstalledAgentSkills', () => ({ updatedAt: null } ], + sources: [ + { + id: 'home-claude', + label: 'Claude home', + path: '/Users/test/.claude/skills', + sourceKind: 'home', + providers: ['claude'], + owner: 'claude', + exists: true + } + ], refresh: vi.fn() }) })) diff --git a/src/renderer/src/components/settings/OrchestrationPane.tsx b/src/renderer/src/components/settings/OrchestrationPane.tsx index dad05eb04..66fe68aa0 100644 --- a/src/renderer/src/components/settings/OrchestrationPane.tsx +++ b/src/renderer/src/components/settings/OrchestrationPane.tsx @@ -66,6 +66,7 @@ export function OrchestrationPane(): React.JSX.Element { loading: orchestrationSkillLoading, error: orchestrationSkillError, skills: discoveredSkills, + sources: discoveredSkillSources, refresh: refreshOrchestrationSkill } = useInstalledAgentSkill(ORCHESTRATION_SKILL_NAME, { discoveryTarget: activeSkillRuntime.discoveryTarget, @@ -150,6 +151,7 @@ export function OrchestrationPane(): React.JSX.Element { } diff --git a/src/renderer/src/components/settings/OrchestrationSkillAgentCoverage.test.tsx b/src/renderer/src/components/settings/OrchestrationSkillAgentCoverage.test.tsx index b6310e618..9e0146d04 100644 --- a/src/renderer/src/components/settings/OrchestrationSkillAgentCoverage.test.tsx +++ b/src/renderer/src/components/settings/OrchestrationSkillAgentCoverage.test.tsx @@ -2,13 +2,15 @@ import { renderToStaticMarkup } from 'react-dom/server' import { describe, expect, it, vi } from 'vitest' import { OrchestrationSkillAgentCoverage } from './OrchestrationSkillAgentCoverage' +const useDetectedAgents = vi.fn(() => ({ + detectedIds: ['claude', 'codex'], + isLoading: false, + isRefreshing: false, + refresh: vi.fn() +})) + vi.mock('@/hooks/useDetectedAgents', () => ({ - useDetectedAgents: () => ({ - detectedIds: ['claude', 'codex'], - isLoading: false, - isRefreshing: false, - refresh: vi.fn() - }) + useDetectedAgents: (...args: unknown[]) => useDetectedAgents(...(args as [])) })) describe('OrchestrationSkillAgentCoverage', () => { @@ -16,6 +18,17 @@ describe('OrchestrationSkillAgentCoverage', () => { const markup = renderToStaticMarkup( { expect(markup).toContain('Ready') expect(markup).toContain('Missing') expect(markup).not.toContain('View details') + // Why: an omitted target reads as "host unknown", which pins detectedIds to + // null and leaves the widget spinning forever. + expect(useDetectedAgents).toHaveBeenCalledWith({ kind: 'local' }) }) }) diff --git a/src/renderer/src/components/settings/OrchestrationSkillAgentCoverage.tsx b/src/renderer/src/components/settings/OrchestrationSkillAgentCoverage.tsx index 036af3795..78bca3a04 100644 --- a/src/renderer/src/components/settings/OrchestrationSkillAgentCoverage.tsx +++ b/src/renderer/src/components/settings/OrchestrationSkillAgentCoverage.tsx @@ -1,4 +1,4 @@ -import type { DiscoveredSkill } from '../../../../shared/skills' +import type { DiscoveredSkill, SkillDiscoverySource } from '../../../../shared/skills' import type { OrchestrationSkillAgentStatus } from '@/lib/orchestration-skill-coverage' import { AgentIcon } from '@/lib/agent-catalog' import { useDetectedAgents } from '@/hooks/useDetectedAgents' @@ -68,14 +68,15 @@ function AgentCoverageChip({ export function OrchestrationSkillAgentCoverage(props: { skills: readonly DiscoveredSkill[] + sources: readonly SkillDiscoverySource[] loading: boolean embedded?: boolean className?: string }): React.JSX.Element { - const { skills, loading: skillsLoading, embedded = false, className } = props + const { skills, sources, loading: skillsLoading, embedded = false, className } = props const { detectedIds, isLoading: agentsLoading } = useDetectedAgents({ kind: 'local' }) const loading = skillsLoading || agentsLoading || detectedIds === null - const agentStatuses = getOrchestrationSkillAgentStatuses(skills, detectedIds ?? []) + const agentStatuses = getOrchestrationSkillAgentStatuses(skills, detectedIds ?? [], sources) const installedCount = agentStatuses.filter((status) => status.installed).length const totalCount = agentStatuses.length const fullCoverage = !loading && totalCount > 0 && installedCount === totalCount diff --git a/src/renderer/src/hooks/useInstalledAgentSkills.ts b/src/renderer/src/hooks/useInstalledAgentSkills.ts index e19bac655..6d2afc40e 100644 --- a/src/renderer/src/hooks/useInstalledAgentSkills.ts +++ b/src/renderer/src/hooks/useInstalledAgentSkills.ts @@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import type { DiscoveredSkill, SkillDiscoveryResult, + SkillDiscoverySource, SkillDiscoveryTarget, SkillSourceKind } from '../../../shared/skills' @@ -29,6 +30,7 @@ export type InstalledAgentSkillState = { loading: boolean error: string | null skills: readonly DiscoveredSkill[] + sources: readonly SkillDiscoverySource[] refresh: () => Promise } @@ -304,6 +306,10 @@ export function useInstalledAgentSkillNames( () => (enabled && resultForRender ? resultForRender.skills : []), [enabled, resultForRender] ) + const sources = useMemo( + () => (enabled && resultForRender ? resultForRender.sources : []), + [enabled, resultForRender] + ) const installed = useMemo( () => @@ -326,6 +332,7 @@ export function useInstalledAgentSkillNames( loading: loadingForRender, error: errorForRender, skills, + sources, refresh: forceRefresh } } diff --git a/src/renderer/src/lib/orchestration-skill-coverage.test.ts b/src/renderer/src/lib/orchestration-skill-coverage.test.ts index b4d287e3f..e30c11925 100644 --- a/src/renderer/src/lib/orchestration-skill-coverage.test.ts +++ b/src/renderer/src/lib/orchestration-skill-coverage.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import type { DiscoveredSkill } from '../../../shared/skills' +import type { DiscoveredSkill, SkillDiscoverySource } from '../../../shared/skills' import type { TuiAgent } from '../../../shared/types' import { agentHasOrchestrationSkill, @@ -24,6 +24,22 @@ function skill(overrides: Partial): DiscoveredSkill { } } +function source( + path: string, + owner: SkillDiscoverySource['owner'], + sourceKind: SkillDiscoverySource['sourceKind'] = 'home' +): SkillDiscoverySource { + return { + id: path, + label: path, + path, + sourceKind, + providers: ['agent-skills'], + owner, + exists: true + } +} + describe('orchestration skill agent coverage', () => { it('marks shared-path agents from the global ~/.agents/skills install', () => { const skills = [ @@ -35,7 +51,13 @@ describe('orchestration skill agent coverage', () => { }) ] - expect(getOrchestrationSkillAgentStatuses(skills, ['codex', 'gemini', 'droid'])).toEqual([ + expect( + getOrchestrationSkillAgentStatuses( + skills, + ['codex', 'gemini', 'droid'], + [source('/Users/test/.agents/skills', null)] + ) + ).toEqual([ { agent: 'codex', label: 'Codex', installed: true }, { agent: 'gemini', label: 'Gemini', installed: true }, { agent: 'droid', label: 'Droid', installed: true } @@ -52,49 +74,82 @@ describe('orchestration skill agent coverage', () => { }) ] - expect(agentHasOrchestrationSkill('claude', skills)).toBe(true) - expect(agentHasOrchestrationSkill('codex', skills)).toBe(false) - expect(agentHasOrchestrationSkill('gemini', skills)).toBe(false) + const sources = [source('/Users/test/.claude/skills', 'claude')] + expect(agentHasOrchestrationSkill('claude', skills, sources)).toBe(true) + expect(agentHasOrchestrationSkill('codex', skills, sources)).toBe(false) + expect(agentHasOrchestrationSkill('gemini', skills, sources)).toBe(false) }) it('marks Codex from plugin cache installs', () => { expect( - agentHasOrchestrationSkill('codex', [ - skill({ - providers: ['codex', 'agent-skills'], - sourceKind: 'plugin', - sourceLabel: 'Codex plugin cache', - rootPath: '/Users/test/.codex/plugins/cache', - directoryPath: '/Users/test/.codex/plugins/cache/vendor/orchestration' - }) - ]) + agentHasOrchestrationSkill( + 'codex', + [ + skill({ + providers: ['codex', 'agent-skills'], + sourceKind: 'plugin', + sourceLabel: 'Codex plugin cache', + rootPath: '/Users/test/.codex/plugins/cache', + directoryPath: '/Users/test/.codex/plugins/cache/vendor/orchestration' + }) + ], + [source('/Users/test/.codex/plugins/cache', 'codex', 'plugin')] + ) + ).toBe(true) + }) + + it('marks Claude from an enabled plugin install', () => { + // Why: Claude Code loads skills from enabled plugins, so an owned plugin root + // counts the same as the Codex plugin cache does. + expect( + agentHasOrchestrationSkill( + 'claude', + [ + skill({ + providers: ['claude', 'agent-skills'], + sourceKind: 'plugin', + sourceLabel: 'Claude plugin', + rootPath: '/Users/test/.claude/plugins/repos/vendor/pack/skills', + directoryPath: '/Users/test/.claude/plugins/repos/vendor/pack/skills/orchestration' + }) + ], + [source('/Users/test/.claude/plugins/repos/vendor/pack/skills', 'claude', 'plugin')] + ) ).toBe(true) }) it('ignores repo-scoped orchestration installs', () => { expect( - agentHasOrchestrationSkill('gemini', [ - skill({ - providers: ['agent-skills'], - sourceKind: 'repo', - rootPath: '/workspace/.agents/skills', - directoryPath: '/workspace/.agents/skills/orchestration' - }) - ]) + agentHasOrchestrationSkill( + 'gemini', + [ + skill({ + providers: ['agent-skills'], + sourceKind: 'repo', + rootPath: '/workspace/.agents/skills', + directoryPath: '/workspace/.agents/skills/orchestration' + }) + ], + [source('/workspace/.agents/skills', null, 'repo')] + ) ).toBe(false) }) it('matches orchestration by directory name when frontmatter uses a display name', () => { expect( - agentHasOrchestrationSkill('claude', [ - skill({ - name: 'Orca Orchestration', - providers: ['claude'], - sourceKind: 'home', - rootPath: '/Users/test/.claude/skills', - directoryPath: '/Users/test/.claude/skills/orchestration' - }) - ]) + agentHasOrchestrationSkill( + 'claude', + [ + skill({ + name: 'Orca Orchestration', + providers: ['claude'], + sourceKind: 'home', + rootPath: '/Users/test/.claude/skills', + directoryPath: '/Users/test/.claude/skills/orchestration' + }) + ], + [source('/Users/test/.claude/skills', 'claude')] + ) ).toBe(true) }) @@ -140,25 +195,161 @@ describe('orchestration skill agent coverage', () => { const skills = [ skill({ providers: ['agent-skills'], sourceKind: 'home', rootPath, directoryPath }) ] - expect(agentHasOrchestrationSkill(agent, skills)).toBe(true) + const sources = [source(rootPath, agent)] + expect(agentHasOrchestrationSkill(agent, skills, sources)).toBe(true) // Why: a provider-home install must not leak coverage to unrelated agents. - expect(agentHasOrchestrationSkill('claude', skills)).toBe(false) + expect(agentHasOrchestrationSkill('claude', skills, sources)).toBe(false) } }) + it('marks every provider root retained after symlink deduplication', () => { + const roots = [ + source('/Users/test/.codex/skills', 'codex'), + source('/Users/test/.claude/skills', 'claude'), + source('/Users/test/.grok/skills', 'grok'), + source('/Users/test/.config/opencode/skills', 'opencode'), + source('/Users/test/.pi/agent/skills', 'pi'), + source('/Users/test/.gemini/skills', 'gemini'), + source('/Users/test/.gemini/antigravity/skills', 'antigravity'), + source('/Users/test/.cursor/skills', 'cursor') + ] + const skills = [ + skill({ + providers: ['codex', 'claude', 'agent-skills'], + rootPath: roots[0].path, + rootPaths: roots.map((root) => root.path), + directoryPath: '/Users/test/.codex/skills/orchestration' + }) + ] + + expect( + getOrchestrationSkillAgentStatuses( + skills, + [ + 'codex', + 'claude', + 'claude-agent-teams', + 'grok', + 'opencode', + 'pi', + 'gemini', + 'antigravity', + 'cursor' + ], + roots + ).every((status) => status.installed) + ).toBe(true) + }) + + it('does not treat a repository shared root as a global install after deduplication', () => { + const codexRoot = source('/Users/test/.codex/skills', 'codex') + const repoRoot = source('/workspace/.agents/skills', null, 'repo') + const skills = [ + skill({ + providers: ['codex', 'agent-skills'], + rootPath: codexRoot.path, + rootPaths: [codexRoot.path, repoRoot.path], + directoryPath: '/Users/test/.codex/skills/orchestration' + }) + ] + + expect(agentHasOrchestrationSkill('codex', skills, [codexRoot, repoRoot])).toBe(true) + expect(agentHasOrchestrationSkill('grok', skills, [codexRoot, repoRoot])).toBe(false) + }) + + it('keeps the owning home root when a repo root duplicates its path', () => { + // Why: a workspace whose cwd is the home dir scans ~/.claude/skills as both a + // home and a repo root, and the repo duplicate sorts last by label. + const skills = [ + skill({ + providers: ['claude'], + sourceKind: 'home', + rootPath: '/Users/test/.claude/skills', + directoryPath: '/Users/test/.claude/skills/orchestration' + }) + ] + + expect( + agentHasOrchestrationSkill('claude', skills, [ + source('/Users/test/.claude/skills', 'claude'), + source('/Users/test/.claude/skills', 'claude', 'repo') + ]) + ).toBe(true) + }) + + it('leaves an agent uncovered when no source claims the skill root', () => { + const skills = [ + skill({ + providers: ['claude'], + sourceKind: 'home', + rootPath: '/Users/test/.claude/skills', + directoryPath: '/Users/test/.claude/skills/orchestration' + }) + ] + + expect(agentHasOrchestrationSkill('claude', skills, [])).toBe(false) + }) + + it('marks OpenClaude from ~/.claude/skills like Claude Code', () => { + const skills = [ + skill({ + providers: ['claude'], + sourceKind: 'home', + rootPath: '/Users/test/.claude/skills', + directoryPath: '/Users/test/.claude/skills/orchestration' + }) + ] + + expect( + agentHasOrchestrationSkill('openclaude', skills, [ + source('/Users/test/.claude/skills', 'claude') + ]) + ).toBe(true) + }) + it('marks a multi-segment provider-home agent from a Windows-style path', () => { expect( - agentHasOrchestrationSkill('opencode', [ - skill({ - providers: ['agent-skills'], - sourceKind: 'home', - rootPath: 'C:\\Users\\test\\.config\\opencode\\skills', - directoryPath: 'C:\\Users\\test\\.config\\opencode\\skills\\orchestration' - }) - ]) + agentHasOrchestrationSkill( + 'opencode', + [ + skill({ + providers: ['agent-skills'], + sourceKind: 'home', + rootPath: 'C:\\Users\\test\\.config\\opencode\\skills', + directoryPath: 'C:\\Users\\test\\.config\\opencode\\skills\\orchestration' + }) + ], + [source('C:\\Users\\test\\.config\\opencode\\skills', 'opencode')] + ) ).toBe(true) }) + it('keeps Pi and OMP distinct despite sharing the /agent/skills shape', () => { + const piInstall = [ + skill({ + providers: ['agent-skills'], + sourceKind: 'home', + rootPath: '/Users/test/.pi/agent/skills', + directoryPath: '/Users/test/.pi/agent/skills/orchestration' + }) + ] + const ompInstall = [ + skill({ + providers: ['agent-skills'], + sourceKind: 'home', + rootPath: '/Users/test/.omp/agent/skills', + directoryPath: '/Users/test/.omp/agent/skills/orchestration' + }) + ] + + const piSources = [source('/Users/test/.pi/agent/skills', 'pi')] + const ompSources = [source('/Users/test/.omp/agent/skills', 'omp')] + expect(agentHasOrchestrationSkill('pi', piInstall, piSources)).toBe(true) + expect(agentHasOrchestrationSkill('omp', piInstall, piSources)).toBe(false) + expect(agentHasOrchestrationSkill('omp', ompInstall, ompSources)).toBe(true) + expect(agentHasOrchestrationSkill('pi', ompInstall, ompSources)).toBe(false) + }) + it('keeps Gemini and Antigravity distinct despite sharing the ~/.gemini root', () => { const geminiInstall = [ skill({ @@ -177,38 +368,14 @@ describe('orchestration skill agent coverage', () => { }) ] - // Why: `.gemini/skills` and `.gemini/antigravity/skills` are siblings, so a - // segment matcher must not let one provider's install mark the other. - expect(agentHasOrchestrationSkill('gemini', geminiInstall)).toBe(true) - expect(agentHasOrchestrationSkill('antigravity', geminiInstall)).toBe(false) - expect(agentHasOrchestrationSkill('antigravity', antigravityInstall)).toBe(true) - expect(agentHasOrchestrationSkill('gemini', antigravityInstall)).toBe(false) - }) - - it('keeps Pi and OMP distinct despite sharing the agent/skills tail', () => { - const piInstall = [ - skill({ - providers: ['agent-skills'], - sourceKind: 'home', - rootPath: '/Users/test/.pi/agent/skills', - directoryPath: '/Users/test/.pi/agent/skills/orchestration' - }) - ] - const ompInstall = [ - skill({ - providers: ['agent-skills'], - sourceKind: 'home', - rootPath: 'C:\\Users\\test\\.omp\\agent\\skills', - directoryPath: 'C:\\Users\\test\\.omp\\agent\\skills\\orchestration' - }) - ] - - // Why: `.pi/agent/skills` and `.omp/agent/skills` differ only in the leading - // segment, so dropping either anchor would cross-mark the other agent. - expect(agentHasOrchestrationSkill('pi', piInstall)).toBe(true) - expect(agentHasOrchestrationSkill('omp', piInstall)).toBe(false) - expect(agentHasOrchestrationSkill('omp', ompInstall)).toBe(true) - expect(agentHasOrchestrationSkill('pi', ompInstall)).toBe(false) + const geminiSources = [source('/Users/test/.gemini/skills', 'gemini')] + const antigravitySources = [source('/Users/test/.gemini/antigravity/skills', 'antigravity')] + expect(agentHasOrchestrationSkill('gemini', geminiInstall, geminiSources)).toBe(true) + expect(agentHasOrchestrationSkill('antigravity', geminiInstall, geminiSources)).toBe(false) + expect(agentHasOrchestrationSkill('antigravity', antigravityInstall, antigravitySources)).toBe( + true + ) + expect(agentHasOrchestrationSkill('gemini', antigravityInstall, antigravitySources)).toBe(false) }) it('marks Claude Agent Teams from ~/.claude/skills like Claude Code', () => { @@ -221,19 +388,27 @@ describe('orchestration skill agent coverage', () => { }) ] - expect(agentHasOrchestrationSkill('claude-agent-teams', skills)).toBe(true) + expect( + agentHasOrchestrationSkill('claude-agent-teams', skills, [ + source('/Users/test/.claude/skills', 'claude') + ]) + ).toBe(true) }) it('marks Windows skill paths', () => { expect( - agentHasOrchestrationSkill('codex', [ - skill({ - providers: ['codex'], - sourceKind: 'home', - rootPath: 'C:\\Users\\test\\.codex\\skills', - directoryPath: 'C:\\Users\\test\\.codex\\skills\\orchestration' - }) - ]) + agentHasOrchestrationSkill( + 'codex', + [ + skill({ + providers: ['codex'], + sourceKind: 'home', + rootPath: 'C:\\Users\\test\\.codex\\skills', + directoryPath: 'C:\\Users\\test\\.codex\\skills\\orchestration' + }) + ], + [source('C:\\Users\\test\\.codex\\skills', 'codex')] + ) ).toBe(true) }) }) diff --git a/src/renderer/src/lib/orchestration-skill-coverage.ts b/src/renderer/src/lib/orchestration-skill-coverage.ts index 8645081e0..4b4e58144 100644 --- a/src/renderer/src/lib/orchestration-skill-coverage.ts +++ b/src/renderer/src/lib/orchestration-skill-coverage.ts @@ -1,120 +1,16 @@ -import type { DiscoveredSkill } from '../../../shared/skills' +import type { AgentType } from '../../../shared/agent-status-types' +import type { DiscoveredSkill, SkillDiscoverySource } from '../../../shared/skills' import type { TuiAgent } from '../../../shared/types' import { ORCHESTRATION_SKILL_NAME } from '@/lib/agent-feature-install-commands' import { getAgentLabel } from '@/lib/agent-catalog' import { TUI_AGENT_AUTO_PICK_ORDER } from '../../../shared/tui-agent-selection' -export type OrchestrationSkillLocationId = - | 'claude-home' - | 'codex-home' - | 'codex-plugin-cache' - | 'agents-home' - | 'grok-home' - | 'opencode-home' - | 'pi-home' - | 'omp-home' - | 'gemini-home' - | 'antigravity-home' - | 'cursor-home' - export type OrchestrationSkillAgentStatus = { agent: TuiAgent label: string installed: boolean } -type OrchestrationSkillLocationDefinition = { - id: OrchestrationSkillLocationId - matchesSkill: (skill: DiscoveredSkill) => boolean -} - -const ORCHESTRATION_SKILL_LOCATIONS: readonly OrchestrationSkillLocationDefinition[] = [ - { - id: 'claude-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.claude', 'skills']) - }, - { - id: 'codex-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.codex', 'skills']) - }, - { - id: 'codex-plugin-cache', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.codex', 'plugins', 'cache']) - }, - { - id: 'agents-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.agents', 'skills']) - }, - { - id: 'grok-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && pathContainsSegments(skill.rootPath, ['.grok', 'skills']) - }, - { - id: 'opencode-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.config', 'opencode', 'skills']) - }, - { - id: 'pi-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.pi', 'agent', 'skills']) - }, - { - id: 'omp-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.omp', 'agent', 'skills']) - }, - { - // Why: segment matching keeps `.gemini/skills` (Gemini CLI) distinct from the - // sibling `.gemini/antigravity/skills`, so the two never cross-mark each other. - id: 'gemini-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.gemini', 'skills']) - }, - { - id: 'antigravity-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.gemini', 'antigravity', 'skills']) - }, - { - id: 'cursor-home', - matchesSkill: (skill) => - isGlobalOrchestrationSkill(skill) && - pathContainsSegments(skill.rootPath, ['.cursor', 'skills']) - } -] - -const ORCHESTRATION_SKILL_LOCATION_IDS_BY_AGENT: Partial< - Record -> = { - claude: ['claude-home', 'agents-home'], - // Why: Agent Teams runs Claude Code, so it reads the same ~/.claude skills. - 'claude-agent-teams': ['claude-home', 'agents-home'], - openclaude: ['claude-home', 'agents-home'], - codex: ['codex-home', 'codex-plugin-cache', 'agents-home'], - grok: ['grok-home', 'agents-home'], - opencode: ['opencode-home', 'agents-home'], - pi: ['pi-home', 'agents-home'], - omp: ['omp-home', 'agents-home'], - gemini: ['gemini-home', 'agents-home'], - antigravity: ['antigravity-home', 'agents-home'], - cursor: ['cursor-home', 'agents-home'] -} - function normalizeSkillName(value: string): string { return value.trim().toLowerCase() } @@ -123,24 +19,6 @@ function basenameFromPath(pathValue: string): string { return pathValue.split(/[\\/]/).findLast(Boolean) ?? pathValue } -function normalizePath(pathValue: string): string { - return pathValue.replace(/\\/g, '/').toLowerCase() -} - -function pathContainsSegments(pathValue: string, segments: readonly string[]): boolean { - const parts = normalizePath(pathValue).split('/').filter(Boolean) - const target = segments.map((segment) => segment.toLowerCase()) - if (target.length === 0 || parts.length < target.length) { - return false - } - for (let index = 0; index <= parts.length - target.length; index += 1) { - if (target.every((segment, offset) => parts[index + offset] === segment)) { - return true - } - } - return false -} - function isOrchestrationSkill(skill: DiscoveredSkill): boolean { if (!skill.installed) { return false @@ -152,34 +30,38 @@ function isOrchestrationSkill(skill: DiscoveredSkill): boolean { ) } -function isGlobalOrchestrationSkill(skill: DiscoveredSkill): boolean { - return isOrchestrationSkill(skill) && skill.sourceKind !== 'repo' -} - -function getOrchestrationSkillLocationIdsForAgent( - agent: TuiAgent -): readonly OrchestrationSkillLocationId[] { - return ORCHESTRATION_SKILL_LOCATION_IDS_BY_AGENT[agent] ?? ['agents-home'] -} - -function isOrchestrationSkillInstalledAtLocation( - skills: readonly DiscoveredSkill[], - locationId: OrchestrationSkillLocationId -): boolean { - const location = ORCHESTRATION_SKILL_LOCATIONS.find((entry) => entry.id === locationId) - if (!location) { - return false - } - return skills.some((skill) => location.matchesSkill(skill)) +// Why: `native-chat-agent-profiles.ts` carries the same rule as `skillSourceOwner`; +// keep the two in step when an agent starts reading another agent's roots. +function getSkillSourceOwnerForAgent(agent: TuiAgent): AgentType { + // Why: both launch Claude Code and therefore consume Claude-owned skill roots. + return agent === 'claude-agent-teams' || agent === 'openclaude' ? 'claude' : agent } +/** `skills` and `sources` must come from the same discovery scan. */ export function agentHasOrchestrationSkill( agent: TuiAgent, - skills: readonly DiscoveredSkill[] + skills: readonly DiscoveredSkill[], + sources: readonly SkillDiscoverySource[] ): boolean { - return getOrchestrationSkillLocationIdsForAgent(agent).some((locationId) => - isOrchestrationSkillInstalledAtLocation(skills, locationId) - ) + const owner = getSkillSourceOwnerForAgent(agent) + return skills.some((skill) => { + if (!isOrchestrationSkill(skill)) { + return false + } + // Why: dedup keeps one row, so the roots it absorbed still have to be classified. + const rootPaths = skill.rootPaths?.length ? skill.rootPaths : [skill.rootPath] + return rootPaths.some((rootPath) => + // Why: one path can carry several sources — a workspace whose cwd is the + // home dir scans `~/.claude/skills` as both a home and a repo root. Keying + // by path would let the repo duplicate shadow the owning home root. + sources.some( + (source) => + source.path === rootPath && + source.sourceKind !== 'repo' && + (source.owner === null || source.owner === owner) + ) + ) + }) } export function sortOrchestrationAgents(agents: readonly TuiAgent[]): TuiAgent[] { @@ -195,11 +77,12 @@ export function sortOrchestrationAgents(agents: readonly TuiAgent[]): TuiAgent[] export function getOrchestrationSkillAgentStatuses( skills: readonly DiscoveredSkill[], - detectedAgents: readonly TuiAgent[] + detectedAgents: readonly TuiAgent[], + sources: readonly SkillDiscoverySource[] ): OrchestrationSkillAgentStatus[] { return sortOrchestrationAgents(detectedAgents).map((agent) => ({ agent, label: getAgentLabel(agent), - installed: agentHasOrchestrationSkill(agent, skills) + installed: agentHasOrchestrationSkill(agent, skills, sources) })) }