Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(cowork): manage global skills when no folder is attached
Akarshan Biswas8d074e9932c8
diff --git a/src-tauri/src/core/agent/commands.rs b/src-tauri/src/core/agent/commands.rsindex 5857ce2ac..0f623371c 100644--- a/src-tauri/src/core/agent/commands.rs+++ b/src-tauri/src/core/agent/commands.rs@@ -67,13 +67,37 @@ pub async fn agent_skill_hub_list() -> Result<Vec<skill_hub::HubSkill>, String>skill_hub::list().await.map_err(ui_error)}-/// Download a hub skill (SKILL.md + bundled files) into the project as-/// `<name>/SKILL.md`. Scaffolds the project on first use.+/// Download a hub skill (SKILL.md + bundled files) as `<name>/SKILL.md`, into+/// the project store when a project is given (scaffolded on first use), else+/// into the permanent store -- Cowork's skills manager works with no folder+/// attached, and the store is what its agent reads anyway.#[tauri::command]-pub async fn agent_skill_hub_import(project: String, name: String) -> Result<(), String> {- let root = std::path::PathBuf::from(&project);- ensure_project(&root)?;- skill_hub::import(&root, &name).await.map_err(ui_error)+pub async fn agent_skill_hub_import(+ project: Option<String>,+ data_folder: Option<String>,+ name: String,+) -> Result<(), String> {+ let store = match project+ .map(|p| p.trim().to_string())+ .filter(|p| !p.is_empty())+ {+ Some(p) => {+ let root = std::path::PathBuf::from(&p);+ ensure_project(&root)?;+ workspace::project_store(&root)+ }+ None => {+ let data = data_folder+ .filter(|d| !d.trim().is_empty())+ .ok_or_else(|| {+ "ERROR: neither a project nor the data folder was given".to_string()+ })?;+ workspace::ensure_permanent_store(std::path::Path::new(&data))+ .await+ .map_err(ui_error)?+ }+ };+ skill_hub::import(&store, &name).await.map_err(ui_error)}/// Read the project's enabled-skill whitelist (`[skills].enabled`). An emptydiff --git a/src-tauri/src/core/agent/skill_hub.rs b/src-tauri/src/core/agent/skill_hub.rsindex 0f1b64ff9..a95007937 100644--- a/src-tauri/src/core/agent/skill_hub.rs+++ b/src-tauri/src/core/agent/skill_hub.rs@@ -10,10 +10,9 @@ use std::path::Path;use futures::future::join_all;-use tauri_plugin_agent_tools::{skills, workspace};+use tauri_plugin_agent_tools::skills;-const TREE_URL: &str =- "https://api.github.com/repos/anthropics/skills/git/trees/main?recursive=1";+const TREE_URL: &str = "https://api.github.com/repos/anthropics/skills/git/trees/main?recursive=1";const RAW_BASE: &str = "https://raw.githubusercontent.com/anthropics/skills/main/";const SKILLS_PREFIX: &str = "skills/";const USER_AGENT: &str = "jan-agent-skill-import";@@ -110,7 +109,7 @@ pub async fn list() -> Result<Vec<HubSkill>, String> {/// downloads succeed is the destination cleared and rewritten — a mid-download/// error leaves the existing skill untouched, and re-import never leaves stale/// files from a prior version behind.-pub async fn import(root: &Path, name: &str) -> Result<(), String> {+pub async fn import(store: &Path, name: &str) -> Result<(), String> {// Reuse the shared workspace name guard (rejects separators, `..`, `.`, empty).let stem = skills::safe_stem(name)?;let client = client()?;@@ -151,8 +150,9 @@ pub async fn import(root: &Path, name: &str) -> Result<(), String> {fetched.push(result?);}- // Phase 2: replace the destination with the freshly fetched files.- let skills_dir = skills::skills_dir(&workspace::project_store(root));+ // Phase 2: replace the destination with the freshly fetched files. `store`+ // is a store root (project or permanent); the caller resolved it.+ let skills_dir = skills::skills_dir(store);let dest_root = skills_dir.join(&stem);let flat = skills_dir.join(format!("{stem}.md"));let _ = tokio::fs::remove_dir_all(&dest_root).await;diff --git a/web-app/src/containers/dialogs/SkillsManagerDialog.tsx b/web-app/src/containers/dialogs/SkillsManagerDialog.tsxindex 46a945853..593b4e1e1 100644--- a/web-app/src/containers/dialogs/SkillsManagerDialog.tsx+++ b/web-app/src/containers/dialogs/SkillsManagerDialog.tsx@@ -135,14 +135,16 @@ export default function SkillsManagerDialog({<DialogContent className="max-w-3xl"><DialogHeader><DialogTitle>{t('common:skillsTitle')}</DialogTitle>+ {/* Name the store being managed: the current session's folder, or the+ global store every session reads when nothing is attached. */}+ <p className="text-xs text-muted-foreground">+ {folder+ ? t('common:skillsScopeProject', { folder })+ : t('common:skillsScopeGlobal')}+ </p></DialogHeader>- {!folder ? (- <div className="py-10 text-center text-sm text-muted-foreground">- {t('common:skillsSelectFolder')}- </div>- ) : (- <div className="flex gap-4 h-[60vh] overflow-hidden">+ <div className="flex gap-4 h-[60vh] overflow-hidden">{/* Skill list */}<div className="w-1/3 min-h-0 flex flex-col gap-2 border-r pr-3"><Button@@ -294,7 +296,6 @@ export default function SkillsManagerDialog({)}</div></div>- )}</DialogContent></Dialog>)diff --git a/web-app/src/hooks/useSkills.ts b/web-app/src/hooks/useSkills.tsindex 82c11b134..f6dbeee25 100644--- a/web-app/src/hooks/useSkills.ts+++ b/web-app/src/hooks/useSkills.ts@@ -3,6 +3,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { create } from 'zustand'import { toast } from 'sonner'import * as skillStore from '@/lib/skillStore'+import { getServiceHub } from '@/hooks/useServiceHub'import type { SkillMeta } from '@/lib/skillStore'export type { SkillMeta }@@ -45,11 +46,12 @@ const useSkillsVersion = create<{ v: number; bump: () => void }>((set) => ({}))/**- * CRUD over the agent's per-project skills (`<folder>/.jan/agent/skills/*.md`).- * Storage is shared with the settings page's permanent store via `skillStore`;- * only the root differs. The `[skills].enabled` whitelist and the skill hub stay- * on their own commands -- both are project concerns with no store equivalent.- * All operations are scoped to `folder`; with no folder there are no skills.+ * CRUD over the agent's skills. With a `folder`, the project's co-located+ * store (`<folder>/.jan/agent/skills`); without one, the permanent store in+ * the Jan data folder -- which is also what the Cowork agent's `skill_*`+ * tools read, so the sidebar manager works with nothing attached. The+ * `[skills].enabled` whitelist stays a project concern: with no folder it has+ * nowhere to live, so everything reads as enabled and `setEnabled` is a no-op.*/export function useSkills(folder: string | null) {const [skills, setSkills] = useState<SkillMeta[]>([])@@ -63,22 +65,20 @@ export function useSkills(folder: string | null) {const enabledRef = useRef<string[]>([])const scope = useMemo(- () => (folder ? skillStore.projectScope(folder) : null),+ () => (folder ? skillStore.projectScope(folder) : skillStore.storeScope),[folder])const refresh = useCallback(async () => {- if (!folder || !scope) {- setSkills([])- setEnabledState([])- enabledRef.current = []- return- }setLoading(true)try {const [list, en] = await Promise.all([skillStore.listSkills(scope),- invoke<string[]>('agent_skill_enabled_get', { project: folder }),+ // The whitelist lives in the project's agent.toml; the permanent+ // store has none, so everything it holds is enabled.+ folder+ ? invoke<string[]>('agent_skill_enabled_get', { project: folder })+ : Promise.resolve([]),])setSkills(list)setEnabledState(en)@@ -94,6 +94,7 @@ export function useSkills(folder: string | null) {// SkillSelector toggle) don't produce unhandled rejections.const setEnabled = useCallback(async (names: string[]) => {+ if (!folder) returnconst prev = enabledRef.currentsetEnabledState(names)enabledRef.current = names@@ -117,37 +118,30 @@ export function useSkills(folder: string | null) {refresh()}, [refresh, version])- // Callers reach these only from surfaces that already require a folder; the- // guard keeps that an explicit failure rather than a silent write to the- // wrong root.- const requireScope = useCallback(() => {- if (!scope) throw new Error('No project folder selected')- return scope- }, [scope])-const read = useCallback(- (name: string) => skillStore.readSkill(requireScope(), name),- [requireScope]+ (name: string) => skillStore.readSkill(scope, name),+ [scope])const write = useCallback(async (name: string, content: string) => {- await skillStore.writeSkill(requireScope(), name, content)+ await skillStore.writeSkill(scope, name, content)bump()},- [requireScope, bump]+ [scope, bump])const remove = useCallback(async (name: string) => {- await skillStore.deleteSkill(requireScope(), name)+ await skillStore.deleteSkill(scope, name)bump()},- [requireScope, bump]+ [scope, bump])// Anthropic skill hub. `hubList` is project-independent; `hubImport` downloads- // into the current folder, then bumps so all instances re-fetch.+ // into the current folder (or, with none, the permanent store, which needs+ // the data folder to locate), then bumps so all instances re-fetch.const hubList = useCallback(() => invoke<HubSkill[]>('agent_skill_hub_list'),[]@@ -155,7 +149,14 @@ export function useSkills(folder: string | null) {const hubImport = useCallback(async (name: string) => {- await invoke('agent_skill_hub_import', { project: folder, name })+ const dataFolder = folder+ ? undefined+ : ((await getServiceHub().app().getJanDataFolder()) ?? undefined)+ await invoke('agent_skill_hub_import', {+ project: folder ?? undefined,+ dataFolder,+ name,+ })bump()},[folder, bump]diff --git a/web-app/src/locales/en/common.json b/web-app/src/locales/en/common.jsonindex 1ea179b4d..09829e0fa 100644--- a/web-app/src/locales/en/common.json+++ b/web-app/src/locales/en/common.json@@ -64,7 +64,8 @@"skills": "Skills","skillsInContext": "Skills available to the agent this run","skillsTitle": "Manage skills",- "skillsSelectFolder": "Select a project folder in the code screen first to manage its skills.",+ "skillsScopeProject": "Skills for {{folder}}",+ "skillsScopeGlobal": "Global skills, available to every session","skillsEmpty": "No skills yet","skillsPickOrNew": "Select a skill to edit, or create a new one.","skillNew": "New skill",