Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(cowork): surface global skills when no working directory is selected
Akarshan Biswas681d7b8ed31e
diff --git a/web-app/src/containers/SkillSelector.tsx b/web-app/src/containers/SkillSelector.tsxindex 98e939c12..80ec94123 100644--- a/web-app/src/containers/SkillSelector.tsx+++ b/web-app/src/containers/SkillSelector.tsx@@ -19,12 +19,18 @@ export default function SkillSelector({ folder }: { folder: string | null }) {const { t } = useTranslation()const { skills, enabled, setEnabled } = useSkills(folder)- if (!folder || skills.length === 0) return null+ if (skills.length === 0) return nullconst allNames = skills.map((s) => s.name)const effective = effectiveEnabled(enabled, allNames)+ // #8878: the global store is what the Cowork agent actually reads, so its+ // skills are shown and active even with no folder. The `[skills].enabled`+ // whitelist lives in a project's agent.toml, so with no folder it has nowhere+ // to persist -- every global skill is active and the toggle is informational.+ const scoped = folder !== nullconst toggle = (name: string) => {+ if (!scoped) returnconst next = new Set(effective)if (next.has(name)) next.delete(name)else next.add(name)@@ -58,6 +64,11 @@ export default function SkillSelector({ folder }: { folder: string | null }) {<div className="px-2 py-1.5 text-xs text-muted-foreground">{t('common:skillsInContext')}</div>+ {!scoped && (+ <div className="px-2 pb-1.5 text-xs text-muted-foreground">+ {t('common:skillsScopeGlobal')}+ </div>+ )}<div className="max-h-64 overflow-y-auto">{skills.map((s) => (<label@@ -74,6 +85,7 @@ export default function SkillSelector({ folder }: { folder: string | null }) {</div><Switchchecked={effective.has(s.name)}+ disabled={!scoped}onCheckedChange={() => toggle(s.name)}/></label>diff --git a/web-app/src/containers/__tests__/SkillSelector.test.tsx b/web-app/src/containers/__tests__/SkillSelector.test.tsxnew file mode 100644index 000000000..ba923b4e0--- /dev/null+++ b/web-app/src/containers/__tests__/SkillSelector.test.tsx@@ -0,0 +1,77 @@+import { describe, it, expect, vi, beforeEach } from 'vitest'+import { render, screen } from '@testing-library/react'+import userEvent from '@testing-library/user-event'++vi.mock('@/i18n/react-i18next-compat', () => ({+ useTranslation: () => ({ t: (k: string) => k }),+}))++const { useSkills } = vi.hoisted(() => ({ useSkills: vi.fn() }))+vi.mock('@/hooks/useSkills', async () => {+ const actual = await vi.importActual<typeof import('@/hooks/useSkills')>(+ '@/hooks/useSkills'+ )+ return { ...actual, useSkills }+})++import SkillSelector from '../SkillSelector'++const skill = (name: string) => ({ name, description: `${name} desc` })++describe('SkillSelector', () => {+ beforeEach(() => useSkills.mockReset())++ it('renders nothing when there are no skills', () => {+ useSkills.mockReturnValue({ skills: [], enabled: [], setEnabled: vi.fn() })+ const { container } = render(<SkillSelector folder={null} />)+ expect(container).toBeEmptyDOMElement()+ })++ // #8878: global skills are available to the agent with no working directory,+ // so the picker must surface them instead of hiding until a folder is picked.+ it('shows global skills when no folder is attached', async () => {+ useSkills.mockReturnValue({+ skills: [skill('git'), skill('pdf')],+ enabled: [],+ setEnabled: vi.fn(),+ })+ render(<SkillSelector folder={null} />)+ await userEvent.click(await screen.findByRole('button'))+ expect(screen.getByText('git')).toBeInTheDocument()+ expect(screen.getByText('pdf')).toBeInTheDocument()+ expect(screen.getByText('common:skillsScopeGlobal')).toBeInTheDocument()+ })++ // The `[skills].enabled` whitelist lives in a project's agent.toml; with no+ // folder it has nowhere to persist, so the toggle is informational, not live.+ it('disables the per-skill toggle with no folder and never persists', async () => {+ const setEnabled = vi.fn()+ useSkills.mockReturnValue({+ skills: [skill('git')],+ enabled: [],+ setEnabled,+ })+ render(<SkillSelector folder={null} />)+ await userEvent.click(await screen.findByRole('button'))+ const toggle = screen.getByRole('switch')+ expect(toggle).toBeDisabled()+ await userEvent.click(toggle)+ expect(setEnabled).not.toHaveBeenCalled()+ })++ it('keeps the toggle live when a folder is attached', async () => {+ const setEnabled = vi.fn()+ useSkills.mockReturnValue({+ skills: [skill('git')],+ enabled: [],+ setEnabled,+ })+ render(<SkillSelector folder="/home/u/repo" />)+ await userEvent.click(await screen.findByRole('button'))+ const toggle = screen.getByRole('switch')+ expect(toggle).not.toBeDisabled()+ await userEvent.click(toggle)+ expect(setEnabled).toHaveBeenCalled()+ expect(screen.queryByText('common:skillsScopeGlobal')).toBeNull()+ })+})diff --git a/web-app/src/hooks/useSkills.ts b/web-app/src/hooks/useSkills.tsindex f6dbeee25..8e0e6d9ba 100644--- a/web-app/src/hooks/useSkills.ts+++ b/web-app/src/hooks/useSkills.ts@@ -83,6 +83,9 @@ export function useSkills(folder: string | null) {setSkills(list)setEnabledState(en)enabledRef.current = en+ } catch (e) {+ // A discovery failure must be actionable, not a silently empty list (#8878).+ toast.error(String(e))} finally {setLoading(false)}