feat(skills): usage stats, source filtering, archived skills, provenance, pin toggle (#386)

This commit is contained in:
Desmond Zhang
2026-05-02 10:56:58 +10:00
committed by GitHub
parent 018053db19
commit 9325aa5482
16 changed files with 753 additions and 166 deletions
@@ -1,14 +1,25 @@
<script setup lang="ts">
import { ref, watch } from 'vue'
import MarkdownRenderer from '@/components/hermes/chat/MarkdownRenderer.vue'
import { fetchSkillContent, fetchSkillFiles, type SkillFileEntry } from '@/api/hermes/skills'
import { fetchSkillContent, fetchSkillFiles, pinSkillApi, type SkillFileEntry } from '@/api/hermes/skills'
import { useI18n } from 'vue-i18n'
import { useMessage } from 'naive-ui'
const { t } = useI18n()
const message = useMessage()
const props = defineProps<{
category: string
skill: string
skillName: string
patchCount?: number
useCount?: number
viewCount?: number
pinned?: boolean
}>()
const emit = defineEmits<{
pinToggled: [name: string, pinned: boolean]
}>()
const content = ref('')
@@ -67,6 +78,22 @@ function backToSkill() {
fileContent.value = ''
}
const pinLoading = ref(false)
async function handlePinToggle() {
if (pinLoading.value) return
pinLoading.value = true
try {
const newPinned = !props.pinned
await pinSkillApi(props.skillName, newPinned)
emit('pinToggled', props.skillName, newPinned)
} catch (err: any) {
message.error(t('skills.pinFailed') + `: ${err.message}`)
} finally {
pinLoading.value = false
}
}
watch(() => `${props.category}/${props.skill}`, loadSkill, { immediate: true })
</script>
@@ -77,6 +104,23 @@ watch(() => `${props.category}/${props.skill}`, loadSkill, { immediate: true })
<span class="detail-category">{{ category }}</span>
<span class="detail-separator">/</span>
<span class="detail-name">{{ skill }}</span>
<div class="usage-stats">
<button class="pin-toggle" :class="{ active: pinned }" :disabled="pinLoading" :title="pinned ? t('skills.unpin') : t('skills.pin')" @click="handlePinToggle">
<svg width="16" height="16" viewBox="0 0 24 24" :fill="pinned ? 'currentColor' : 'none'" stroke="currentColor" stroke-width="2"><path d="M16 12V4h1V2H7v2h1v8l-2 2v2h5.2v6h1.6v-6H18v-2l-2-2z"/></svg>
</button>
<span v-if="viewCount != null" class="usage-stat" title="Views">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
{{ viewCount }}
</span>
<span v-if="useCount != null" class="usage-stat" title="Uses">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>
{{ useCount }}
</span>
<span v-if="patchCount != null" class="usage-stat" title="Patches">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>
{{ patchCount }}
</span>
</div>
</div>
<div v-if="loading && !content" class="detail-loading">{{ t('common.loading') }}</div>
@@ -136,6 +180,8 @@ watch(() => `${props.category}/${props.skill}`, loadSkill, { immediate: true })
border-bottom: 1px solid $border-color;
margin-bottom: 12px;
font-size: 15px;
display: flex;
align-items: center;
}
.detail-category {
@@ -153,6 +199,59 @@ watch(() => `${props.category}/${props.skill}`, loadSkill, { immediate: true })
font-weight: 600;
}
.usage-stats {
display: flex;
align-items: center;
gap: 12px;
margin-left: auto;
padding-left: 12px;
}
.usage-stat {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 13px;
font-weight: 500;
color: $text-secondary;
white-space: nowrap;
svg {
opacity: 0.7;
}
}
.pin-toggle {
display: inline-flex;
align-items: center;
justify-content: center;
border: 1px solid transparent;
background: none;
color: $text-muted;
cursor: pointer;
padding: 4px;
border-radius: 6px;
opacity: 0.5;
transition: all $transition-fast;
&:hover {
opacity: 1;
color: $accent-primary;
background: rgba(var(--accent-primary-rgb), 0.08);
border-color: rgba(var(--accent-primary-rgb), 0.15);
}
&.active {
opacity: 1;
color: $accent-primary;
}
&:disabled {
cursor: wait;
opacity: 0.3;
}
}
.detail-loading {
flex: 1;
display: flex;
@@ -1,235 +1,335 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import { NSwitch, useMessage } from 'naive-ui'
import type { SkillCategory } from '@/api/hermes/skills'
import type { SkillCategory, SkillSource, SkillInfo } from '@/api/hermes/skills'
import { toggleSkill } from '@/api/hermes/skills'
import { useI18n } from 'vue-i18n'
type SourceFilter = SkillSource | 'modified'
const { t } = useI18n()
const message = useMessage()
const props = defineProps<{
categories: SkillCategory[]
selectedSkill: string | null
searchQuery: string
categories: SkillCategory[]
archived: SkillInfo[]
selectedSkill: string | null
searchQuery: string
sourceFilter: SourceFilter | null
}>()
const emit = defineEmits<{
select: [category: string, skill: string]
select: [category: string, skill: string]
}>()
const collapsedCategories = ref<Set<string>>(new Set())
const archiveCollapsed = ref(true)
const togglingSkills = ref<Set<string>>(new Set())
const filteredArchived = computed(() => {
let result = props.archived
if (props.sourceFilter && props.sourceFilter !== 'modified') {
result = result.filter(s => (s.source || 'local') === props.sourceFilter)
}
if (props.searchQuery) {
const q = props.searchQuery.toLowerCase()
result = result.filter(s => s.name.toLowerCase().includes(q) || s.description.toLowerCase().includes(q))
}
return result
})
const filteredCategories = computed(() => {
if (!props.searchQuery) return props.categories
const q = props.searchQuery.toLowerCase()
return props.categories
.map(cat => ({
...cat,
skills: cat.skills.filter(
s => s.name.toLowerCase().includes(q) || s.description.toLowerCase().includes(q),
),
}))
.filter(cat => cat.skills.length > 0 || cat.name.toLowerCase().includes(q))
let result = props.categories
// Filter by source
if (props.sourceFilter) {
result = result
.map(cat => ({
...cat,
skills: cat.skills.filter(s => {
if (props.sourceFilter === 'modified') return s.modified
return (s.source || 'local') === props.sourceFilter
}),
}))
.filter(cat => cat.skills.length > 0)
}
// Filter by search query
if (props.searchQuery) {
const q = props.searchQuery.toLowerCase()
result = result
.map(cat => ({
...cat,
skills: cat.skills.filter(
s => s.name.toLowerCase().includes(q) || s.description.toLowerCase().includes(q),
),
}))
.filter(cat => cat.skills.length > 0 || cat.name.toLowerCase().includes(q))
}
return result
})
function toggleCategory(name: string) {
if (collapsedCategories.value.has(name)) {
collapsedCategories.value.delete(name)
} else {
collapsedCategories.value.add(name)
}
if (collapsedCategories.value.has(name)) {
collapsedCategories.value.delete(name)
} else {
collapsedCategories.value.add(name)
}
}
function handleSelect(category: string, skill: string) {
emit('select', category, skill)
function handleSelect(category: string, skillName: string) {
emit('select', category, skillName)
}
/** Unique key for selection tracking */
function skillKey(catName: string, skill: { name: string }): string {
return `${catName}/${skill.name}`
}
async function handleToggle(category: string, skillName: string, newEnabled: boolean) {
if (togglingSkills.value.has(skillName)) return
togglingSkills.value.add(skillName)
if (togglingSkills.value.has(skillName)) return
togglingSkills.value.add(skillName)
try {
await toggleSkill(skillName, newEnabled)
// Update local state
const cat = props.categories.find(c => c.name === category)
const skill = cat?.skills.find(s => s.name === skillName)
if (skill) skill.enabled = newEnabled
} catch (err: any) {
message.error(t('skills.toggleFailed') + `: ${err.message}`)
} finally {
togglingSkills.value.delete(skillName)
}
try {
await toggleSkill(skillName, newEnabled)
// Update local state
const cat = props.categories.find(c => c.name === category)
const skill = cat?.skills.find(s => s.name === skillName)
if (skill) skill.enabled = newEnabled
} catch (err: any) {
message.error(t('skills.toggleFailed') + `: ${err.message}`)
} finally {
togglingSkills.value.delete(skillName)
}
}
</script>
<template>
<div class="skill-list">
<div v-if="filteredCategories.length === 0" class="skill-empty">
{{ searchQuery ? t('skills.noMatch') : t('skills.noSkills') }}
<div class="skill-list">
<div v-if="filteredCategories.length === 0" class="skill-empty">
{{ searchQuery ? t('skills.noMatch') : t('skills.noSkills') }}
</div>
<div v-for="cat in filteredCategories" :key="cat.name" class="skill-category">
<button class="category-header" @click="toggleCategory(cat.name)">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
class="category-arrow" :class="{ collapsed: collapsedCategories.has(cat.name) }">
<polyline points="6 9 12 15 18 9" />
</svg>
<span class="category-name">{{ cat.name }}</span>
<span class="category-count">{{ cat.skills.length }}</span>
</button>
<div v-if="!collapsedCategories.has(cat.name)" class="category-skills">
<button v-for="skill in cat.skills" :key="skillKey(cat.name, skill)" class="skill-item" :class="[
{ active: selectedSkill === skillKey(cat.name, skill) },
`source-${skill.source || 'local'}`,
]" @click="handleSelect(cat.name, skill.name)">
<div class="skill-info">
<span class="skill-name">
<span class="source-dot" :class="`dot-${skill.source || 'local'}`"
:title="t(`skills.source.${skill.source || 'local'}`)" />
{{ skill.name }}
<span v-if="skill.modified" class="modified-badge"
:title="t('skills.modified')"></span>
</span>
<span v-if="skill.description" class="skill-desc">{{ skill.description }}</span>
</div>
<NSwitch size="small" :value="skill.enabled !== false" :loading="togglingSkills.has(skill.name)"
@update:value="handleToggle(cat.name, skill.name, $event)" @click.stop />
</button>
</div>
</div>
<!-- Archived skills (separate section) -->
<div v-if="filteredArchived.length > 0 || archived.length > 0" class="skill-category archive-section">
<button class="category-header archive-header" @click="archiveCollapsed = !archiveCollapsed">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
class="category-arrow" :class="{ collapsed: archiveCollapsed }">
<polyline points="6 9 12 15 18 9" />
</svg>
<span class="category-name">{{ t('skills.archived') }}</span>
<span class="category-count">{{ archived.length }}</span>
</button>
<div v-if="!archiveCollapsed" class="category-skills">
<button v-for="skill in filteredArchived" :key="skillKey('.archive', skill)" class="skill-item skill-archived"
:class="{ active: selectedSkill === skillKey('.archive', skill) }"
@click="handleSelect('.archive', skill.name)">
<div class="skill-info">
<span class="skill-name">
<span class="source-dot" :class="`dot-${skill.source || 'local'}`"
:title="t(`skills.source.${skill.source || 'local'}`)" />
{{ skill.name }}
</span>
<span v-if="skill.description" class="skill-desc">{{ skill.description }}</span>
</div>
</button>
</div>
</div>
</div>
<div
v-for="cat in filteredCategories"
:key="cat.name"
class="skill-category"
>
<button class="category-header" @click="toggleCategory(cat.name)">
<svg
width="12" height="12" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2"
class="category-arrow"
:class="{ collapsed: collapsedCategories.has(cat.name) }"
>
<polyline points="6 9 12 15 18 9" />
</svg>
<span class="category-name">{{ cat.name }}</span>
<span class="category-count">{{ cat.skills.length }}</span>
</button>
<div v-if="!collapsedCategories.has(cat.name)" class="category-skills">
<button
v-for="skill in cat.skills"
:key="skill.name"
class="skill-item"
:class="{
active: selectedSkill === `${cat.name}/${skill.name}`,
}"
@click="handleSelect(cat.name, skill.name)"
>
<div class="skill-info">
<span class="skill-name">{{ skill.name }}</span>
<span v-if="skill.description" class="skill-desc">{{ skill.description }}</span>
</div>
<NSwitch
size="small"
:value="skill.enabled !== false"
:loading="togglingSkills.has(skill.name)"
@update:value="handleToggle(cat.name, skill.name, $event)"
@click.stop
/>
</button>
</div>
</div>
</div>
</template>
<style scoped lang="scss">
@use '@/styles/variables' as *;
.skill-list {
flex: 1;
overflow-y: auto;
padding: 8px;
flex: 1;
overflow-y: auto;
padding: 8px;
}
.skill-empty {
padding: 24px 16px;
font-size: 13px;
color: $text-muted;
text-align: center;
padding: 24px 16px;
font-size: 13px;
color: $text-muted;
text-align: center;
}
.skill-category {
margin-bottom: 4px;
margin-bottom: 4px;
}
.category-header {
display: flex;
align-items: center;
gap: 6px;
width: 100%;
padding: 6px 10px;
border: none;
background: none;
color: $text-secondary;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.3px;
cursor: pointer;
border-radius: $radius-sm;
display: flex;
align-items: center;
gap: 6px;
width: 100%;
padding: 6px 10px;
border: none;
background: none;
color: $text-secondary;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.3px;
cursor: pointer;
border-radius: $radius-sm;
&:hover {
background: rgba(var(--accent-primary-rgb), 0.04);
}
&:hover {
background: rgba(var(--accent-primary-rgb), 0.04);
}
}
.category-arrow {
flex-shrink: 0;
transition: transform $transition-fast;
flex-shrink: 0;
transition: transform $transition-fast;
&.collapsed {
transform: rotate(-90deg);
}
&.collapsed {
transform: rotate(-90deg);
}
}
.category-name {
flex: 1;
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.category-count {
font-size: 11px;
color: $text-muted;
background: rgba(var(--accent-primary-rgb), 0.06);
padding: 1px 6px;
border-radius: 8px;
font-size: 11px;
color: $text-muted;
background: rgba(var(--accent-primary-rgb), 0.06);
padding: 1px 6px;
border-radius: 8px;
}
.category-skills {
padding: 2px 0 4px;
padding: 2px 0 4px;
}
.skill-item {
display: flex;
flex-direction: row;
align-items: center;
width: 100%;
padding: 6px 10px 6px 28px;
border: none;
background: none;
color: $text-secondary;
font-size: 13px;
text-align: left;
cursor: pointer;
border-radius: $radius-sm;
transition: all $transition-fast;
gap: 8px;
display: flex;
flex-direction: row;
align-items: center;
width: 100%;
padding: 6px 10px 6px 28px;
border: none;
background: none;
color: $text-secondary;
font-size: 13px;
text-align: left;
cursor: pointer;
border-radius: $radius-sm;
transition: all $transition-fast;
gap: 8px;
&:hover {
background: rgba(var(--accent-primary-rgb), 0.06);
color: $text-primary;
}
&:hover {
background: rgba(var(--accent-primary-rgb), 0.06);
color: $text-primary;
}
&.active {
background: rgba(var(--accent-primary-rgb), 0.1);
color: $text-primary;
font-weight: 500;
}
&.active {
background: rgba(var(--accent-primary-rgb), 0.1);
color: $text-primary;
font-weight: 500;
}
}
// Source indicator dot
.source-dot {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
margin-right: 6px;
flex-shrink: 0;
vertical-align: middle;
}
.dot-builtin {
background: #888;
}
.dot-hub {
background: #4a90d9;
}
.dot-local {
background: #66bb6a;
}
.skill-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.skill-name {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.modified-badge {
font-size: 11px;
color: $warning;
margin-left: 2px;
opacity: 0.7;
}
.skill-desc {
font-size: 11px;
color: $text-muted;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-top: 1px;
font-size: 11px;
color: $text-muted;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-top: 1px;
}
.archive-section {
margin-top: 12px;
padding-top: 8px;
border-top: 1px solid $border-color;
}
.archive-header {
color: $text-muted;
}
.skill-archived {
opacity: 0.6;
padding-left: 28px;
}
</style>