Refactor: share version-library grouping and bumpPatch
Extracts the per-key version grouping + same-version dedupe (org-owned shadows builtin) into lib/versionedLibrary.groupVersions and the semver patch bump into lib/semver.bumpPatch, both of which were duplicated byte-for-byte across the Skills and Agent-profiles pages. One source of truth so the two libraries can't drift. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,8 @@ import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from '
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { MarkdownEditor } from '@/components/MarkdownEditor'
|
||||
import { api } from '@/lib/api'
|
||||
import { bumpPatch } from '@/lib/semver'
|
||||
import { groupVersions } from '@/lib/versionedLibrary'
|
||||
import { useAuth } from '@/store/auth'
|
||||
|
||||
interface ActionDto {
|
||||
@@ -106,19 +108,6 @@ const emptyForm = (): FormState => ({
|
||||
goldenTests: [],
|
||||
})
|
||||
|
||||
/** Bump the last numeric segment of a semver-ish string (1.0.0 → 1.0.1). */
|
||||
function bumpPatch(version: string): string {
|
||||
const parts = version.split('.')
|
||||
for (let i = parts.length - 1; i >= 0; i--) {
|
||||
const n = Number(parts[i])
|
||||
if (Number.isInteger(n)) {
|
||||
parts[i] = String(n + 1)
|
||||
return parts.join('.')
|
||||
}
|
||||
}
|
||||
return `${version}.1`
|
||||
}
|
||||
|
||||
const csv = (s: string): string[] =>
|
||||
s.split(',').map((x) => x.trim()).filter(Boolean)
|
||||
|
||||
@@ -175,26 +164,8 @@ export function SkillsPage() {
|
||||
void load()
|
||||
}, [load])
|
||||
|
||||
// Group every version under its key; newest (and the org's own) first comes from the API order.
|
||||
const groups = useMemo(() => {
|
||||
const byKey = new Map<string, SkillSummary[]>()
|
||||
for (const s of skills) {
|
||||
const list = byKey.get(s.skillKey) ?? []
|
||||
list.push(s)
|
||||
byKey.set(s.skillKey, list)
|
||||
}
|
||||
// If an org has forked a builtin but kept the same version, the org's own copy shadows the builtin
|
||||
// (it's the one that runs and the one you can edit), so the picker shows one clear, editable entry.
|
||||
for (const [key, list] of byKey) {
|
||||
const perVersion = new Map<string, SkillSummary>()
|
||||
for (const s of list) {
|
||||
const existing = perVersion.get(s.version)
|
||||
if (!existing || (existing.origin === 'Builtin' && s.origin !== 'Builtin')) perVersion.set(s.version, s)
|
||||
}
|
||||
byKey.set(key, [...perVersion.values()])
|
||||
}
|
||||
return [...byKey.entries()].sort((a, b) => a[0].localeCompare(b[0]))
|
||||
}, [skills])
|
||||
// Group every version under its key (org-owned shadows a same-version builtin). See groupVersions.
|
||||
const groups = useMemo(() => groupVersions(skills, (s) => s.skillKey), [skills])
|
||||
|
||||
// Read-only details: reconstruct the SKILL.md and render it. Works for builtins too — inspect a
|
||||
// skill (frontmatter, prompt body, actions, golden tests) without forking or versioning it.
|
||||
|
||||
Reference in New Issue
Block a user