šŖ¢ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(skills): compare saved versions and draft changes (#18409)
tobi_kl7ba71f0f4517
diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex b40cab54e6..73330866d1 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -170,6 +170,7 @@ const events = {"new_form_open","version_create","version_download",+ "version_compare","delete","import_open","import",diff --git a/web/src/features/skills/components/CreateSkillVersionDialog.tsx b/web/src/features/skills/components/CreateSkillVersionDialog.tsxindex 645ecaaa0f..2703977a18 100644--- a/web/src/features/skills/components/CreateSkillVersionDialog.tsx+++ b/web/src/features/skills/components/CreateSkillVersionDialog.tsx@@ -5,8 +5,10 @@ import { Dialog } from "@/src/components/design-system/Dialog/Dialog";import { Label } from "@/src/components/ui/label";import { Textarea } from "@/src/components/ui/textarea";import { type SkillEditorStore } from "@/src/features/skills/components/skillEditorStore";+import { SkillDraftChanges } from "./SkillDraftChanges";export function CreateSkillVersionDialog({+ projectId,store,name,isFirstVersion,@@ -14,6 +16,7 @@ export function CreateSkillVersionDialog({disabled,onConfirm,}: {+ projectId: string;store: SkillEditorStore;name: string;isFirstVersion: boolean;@@ -33,6 +36,7 @@ export function CreateSkillVersionDialog({return (<Dialogtitle={isFirstVersion ? "Create skill" : "Create new version"}+ size="xxl"actions={[{label: isFirstVersion ? "Create skill" : "Create version",@@ -44,45 +48,53 @@ export function CreateSkillVersionDialog({]}><Dialog.Body>- <div className="ph-no-capture flex flex-col gap-4">- <p className="text-muted-foreground">- {isFirstVersion ? (- <>- Create <strong>{name}</strong> as a new skill using the current- files.- </>- ) : (- <>- Commit the current draft of <strong>{name}</strong> as an- immutable version.- </>- )}- </p>- {isFirstVersion && originalName ? (- <Alert variant="warning" icon={TriangleAlert}>- <Alert.Title>You are duplicating this skill</Alert.Title>- <Alert.Description>- This creates <strong>{name}</strong> as a separate skill,- starting at version 1. <strong>{originalName}</strong> stays- unchanged.- </Alert.Description>- </Alert>- ) : null}- <div className="grid gap-2">- <Label htmlFor="skill-version-note">Version note</Label>- <p className="text-muted-foreground text-sm">- Describe the changes in this version to make the history easier to- understand.+ <div className="ph-no-capture flex min-h-0 flex-1 flex-col gap-4">+ <div className="flex shrink-0 flex-col gap-4">+ <p className="text-muted-foreground">+ {isFirstVersion ? (+ <>+ Create <strong>{name}</strong> as a new skill using the+ current files.+ </>+ ) : (+ <>+ Commit the current draft of <strong>{name}</strong> as an+ immutable version.+ </>+ )}</p>- <Textarea- id="skill-version-note"- value={commitMessage}- onChange={(event) => setCommitMessage(event.target.value)}- placeholder="Add version noteā¦"- rows={5}- autoFocus- />+ {isFirstVersion && originalName ? (+ <Alert variant="warning" icon={TriangleAlert}>+ <Alert.Title>You are duplicating this skill</Alert.Title>+ <Alert.Description>+ This creates <strong>{name}</strong> as a separate skill,+ starting at version 1. <strong>{originalName}</strong> stays+ unchanged.+ </Alert.Description>+ </Alert>+ ) : null}+ <div className="grid gap-2">+ <Label htmlFor="skill-version-note">Version note</Label>+ <p className="text-muted-foreground text-sm">+ Describe the changes in this version to make the history easier+ to understand.+ </p>+ <Textarea+ id="skill-version-note"+ value={commitMessage}+ onChange={(event) => setCommitMessage(event.target.value)}+ placeholder="Add version noteā¦"+ rows={3}+ autoFocus+ />+ </div></div>+ <h3 className="shrink-0 text-sm font-bold">File changes</h3>+ <SkillDraftChanges+ projectId={projectId}+ store={store}+ isFirstVersion={isFirstVersion}+ /></div></Dialog.Body></Dialog>diff --git a/web/src/features/skills/components/SkillComparisonError.tsx b/web/src/features/skills/components/SkillComparisonError.tsxnew file mode 100644index 0000000000..334efa273c--- /dev/null+++ b/web/src/features/skills/components/SkillComparisonError.tsx@@ -0,0 +1,10 @@+import { Button } from "@/src/components/design-system/Button/Button";++export function SkillComparisonError({ retry }: { retry: () => void }) {+ return (+ <div role="alert" className="flex flex-col items-start gap-2 text-sm">+ <p>Could not load the comparison. Please try again.</p>+ <Button text="Retry" variant="secondary" onClick={retry} />+ </div>+ );+}diff --git a/web/src/features/skills/components/SkillDraftChanges.tsx b/web/src/features/skills/components/SkillDraftChanges.tsxnew file mode 100644index 0000000000..64f25e7a99--- /dev/null+++ b/web/src/features/skills/components/SkillDraftChanges.tsx@@ -0,0 +1,85 @@+import { useState } from "react";+import { useStore } from "zustand";+import { api } from "@/src/utils/api";+import { compareSkillFiles } from "@/src/features/skills/utils/compareSkillFiles";+import { type SkillDraftFile, type SkillEditorStore } from "./skillEditorStore";+import { SkillComparisonError } from "./SkillComparisonError";+import { SkillFileChanges } from "./SkillFileChanges";+import { SkillFileDiff } from "./SkillFileDiff";++export function SkillDraftChanges({+ projectId,+ store,+ isFirstVersion,+}: {+ projectId: string;+ store: SkillEditorStore;+ isFirstVersion: boolean;+}) {+ const [selectedPath, setSelectedPath] = useState<string>();+ const name = useStore(store, (state) => state.name);+ const baseVersion = useStore(store, (state) => state.baseVersion);+ const draftFiles = useStore(store, (state) => state.files);+ const hasBaseVersion = !isFirstVersion && baseVersion !== null;+ const base = api.skills.byName.useQuery(+ { projectId, name, version: baseVersion ?? 1 },+ {+ enabled: hasBaseVersion,+ refetchOnWindowFocus: false,+ meta: { silentAllErrors: true },+ },+ );+ function retryBase() {+ base.refetch();+ }+ if (hasBaseVersion && base.isError) {+ return <SkillComparisonError retry={retryBase} />;+ }+ if (hasBaseVersion && !base.data) {+ return (+ <p role="status" className="text-muted-foreground text-sm">+ Loading base versionā¦+ </p>+ );+ }+ const changes = compareSkillFiles(+ hasBaseVersion ? base.data!.files : [],+ Object.values(draftFiles).map((file) => ({+ path: file.path,+ sha256Hash: file.currentSha,+ })),+ );+ const selectedFile =+ changes.find((file) => file.path === selectedPath) ?? changes[0];+ const draft = selectedFile ? draftFiles[selectedFile.path] : undefined;+ const newFile = getDraftFileContent(draft);++ return (+ <SkillFileChanges+ files={changes}+ emptyMessage="No file changes in this draft."+ selectedFile={selectedFile}+ onSelectFile={setSelectedPath}+ >+ {selectedFile ? (+ <SkillFileDiff+ projectId={projectId}+ oldFile={+ selectedFile.oldFile?.sha256Hash+ ? { sha256Hash: selectedFile.oldFile.sha256Hash }+ : null+ }+ newFile={newFile}+ oldLabel={hasBaseVersion ? `Version ${baseVersion}` : "New skill"}+ newLabel="Draft"+ />+ ) : null}+ </SkillFileChanges>+ );+}++function getDraftFileContent(draft: SkillDraftFile | undefined) {+ if (draft?.content !== undefined) return { content: draft.content };+ if (draft?.sourceSha) return { sha256Hash: draft.sourceSha };+ return null;+}diff --git a/web/src/features/skills/components/SkillEditor.tsx b/web/src/features/skills/components/SkillEditor.tsxindex d2a4d5d899..0d66abc85c 100644--- a/web/src/features/skills/components/SkillEditor.tsx+++ b/web/src/features/skills/components/SkillEditor.tsx@@ -436,6 +436,7 @@ export function SkillEditor({<DialogController<boolean>renderDialog={({ state: createNew, closeDialog }) => (<CreateSkillVersionDialog+ projectId={projectId}store={store}name={createNew ? draftName : name}isFirstVersion={createNew}@@ -545,6 +546,8 @@ export function SkillEditor({<div className="flex min-h-[720px] flex-1 flex-col overflow-hidden border-t md:min-h-[560px] md:flex-row">{history.kind === "versions" ? (<SkillVersionHistory+ projectId={projectId}+ name={name}{...history}dirty={dirty}isDraft={isDraft}diff --git a/web/src/features/skills/components/SkillFileChanges.stories.tsx b/web/src/features/skills/components/SkillFileChanges.stories.tsxnew file mode 100644index 0000000000..0a3cfca504--- /dev/null+++ b/web/src/features/skills/components/SkillFileChanges.stories.tsx@@ -0,0 +1,53 @@+import { type ComponentProps, useState } from "react";+import preview from "../../../../.storybook/preview";+import DiffViewer from "@/src/components/DiffViewer";+import { compareSkillFiles } from "../utils/compareSkillFiles";+import { SkillFileChanges } from "./SkillFileChanges";++const meta = preview.meta({ component: FileStatusesExample });++export const FileStatuses = meta.story({+ args: {+ files: compareSkillFiles(+ [+ { path: "SKILL.md", sha256Hash: "original" },+ { path: "references/legacy.md", sha256Hash: "removed" },+ { path: "scripts/review.py", sha256Hash: "unchanged" },+ ],+ [+ { path: "SKILL.md", sha256Hash: "updated" },+ { path: "references/checklist.md", sha256Hash: "added" },+ { path: "scripts/review.py", sha256Hash: "unchanged" },+ ],+ ),+ emptyMessage: "No file changes.",+ },+});++function FileStatusesExample({+ files,+ emptyMessage,+}: Pick<ComponentProps<typeof SkillFileChanges>, "files" | "emptyMessage">) {+ const [selectedPath, setSelectedPath] = useState<string>();+ const selectedFile =+ files.find((file) => file.path === selectedPath) ?? files[0];+ return (+ <SkillFileChanges+ files={files}+ emptyMessage={emptyMessage}+ selectedFile={selectedFile}+ onSelectFile={setSelectedPath}+ >+ {selectedFile ? (+ <DiffViewer+ oldString={selectedFile.oldFile ? "Read the code.\n" : ""}+ newString={+ selectedFile.newFile ? "Read the code and run tests.\n" : ""+ }+ oldLabel="Version 1"+ newLabel="Draft"+ />+ ) : null}+ </SkillFileChanges>+ );+}diff --git a/web/src/features/skills/components/SkillFileChanges.tsx b/web/src/features/skills/components/SkillFileChanges.tsxnew file mode 100644index 0000000000..b256711aef--- /dev/null+++ b/web/src/features/skills/components/SkillFileChanges.tsx@@ -0,0 +1,104 @@+import { type MouseEvent, type ReactNode } from "react";+import { Badge } from "@/src/components/design-system/Badge/Badge";+import { type compareSkillFiles } from "@/src/features/skills/utils/compareSkillFiles";+import { cn } from "@/src/utils/tailwind";++const statusColors = {+ Modified: "blue",+ Added: "green",+ Removed: "red",+ Unchanged: "filled",+} as const;++export function SkillFileChanges({+ files,+ emptyMessage,+ selectedFile,+ onSelectFile,+ children,+}: {+ files: ReturnType<typeof compareSkillFiles>;+ emptyMessage: string;+ selectedFile: ReturnType<typeof compareSkillFiles>[number] | undefined;+ onSelectFile: (path: string) => void;+ children: ReactNode;+}) {+ const changedCount = files.filter(+ (file) => file.status !== "Unchanged",+ ).length;+ function handleSelectFile(event: MouseEvent<HTMLButtonElement>) {+ onSelectFile(event.currentTarget.value);+ }+ if (!changedCount) {+ return (+ <p role="status" className="text-muted-foreground text-sm">+ {emptyMessage}+ </p>+ );+ }++ return (+ <>+ <p className="text-muted-foreground text-sm">+ {changedCount} changed {changedCount === 1 ? "file" : "files"}+ </p>+ <div className="flex min-h-96 flex-1 flex-col gap-4 md:min-h-64 md:flex-row">+ <nav+ aria-label="Compared files"+ className="max-h-48 shrink-0 overflow-y-auto rounded-md border md:max-h-none md:w-64"+ >+ {files.map((file) => (+ <button+ key={file.path}+ type="button"+ aria-current={+ selectedFile?.path === file.path ? "true" : undefined+ }+ value={file.path}+ onClick={handleSelectFile}+ className={cn(+ "hover:bg-accent flex w-full flex-col gap-1 border-b p-3 text-left text-sm last:border-b-0",+ selectedFile?.path === file.path && "bg-accent",+ )}+ >+ <span+ className={cn(+ "w-full break-words",+ file.status === "Unchanged"+ ? "text-muted-foreground"+ : "font-bold",+ )}+ >+ {file.path}+ </span>+ <Badge+ text={file.status}+ color={statusColors[file.status]}+ size="sm"+ />+ </button>+ ))}+ </nav>+ <div className="min-h-0 min-w-0 flex-1 overflow-auto">+ {selectedFile ? (+ <section+ aria-label={`Changes to ${selectedFile.path}`}+ className="flex flex-col gap-3"+ >+ <h3 className="text-sm font-bold break-words">+ {selectedFile.path} Ā· {selectedFile.status}+ </h3>+ {selectedFile.status === "Unchanged" ? (+ <p className="text-muted-foreground text-sm">+ This file is unchanged.+ </p>+ ) : (+ <div key={selectedFile.path}>{children}</div>+ )}+ </section>+ ) : null}+ </div>+ </div>+ </>+ );+}diff --git a/web/src/features/skills/components/SkillFileDiff.tsx b/web/src/features/skills/components/SkillFileDiff.tsxnew file mode 100644index 0000000000..c079775619--- /dev/null+++ b/web/src/features/skills/components/SkillFileDiff.tsx@@ -0,0 +1,83 @@+import DiffViewer from "@/src/components/DiffViewer";+import { api } from "@/src/utils/api";+import { SkillComparisonError } from "./SkillComparisonError";++type FileContent = { content: string } | { sha256Hash: string } | null;++export function SkillFileDiff({+ projectId,+ oldFile,+ newFile,+ oldLabel,+ newLabel,+}: {+ projectId: string;+ oldFile: FileContent;+ newFile: FileContent;+ oldLabel: string;+ newLabel: string;+}) {+ const oldHash =+ oldFile && "sha256Hash" in oldFile ? oldFile.sha256Hash : null;+ const newHash =+ newFile && "sha256Hash" in newFile ? newFile.sha256Hash : null;+ const oldContent = api.skills.fileContents.useQuery(+ { projectId, sha256Hashes: oldHash ? [oldHash] : [] },+ {+ enabled: Boolean(oldHash),+ staleTime: Infinity,+ meta: { silentAllErrors: true },+ },+ );+ const newContent = api.skills.fileContents.useQuery(+ { projectId, sha256Hashes: newHash ? [newHash] : [] },+ {+ enabled: Boolean(newHash),+ staleTime: Infinity,+ meta: { silentAllErrors: true },+ },+ );+ const retry = () => {+ if (oldHash) oldContent.refetch();+ if (newHash) newContent.refetch();+ };+ if ((oldHash && oldContent.isError) || (newHash && newContent.isError)) {+ return <SkillComparisonError retry={retry} />;+ }+ if ((oldHash && oldContent.isPending) || (newHash && newContent.isPending)) {+ return (+ <p role="status" className="text-muted-foreground text-sm">+ Loading file contentsā¦+ </p>+ );+ }+ const oldString = getContent(oldFile, oldContent.data?.data);+ const newString = getContent(newFile, newContent.data?.data);+ if (oldString === undefined || newString === undefined) {+ return <SkillComparisonError retry={retry} />;+ }+ if (!oldString && !newString && (!oldFile || !newFile)) {+ return (+ <p className="text-muted-foreground text-sm">+ An empty file was {oldFile ? "removed" : "added"}.+ </p>+ );+ }+ return (+ <DiffViewer+ oldString={oldString}+ newString={newString}+ oldLabel={`${oldLabel}${oldFile ? "" : " Ā· File absent"}`}+ newLabel={`${newLabel}${newFile ? "" : " Ā· File absent"}`}+ />+ );+}++function getContent(+ file: FileContent,+ loaded: { sha256Hash: string; content: string }[] | undefined,+) {+ if (!file) return "";+ if ("content" in file) return file.content;+ return loaded?.find((item) => item.sha256Hash === file.sha256Hash)?.content;+}diff --git a/web/src/features/skills/components/SkillVersionComparison.tsx b/web/src/features/skills/components/SkillVersionComparison.tsxnew file mode 100644index 0000000000..322a5aeb25--- /dev/null+++ b/web/src/features/skills/components/SkillVersionComparison.tsx@@ -0,0 +1,209 @@+import { type ReactNode, useState } from "react";+import { Button } from "@/src/components/design-system/Button/Button";+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";+import { SelectInput } from "@/src/components/design-system/SelectInput/SelectInput";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";+import { compareSkillFiles } from "@/src/features/skills/utils/compareSkillFiles";+import { SkillFileChanges } from "./SkillFileChanges";+import { SkillFileDiff } from "./SkillFileDiff";+import { SkillComparisonError } from "./SkillComparisonError";+import { api } from "@/src/utils/api";++type ComparisonProps = {+ projectId: string;+ name: string;+ selectedVersion: number;+ versions: { version: number }[];+ hasMore: boolean;+ isLoadingMore: boolean;+ loadMoreError: boolean;+ onLoadMore: () => void;+};++export function SkillVersionComparisonController({+ children,+ ...props+}: ComparisonProps & {+ children: (control: {+ openComparison: (version: number) => void;+ }) => ReactNode;+}) {+ const capture = usePostHogClientCapture();++ return (+ <DialogController<{ before: number; after: number }>+ renderDialog={({ state }) => (+ <SkillVersionComparison {...props} initialVersions={state} />+ )}+ >+ {({ openDialog }) =>+ children({+ openComparison: (version) => {+ if (version === props.selectedVersion) return;+ const before = version;+ const after = props.selectedVersion;+ capture("skills:version_compare", {+ beforeVersion: before,+ afterVersion: after,+ });+ openDialog({ before, after });+ },+ })+ }+ </DialogController>+ );+}++function SkillVersionComparison({+ initialVersions,+ ...props+}: ComparisonProps & { initialVersions: { before: number; after: number } }) {+ const [before, setBefore] = useState(initialVersions.before);+ const [after, setAfter] = useState(initialVersions.after);+ const options = [+ ...new Set([+ props.selectedVersion,+ ...props.versions.map(({ version }) => version),+ ]),+ ]+ .sort((a, b) => b - a)+ .map((version) => ({+ value: String(version),+ label: `Version ${version}`,+ }));++ function handleBeforeChange(value: string) {+ setBefore(Number(value));+ }+ function handleAfterChange(value: string) {+ setAfter(Number(value));+ }++ return (+ <Dialog title="Compare skill versions" size="xxl">+ <div className="ph-no-capture flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4">+ <p className="text-muted-foreground text-sm">+ Compare saved file contents. Unsaved draft changes are not included.+ </p>+ <div className="grid shrink-0 grid-cols-2 gap-4">+ <div className="flex min-w-0 flex-col gap-1">+ <span className="text-sm font-bold">From</span>+ <SelectInput+ aria-label="From version"+ value={String(before)}+ options={options}+ placeholder="Select version"+ onValueChange={handleBeforeChange}+ />+ </div>+ <div className="flex min-w-0 flex-col gap-1">+ <span className="text-sm font-bold">To</span>+ <SelectInput+ aria-label="To version"+ value={String(after)}+ options={options}+ placeholder="Select version"+ onValueChange={handleAfterChange}+ />+ </div>+ </div>+ {props.hasMore ? (+ <div className="flex flex-col items-start gap-2">+ {props.loadMoreError ? (+ <p role="alert">+ Could not load older versions. Please try again.+ </p>+ ) : null}+ <Button+ text="Load older versions"+ variant="secondary"+ size="sm"+ loading={props.isLoadingMore}+ onClick={props.onLoadMore}+ />+ </div>+ ) : null}+ {before === after ? (+ <p role="status" className="text-muted-foreground text-sm">+ Select two different versions to compare.+ </p>+ ) : (+ <SkillVersionFiles+ key={`${before}:${after}`}+ projectId={props.projectId}+ name={props.name}+ before={before}+ after={after}+ />+ )}+ </div>+ </Dialog>+ );+}++function SkillVersionFiles({+ projectId,+ name,+ before,+ after,+}: {+ projectId: string;+ name: string;+ before: number;+ after: number;+}) {+ const [selectedPath, setSelectedPath] = useState<string>();+ const oldVersion = api.skills.byName.useQuery(+ { projectId, name, version: before },+ { refetchOnWindowFocus: false, meta: { silentAllErrors: true } },+ );+ const newVersion = api.skills.byName.useQuery(+ { projectId, name, version: after },+ { refetchOnWindowFocus: false, meta: { silentAllErrors: true } },+ );++ function retryVersions() {+ oldVersion.refetch();+ newVersion.refetch();+ }+ if (oldVersion.isError || newVersion.isError) {+ return <SkillComparisonError retry={retryVersions} />;+ }+ if (!oldVersion.data || !newVersion.data) {+ return (+ <p role="status" className="text-muted-foreground text-sm">+ Loading versionsā¦+ </p>+ );+ }+ const files = compareSkillFiles(oldVersion.data.files, newVersion.data.files);+ const selectedFile =+ files.find((file) => file.path === selectedPath) ?? files[0];+ return (+ <SkillFileChanges+ files={files}+ emptyMessage="No file changes between these versions."+ selectedFile={selectedFile}+ onSelectFile={setSelectedPath}+ >+ {selectedFile ? (+ <SkillFileDiff+ projectId={projectId}+ oldFile={+ selectedFile.oldFile?.sha256Hash+ ? { sha256Hash: selectedFile.oldFile.sha256Hash }+ : null+ }+ newFile={+ selectedFile.newFile?.sha256Hash+ ? { sha256Hash: selectedFile.newFile.sha256Hash }+ : null+ }+ oldLabel={`Version ${before}`}+ newLabel={`Version ${after}`}+ />+ ) : null}+ </SkillFileChanges>+ );+}diff --git a/web/src/features/skills/components/SkillVersionHistory.tsx b/web/src/features/skills/components/SkillVersionHistory.tsxindex 415120ebd4..2585ca91f6 100644--- a/web/src/features/skills/components/SkillVersionHistory.tsx+++ b/web/src/features/skills/components/SkillVersionHistory.tsx@@ -1,5 +1,6 @@-import { useState } from "react";-import { PanelLeftClose, PanelLeftOpen } from "lucide-react";+import { type MouseEvent, useState } from "react";+import { FileDiffIcon, PanelLeftClose, PanelLeftOpen } from "lucide-react";+import { IconButton } from "@/src/components/design-system/IconButton/IconButton";import { Badge } from "@/src/components/ui/badge";import { Button } from "@/src/components/ui/button";import {@@ -8,12 +9,15 @@ import {} from "@/src/features/prompts/components/timeline";import { cn } from "@/src/utils/tailwind";import { SkillLabelsSelect } from "./SkillMetadataSelect";+import { SkillVersionComparisonController } from "./SkillVersionComparison";export function SkillVersionHistory(props:| { kind: "new" }| {kind: "versions";+ projectId: string;+ name: string;versions: Array<{version: number;labels: string[];@@ -161,31 +165,61 @@ export function SkillVersionHistory(}/></div>- <button- type="button"- className="flex w-full flex-col gap-1 text-left"- aria-current={- !props.isDraft && version === props.selectedVersion- ? "page"- : undefined- }- onClick={() => selectVersion(version)}- >- {commitMessage ? (+ <div className="flex items-start gap-1">+ <button+ type="button"+ className="flex min-w-0 flex-1 flex-col gap-1 text-left"+ aria-current={+ !props.isDraft && version === props.selectedVersion+ ? "page"+ : undefined+ }+ onClick={() => selectVersion(version)}+ >+ {commitMessage ? (+ <span+ className="text-muted-foreground max-w-full truncate text-xs"+ title={commitMessage}+ >+ {commitMessage}+ </span>+ ) : null}<span- className="text-muted-foreground max-w-full truncate text-xs"- title={commitMessage}+ className="text-muted-foreground flex flex-wrap gap-1 text-xs break-words"+ title={`Created ${createdAt.toLocaleString()}`}>- {commitMessage}+ {createdAt.toLocaleString()} by{" "}+ {creator || createdBy}</span>+ </button>+ {version !== props.selectedVersion ? (+ <SkillVersionComparisonController+ {...props}+ versions={sortedVersions}+ >+ {({ openComparison }) => {+ function handleCompareClick(+ event: MouseEvent<HTMLButtonElement>,+ ) {+ event.stopPropagation();+ openComparison(version);+ }+ return (+ <div className="shrink-0 group-focus-within/skill-version:opacity-100 group-hover/skill-version:opacity-100 [@media(hover:hover)]:opacity-0">+ <IconButton+ icon={FileDiffIcon}+ label={`Compare version ${version} with selected version ${props.selectedVersion}`}+ title="Compare with selected version"+ variant="outline"+ size="sm"+ onClick={handleCompareClick}+ />+ </div>+ );+ }}+ </SkillVersionComparisonController>) : null}- <span- className="text-muted-foreground flex flex-wrap gap-1 text-xs break-words"- title={`Created ${createdAt.toLocaleString()}`}- >- {createdAt.toLocaleString()} by {creator || createdBy}- </span>- </button>+ </div></TimelineItem>),)diff --git a/web/src/features/skills/utils/compareSkillFiles.ts b/web/src/features/skills/utils/compareSkillFiles.tsnew file mode 100644index 0000000000..7421350e13--- /dev/null+++ b/web/src/features/skills/utils/compareSkillFiles.ts@@ -0,0 +1,31 @@+type FileReference = { path: string; sha256Hash: string | null };++export function compareSkillFiles(+ before: FileReference[],+ after: FileReference[],+) {+ const oldFiles = new Map(before.map((file) => [file.path, file]));+ const newFiles = new Map(after.map((file) => [file.path, file]));+ return [...new Set([...oldFiles.keys(), ...newFiles.keys()])]+ .map((path) => {+ const oldFile = oldFiles.get(path);+ const newFile = newFiles.get(path);+ let status: "Added" | "Removed" | "Modified" | "Unchanged" = "Modified";+ if (!oldFile) status = "Added";+ else if (!newFile) status = "Removed";+ else if (+ oldFile.sha256Hash !== null &&+ oldFile.sha256Hash === newFile.sha256Hash+ )+ status = "Unchanged";+ return { path, oldFile, newFile, status };+ })+ .sort((a, b) => {+ const unchanged =+ Number(a.status === "Unchanged") - Number(b.status === "Unchanged");+ if (unchanged) return unchanged;+ if (a.path === "SKILL.md") return -1;+ if (b.path === "SKILL.md") return 1;+ return a.path.localeCompare(b.path);+ });+}