mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-27 16:26:16 +08:00
feat: add skill storage location toggle between CC Switch and ~/.agents/skills
Allow users to choose between storing skills in CC Switch's managed directory (~/.cc-switch/skills/) or the Agent Skills open standard directory (~/.agents/skills/). Includes migration logic that safely moves files before updating settings, with confirmation dialog for non-empty installations.
This commit is contained in:
@@ -32,6 +32,7 @@ import { LanguageSettings } from "@/components/settings/LanguageSettings";
|
||||
import { ThemeSettings } from "@/components/settings/ThemeSettings";
|
||||
import { WindowSettings } from "@/components/settings/WindowSettings";
|
||||
import { AppVisibilitySettings } from "@/components/settings/AppVisibilitySettings";
|
||||
import { SkillStorageLocationSettings } from "@/components/settings/SkillStorageLocationSettings";
|
||||
import { SkillSyncMethodSettings } from "@/components/settings/SkillSyncMethodSettings";
|
||||
import { TerminalSettings } from "@/components/settings/TerminalSettings";
|
||||
import { DirectorySettings } from "@/components/settings/DirectorySettings";
|
||||
@@ -44,6 +45,7 @@ import { ModelTestConfigPanel } from "@/components/usage/ModelTestConfigPanel";
|
||||
import { UsageDashboard } from "@/components/usage/UsageDashboard";
|
||||
import { LogConfigPanel } from "@/components/settings/LogConfigPanel";
|
||||
import { AuthCenterPanel } from "@/components/settings/AuthCenterPanel";
|
||||
import { useInstalledSkills } from "@/hooks/useSkills";
|
||||
import { useSettings } from "@/hooks/useSettings";
|
||||
import { useImportExport } from "@/hooks/useImportExport";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -96,6 +98,8 @@ export function SettingsPage({
|
||||
resetStatus,
|
||||
} = useImportExport({ onImportSuccess });
|
||||
|
||||
const { data: installedSkills } = useInstalledSkills();
|
||||
|
||||
const [activeTab, setActiveTab] = useState<string>("general");
|
||||
const [showRestartPrompt, setShowRestartPrompt] = useState(false);
|
||||
|
||||
@@ -229,6 +233,13 @@ export function SettingsPage({
|
||||
settings={settings}
|
||||
onChange={handleAutoSave}
|
||||
/>
|
||||
<SkillStorageLocationSettings
|
||||
value={settings.skillStorageLocation ?? "cc_switch"}
|
||||
installedCount={installedSkills?.length ?? 0}
|
||||
onMigrated={(location) =>
|
||||
updateSettings({ skillStorageLocation: location })
|
||||
}
|
||||
/>
|
||||
<SkillSyncMethodSettings
|
||||
value={settings.skillSyncMethod ?? "auto"}
|
||||
onChange={(method) =>
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { skillsApi, type MigrationResult } from "@/lib/api/skills";
|
||||
import type { SkillStorageLocation } from "@/types";
|
||||
|
||||
export interface SkillStorageLocationSettingsProps {
|
||||
value: SkillStorageLocation;
|
||||
installedCount: number;
|
||||
onMigrated: (target: SkillStorageLocation) => void;
|
||||
}
|
||||
|
||||
export function SkillStorageLocationSettings({
|
||||
value,
|
||||
installedCount,
|
||||
onMigrated,
|
||||
}: SkillStorageLocationSettingsProps) {
|
||||
const { t } = useTranslation();
|
||||
const [pendingTarget, setPendingTarget] =
|
||||
useState<SkillStorageLocation | null>(null);
|
||||
const [isMigrating, setIsMigrating] = useState(false);
|
||||
|
||||
const handleSelect = (target: SkillStorageLocation) => {
|
||||
if (target === value) return;
|
||||
if (installedCount > 0) {
|
||||
setPendingTarget(target);
|
||||
} else {
|
||||
doMigrate(target);
|
||||
}
|
||||
};
|
||||
|
||||
const doMigrate = async (target: SkillStorageLocation) => {
|
||||
setIsMigrating(true);
|
||||
setPendingTarget(null);
|
||||
try {
|
||||
const result: MigrationResult = await skillsApi.migrateStorage(target);
|
||||
if (result.errors.length > 0) {
|
||||
toast.warning(
|
||||
t("settings.skillStorage.migrationPartial", {
|
||||
migrated: result.migratedCount,
|
||||
errors: result.errors.length,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
toast.success(
|
||||
t("settings.skillStorage.migrationSuccess", {
|
||||
count: result.migratedCount,
|
||||
}),
|
||||
);
|
||||
}
|
||||
onMigrated(target);
|
||||
} catch (error) {
|
||||
toast.error(String(error));
|
||||
} finally {
|
||||
setIsMigrating(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="space-y-2">
|
||||
<header className="space-y-1">
|
||||
<h3 className="text-sm font-medium">
|
||||
{t("settings.skillStorage.title")}
|
||||
</h3>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t("settings.skillStorage.description")}
|
||||
</p>
|
||||
</header>
|
||||
<div className="inline-flex gap-1 rounded-md border border-border-default bg-background p-1">
|
||||
<StorageButton
|
||||
active={value === "cc_switch"}
|
||||
disabled={isMigrating}
|
||||
onClick={() => handleSelect("cc_switch")}
|
||||
>
|
||||
{t("settings.skillStorage.ccSwitch")}
|
||||
</StorageButton>
|
||||
<StorageButton
|
||||
active={value === "unified"}
|
||||
disabled={isMigrating}
|
||||
onClick={() => handleSelect("unified")}
|
||||
>
|
||||
{isMigrating && value !== "unified" ? (
|
||||
<Loader2 size={14} className="mr-1 animate-spin" />
|
||||
) : null}
|
||||
{t("settings.skillStorage.unified")}
|
||||
</StorageButton>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{value === "unified"
|
||||
? t("settings.skillStorage.unifiedHint")
|
||||
: t("settings.skillStorage.ccSwitchHint")}
|
||||
</p>
|
||||
|
||||
{/* 迁移确认对话框 */}
|
||||
<Dialog
|
||||
open={pendingTarget !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setPendingTarget(null);
|
||||
}}
|
||||
>
|
||||
<DialogContent className="max-w-md" zIndex="alert">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("settings.skillStorage.confirmTitle")}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{t("settings.skillStorage.confirmMessage", {
|
||||
count: installedCount,
|
||||
})}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setPendingTarget(null)}>
|
||||
{t("common.cancel")}
|
||||
</Button>
|
||||
<Button onClick={() => pendingTarget && doMigrate(pendingTarget)}>
|
||||
{t("common.confirm")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
interface StorageButtonProps {
|
||||
active: boolean;
|
||||
disabled?: boolean;
|
||||
onClick: () => void;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
function StorageButton({
|
||||
active,
|
||||
disabled,
|
||||
onClick,
|
||||
children,
|
||||
}: StorageButtonProps) {
|
||||
return (
|
||||
<Button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
size="sm"
|
||||
variant={active ? "default" : "ghost"}
|
||||
className={cn(
|
||||
"min-w-[96px]",
|
||||
active
|
||||
? "shadow-sm"
|
||||
: "text-muted-foreground hover:text-foreground hover:bg-muted",
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -478,6 +478,18 @@
|
||||
"geminiDesc": "Google Gemini CLI",
|
||||
"opencodeDesc": "OpenCode CLI"
|
||||
},
|
||||
"skillStorage": {
|
||||
"title": "Skill Storage Location",
|
||||
"description": "Choose where CC Switch stores the master copies of your skills",
|
||||
"ccSwitch": "CC Switch",
|
||||
"unified": "~/.agents/skills",
|
||||
"ccSwitchHint": "Skills are stored in ~/.cc-switch/skills/ and synced to each app via symlink or copy.",
|
||||
"unifiedHint": "Skills are stored in ~/.agents/skills/, the Agent Skills open standard. Compatible tools (Claude Code, Codex, Gemini CLI, etc.) discover skills here natively.",
|
||||
"confirmTitle": "Migrate Skill Storage",
|
||||
"confirmMessage": "{{count}} skill(s) will be moved to the new location. Continue?",
|
||||
"migrationSuccess": "Successfully migrated {{count}} skill(s)",
|
||||
"migrationPartial": "Migrated {{migrated}} skill(s), {{errors}} error(s). Check logs for details."
|
||||
},
|
||||
"skillSync": {
|
||||
"title": "Skill Sync Method",
|
||||
"description": "Choose how to sync Skills files",
|
||||
|
||||
@@ -478,6 +478,18 @@
|
||||
"geminiDesc": "Google Gemini CLI",
|
||||
"opencodeDesc": "OpenCode CLI"
|
||||
},
|
||||
"skillStorage": {
|
||||
"title": "スキル保存場所",
|
||||
"description": "CC Switch がスキルのマスターコピーを保存するディレクトリを選択します",
|
||||
"ccSwitch": "CC Switch",
|
||||
"unified": "~/.agents/skills",
|
||||
"ccSwitchHint": "スキルは ~/.cc-switch/skills/ に保存され、シンボリックリンクまたはコピーで各アプリに同期されます。",
|
||||
"unifiedHint": "スキルは ~/.agents/skills/ に保存されます(Agent Skills オープン標準)。対応ツール(Claude Code、Codex、Gemini CLI など)はこのディレクトリのスキルを直接検出します。",
|
||||
"confirmTitle": "スキル保存場所の移行",
|
||||
"confirmMessage": "{{count}} 個のスキルを新しい場所に移動します。続行しますか?",
|
||||
"migrationSuccess": "{{count}} 個のスキルを移行しました",
|
||||
"migrationPartial": "{{migrated}} 個のスキルを移行、{{errors}} 個のエラー。詳細はログを確認してください。"
|
||||
},
|
||||
"skillSync": {
|
||||
"title": "スキル同期方式",
|
||||
"description": "スキルファイルの同期方法を選択",
|
||||
|
||||
@@ -478,6 +478,18 @@
|
||||
"geminiDesc": "Google Gemini CLI",
|
||||
"opencodeDesc": "OpenCode CLI"
|
||||
},
|
||||
"skillStorage": {
|
||||
"title": "技能存储位置",
|
||||
"description": "选择 CC Switch 存放技能主副本的目录",
|
||||
"ccSwitch": "CC Switch",
|
||||
"unified": "~/.agents/skills",
|
||||
"ccSwitchHint": "技能存储在 ~/.cc-switch/skills/,由 CC Switch 统一管理并同步到各应用。",
|
||||
"unifiedHint": "技能存储在 ~/.agents/skills/,遵循 Agent Skills 开放标准。兼容的工具(Claude Code、Codex、Gemini CLI 等)可直接发现此目录中的技能。",
|
||||
"confirmTitle": "迁移技能存储",
|
||||
"confirmMessage": "将移动 {{count}} 个技能到新位置,是否继续?",
|
||||
"migrationSuccess": "已成功迁移 {{count}} 个技能",
|
||||
"migrationPartial": "迁移了 {{migrated}} 个技能,{{errors}} 个失败,请查看日志"
|
||||
},
|
||||
"skillSync": {
|
||||
"title": "Skill 同步方式",
|
||||
"description": "选择 Skills 的文件同步策略",
|
||||
|
||||
@@ -88,6 +88,13 @@ export interface SkillUpdateInfo {
|
||||
remoteHash: string;
|
||||
}
|
||||
|
||||
/** 存储位置迁移结果 */
|
||||
export interface MigrationResult {
|
||||
migratedCount: number;
|
||||
skippedCount: number;
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
/** 仓库配置 */
|
||||
export interface SkillRepo {
|
||||
owner: string;
|
||||
@@ -169,6 +176,13 @@ export const skillsApi = {
|
||||
return await invoke("update_skill", { id });
|
||||
},
|
||||
|
||||
/** 迁移 Skill 存储位置 */
|
||||
async migrateStorage(
|
||||
target: "cc_switch" | "unified",
|
||||
): Promise<MigrationResult> {
|
||||
return await invoke("migrate_skill_storage", { target });
|
||||
},
|
||||
|
||||
// ========== 兼容旧 API ==========
|
||||
|
||||
/** 获取技能列表(兼容旧 API) */
|
||||
|
||||
@@ -29,6 +29,7 @@ export const settingsSchema = z.object({
|
||||
|
||||
// Skill 同步设置
|
||||
skillSyncMethod: z.enum(["auto", "symlink", "copy"]).optional(),
|
||||
skillStorageLocation: z.enum(["cc_switch", "unified"]).optional(),
|
||||
|
||||
// WebDAV v2 同步设置(通过专用命令保存,schema 仅用于读取)
|
||||
webdavSync: z
|
||||
|
||||
@@ -177,6 +177,9 @@ export interface ProviderMeta {
|
||||
// Skill 同步方式
|
||||
export type SkillSyncMethod = "auto" | "symlink" | "copy";
|
||||
|
||||
// Skill 存储位置
|
||||
export type SkillStorageLocation = "cc_switch" | "unified";
|
||||
|
||||
// Claude API 格式类型
|
||||
// - "anthropic": 原生 Anthropic Messages API 格式,直接透传
|
||||
// - "openai_chat": OpenAI Chat Completions 格式,需要格式转换
|
||||
@@ -292,6 +295,8 @@ export interface Settings {
|
||||
// ===== Skill 同步设置 =====
|
||||
// Skill 同步方式:auto(默认,优先 symlink)、symlink、copy
|
||||
skillSyncMethod?: SkillSyncMethod;
|
||||
// Skill 存储位置:cc_switch(默认)或 unified(~/.agents/skills/)
|
||||
skillStorageLocation?: SkillStorageLocation;
|
||||
|
||||
// ===== WebDAV v2 同步设置 =====
|
||||
webdavSync?: WebDavSyncSettings;
|
||||
|
||||
Reference in New Issue
Block a user