diff --git a/src/components/PluginsSection.tsx b/src/components/PluginsSection.tsx index 4856ac35..e160df49 100644 --- a/src/components/PluginsSection.tsx +++ b/src/components/PluginsSection.tsx @@ -5,6 +5,7 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; +import { Separator } from '@/components/ui/separator'; import { usePlugins } from '@/hooks/usePlugins'; import { useToast } from '@/hooks/useToast'; import { Alert, AlertDescription } from '@/components/ui/alert'; @@ -12,7 +13,7 @@ import { Alert, AlertDescription } from '@/components/ui/alert'; export function PluginsSection() { const { t } = useTranslation(); const { toast } = useToast(); - const { plugins, skills, clonePlugin, syncPlugin, deletePlugin } = usePlugins(); + const { plugins, skills, clonePlugin, syncPlugin, deletePlugin, getPluginGitInfo } = usePlugins(); const [gitUrl, setGitUrl] = useState(''); const handleAddPlugin = async () => { @@ -76,12 +77,49 @@ export function PluginsSection() { }, {} as Record); return ( -
-
- -

{t('plugins')}

+
+ {/* Divider */} + + + {/* Plugins Header */} +
+
+ +

{t('plugins')}

+
+

+ {t('pluginsDescription')} +

+ {/* Configured Plugins List */} + {plugins.length > 0 ? ( +
+ {plugins.map((pluginName) => { + const pluginSkills = skillsByPlugin[pluginName] || []; + const isSyncing = syncPlugin.isPending && syncPlugin.variables === pluginName; + const isDeleting = deletePlugin.isPending && deletePlugin.variables === pluginName; + + return ; + })} +
+ ) : ( + + + {t('noPluginsConfigured')} + + + )} + {/* Add Plugin Section */} @@ -131,116 +169,123 @@ export function PluginsSection() { - - {/* Configured Plugins List */} - {plugins.length > 0 ? ( -
- {plugins.map((pluginName) => { - const pluginSkills = skillsByPlugin[pluginName] || []; - const isSyncing = syncPlugin.isPending && syncPlugin.variables === pluginName; - const isDeleting = deletePlugin.isPending && deletePlugin.variables === pluginName; - - return ( - - - -
- - {pluginName} - {pluginSkills.length > 0 && ( - - ({pluginSkills.length} {pluginSkills.length === 1 ? 'skill' : 'skills'}) - - )} -
-
- -
- {/* Skills List */} - {pluginSkills.length > 0 && ( -
- -
- {pluginSkills.map((skill) => ( -
-
-
{skill.name}
-
- {skill.description} -
-
-
- ))} -
-
- )} - - {pluginSkills.length === 0 && ( - - - {t('noSkillsFound')} - - - )} - - {/* Plugin Actions */} -
- - -
-
-
-
-
- ); - })} -
- ) : ( - - - {t('noPluginsConfigured')} - - - )}
); } + +interface PluginItemProps { + pluginName: string; + pluginSkills: Array<{ name: string; description: string; path: string; plugin: string }>; + isSyncing: boolean; + isDeleting: boolean; + onSync: (pluginName: string) => void; + onDelete: (pluginName: string) => void; + getPluginGitInfo: (pluginName: string) => { data: { commitHash: string; commitDate: Date; commitMessage: string } | null | undefined; isLoading: boolean }; +} + +function PluginItem({ pluginName, pluginSkills, isSyncing, isDeleting, onSync, onDelete, getPluginGitInfo }: PluginItemProps) { + const { t } = useTranslation(); + const { data: gitInfo } = getPluginGitInfo(pluginName); + + return ( + + + +
+ + {pluginName} + {pluginSkills.length > 0 && ( + + ({pluginSkills.length} {pluginSkills.length === 1 ? 'skill' : 'skills'}) + + )} +
+
+ +
+ {/* Skills List */} + {pluginSkills.length > 0 && ( +
+ +
+ {pluginSkills.map((skill) => ( +
+
+
{skill.name}
+
+ {skill.description} +
+
+
+ ))} +
+
+ )} + + {pluginSkills.length === 0 && ( + + + {t('noSkillsFound')} + + + )} + + {/* Plugin Actions and Git Info */} +
+ {gitInfo && ( +
+ {gitInfo.commitHash.substring(0, 7)} + • + {gitInfo.commitDate.toLocaleDateString()} +
+ )} +
+ + +
+
+
+
+
+
+ ); +} diff --git a/src/hooks/usePlugins.ts b/src/hooks/usePlugins.ts index b0a3f1bb..5ff4d3ad 100644 --- a/src/hooks/usePlugins.ts +++ b/src/hooks/usePlugins.ts @@ -1,7 +1,7 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { useFS } from './useFS'; import { useFSPaths } from './useFSPaths'; -import { getPlugins, getAllSkills, deletePlugin as deletePluginFn } from '@/lib/plugins'; +import { getPlugins, getAllSkills, deletePlugin as deletePluginFn, getPluginGitInfo, type PluginGitInfo } from '@/lib/plugins'; import { useGit } from './useGit'; import { join } from 'path-browserify'; @@ -115,6 +115,16 @@ export function usePlugins() { }, }); + // Function to get git info for a specific plugin + const getPluginGitInfoQuery = (pluginName: string) => { + return useQuery({ + queryKey: ['plugin-git-info', pluginsPath, pluginName], + queryFn: async () => { + return await getPluginGitInfo(fs, pluginsPath, pluginName); + }, + }); + }; + return { plugins: pluginsQuery.data || [], isLoadingPlugins: pluginsQuery.isLoading, @@ -123,5 +133,6 @@ export function usePlugins() { clonePlugin, syncPlugin, deletePlugin, + getPluginGitInfo: getPluginGitInfoQuery, }; } diff --git a/src/lib/plugins.ts b/src/lib/plugins.ts index 4c832ad9..fc9ca46f 100644 --- a/src/lib/plugins.ts +++ b/src/lib/plugins.ts @@ -1,6 +1,7 @@ import { join } from 'path-browserify'; import matter from 'gray-matter'; import type { JSRuntimeFS } from './JSRuntime'; +import * as git from 'isomorphic-git'; export interface Skill { /** Skill name (alphanumeric lowercase only) */ @@ -19,6 +20,12 @@ export interface SkillFrontmatter { [key: string]: unknown; } +export interface PluginGitInfo { + commitHash: string; + commitDate: Date; + commitMessage: string; +} + /** * Validates a skill name (alphanumeric lowercase with hyphens) */ @@ -142,6 +149,36 @@ export async function readSkillContent(fs: JSRuntimeFS, skill: Skill): Promise { + const pluginPath = join(pluginsPath, pluginName); + + try { + // Get the latest commit + const commits = await git.log({ + fs, + dir: pluginPath, + depth: 1, + }); + + if (commits.length === 0) { + return null; + } + + const commit = commits[0]; + + return { + commitHash: commit.oid, + commitDate: new Date(commit.commit.committer.timestamp * 1000), + commitMessage: commit.commit.message, + }; + } catch { + return null; + } +} + /** * Delete a plugin directory */ diff --git a/src/locales/en.json b/src/locales/en.json index 01165bac..2ff60d9d 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -455,6 +455,7 @@ "alreadyRedeemed": "Already Redeemed", "giftCardAlreadyRedeemed": "This gift card has already been redeemed.", "plugins": "Plugins", + "pluginsDescription": "Extend the AI's capabilities with reusable skills from Git repositories.", "addPlugin": "Add Plugin", "gitRepositoryUrl": "Git Repository URL", "pluginDescription": "Plugins can contain skills that extend the AI's capabilities with specialized workflows.",