Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(skills): link imported skills to their source (#6928)
Guillaumeddd04a73fd50
diff --git a/packages/views/navigation/index.ts b/packages/views/navigation/index.tsindex 9d6e0dc083..3bc4025c7c 100644--- a/packages/views/navigation/index.ts+++ b/packages/views/navigation/index.ts@@ -8,7 +8,7 @@ export { AppLink } from "./app-link";export { resolveClickIntent } from "./click-intent";export type { LinkClickIntent } from "./click-intent";export { useAppOrigin } from "./use-app-origin";-export { useRowLink } from "./use-row-link";+export { useRowLink, rowLinkInteractiveProps } from "./use-row-link";export { useIntentNavigate } from "./use-intent-navigate";export { useBackOrReplace } from "./use-back-or-replace";export type { NavigationAdapter } from "./types";diff --git a/packages/views/navigation/use-row-link.test.tsx b/packages/views/navigation/use-row-link.test.tsxindex 0d6591e654..7e0ce7d743 100644--- a/packages/views/navigation/use-row-link.test.tsx+++ b/packages/views/navigation/use-row-link.test.tsx@@ -1,7 +1,7 @@import { afterEach, describe, expect, it, vi } from "vitest";import { fireEvent, render, screen } from "@testing-library/react";import { NavigationProvider } from "./context";-import { useRowLink } from "./use-row-link";+import { rowLinkInteractiveProps, useRowLink } from "./use-row-link";import type { NavigationAdapter } from "./types";function makeAdapter(@@ -175,4 +175,50 @@ describe("useRowLink", () => {);expect(push).not.toHaveBeenCalled();});++ // Nested interactive elements must stop auxclick too, not just click: the+ // row's auxclick handler calls preventDefault(), which would cancel a+ // nested anchor's native middle-click open and background-tab the row+ // instead of the link's destination.+ it("rowLinkInteractiveProps shields a nested anchor from the row's handlers", () => {+ const push = vi.fn();+ const openInNewTab = vi.fn();+ const adapter = makeAdapter({ push, openInNewTab });++ function NestedProbe() {+ const rowLink = useRowLink();+ return (+ <div role="row" {...rowLink("/acme/projects/p1")}>+ <a+ href="https://example.com"+ target="_blank"+ rel="noopener noreferrer"+ {...rowLinkInteractiveProps}+ >+ source+ </a>+ </div>+ );+ }+ render(+ <NavigationProvider value={adapter}>+ <NestedProbe />+ </NavigationProvider>,+ );++ const anchor = screen.getByRole("link");+ fireEvent.click(anchor);+ const aux = new MouseEvent("auxclick", {+ bubbles: true,+ button: 1,+ cancelable: true,+ });+ anchor.dispatchEvent(aux);++ // Neither event reached the row, and the anchor's native behaviour+ // survives (no preventDefault from the row's middle-click handler).+ expect(aux.defaultPrevented).toBe(false);+ expect(push).not.toHaveBeenCalled();+ expect(openInNewTab).not.toHaveBeenCalled();+ });});diff --git a/packages/views/navigation/use-row-link.ts b/packages/views/navigation/use-row-link.tsindex 0c6381fcd4..e38f6a2745 100644--- a/packages/views/navigation/use-row-link.ts+++ b/packages/views/navigation/use-row-link.ts@@ -15,7 +15,9 @@ import { useNavigation } from "./context";* The whole row navigates on click — the row is the click target, so the* name cell stays plain text (no nested `<a>`, which would be a redundant* second entry point). Interactive cells (checkbox, kebab, inline editors)- * call `stopPropagation` so clicking them never reaches these handlers.+ * must stop propagation so interacting with them never reaches these+ * handlers — spread `rowLinkInteractiveProps` on them rather than wiring+ * `onClick` alone, because the row handles `auxclick` too.** Mirrors AppLink's modifier semantics via `resolveClickIntent`: a plain left* click pushes; cmd/ctrl (or a middle click) opens a background tab on@@ -32,6 +34,21 @@ import { useNavigation } from "./context";* Callers add `cursor-pointer` to the row's own className (kept out of the* returned props so it can't clash with the row's existing className).*/+/**+ * Props for interactive elements nested inside a `useRowLink` row.+ *+ * Stops BOTH `click` and `auxclick` from bubbling to the row. Stopping only+ * `click` is a trap: a middle click bubbles as `auxclick`, the row handler+ * calls `preventDefault()`, and for a nested `<a>` that cancels the anchor's+ * native middle-click open — so the row opens in a background tab instead of+ * the link's own destination. Native behaviour on the element itself is+ * untouched (no `preventDefault` here), so anchors keep their default open.+ */+export const rowLinkInteractiveProps = {+ onClick: (e: React.MouseEvent) => e.stopPropagation(),+ onAuxClick: (e: React.MouseEvent) => e.stopPropagation(),+};+export function useRowLink() {const { push, openInNewTab, prefetch, getShareableUrl } = useNavigation();diff --git a/packages/views/skills/components/refresh-skill-dialog.test.tsx b/packages/views/skills/components/refresh-skill-dialog.test.tsxnew file mode 100644index 0000000000..1f51f1801d--- /dev/null+++ b/packages/views/skills/components/refresh-skill-dialog.test.tsx@@ -0,0 +1,95 @@+// @vitest-environment jsdom++import { describe, it, expect, vi, beforeEach } from "vitest";+import { render, screen } from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import type { SkillSummary } from "@multica/core/types";+import { I18nProvider } from "@multica/core/i18n/react";+import enCommon from "../../locales/en/common.json";+import enSkills from "../../locales/en/skills.json";+import type { OriginInfo } from "../lib/origin";++const TEST_RESOURCES = { en: { common: enCommon, skills: enSkills } };++vi.mock("@multica/core/api", () => ({+ api: { refreshSkill: vi.fn() },+}));+vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn() } }));++import { RefreshSkillDialog } from "./refresh-skill-dialog";++const skill: SkillSummary = {+ id: "skill-1",+ workspace_id: "ws-1",+ name: "animations",+ description: "",+ config: {},+ created_by: "user-1",+ created_at: "2026-07-28T18:11:37Z",+ updated_at: "2026-07-28T18:14:40Z",+};++function renderDialog(origin: OriginInfo | null) {+ const queryClient = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ render(+ <I18nProvider locale="en" resources={TEST_RESOURCES}>+ <QueryClientProvider client={queryClient}>+ <RefreshSkillDialog+ skill={skill}+ origin={origin}+ wsId="ws-1"+ open+ onOpenChange={() => {}}+ />+ </QueryClientProvider>+ </I18nProvider>,+ );+}++beforeEach(() => {+ vi.clearAllMocks();+});++describe("RefreshSkillDialog source URL", () => {+ const SOURCE_URL = "https://github.com/anthropics/skills/tree/main/animations";++ it("shows the source URL as an external link", async () => {+ renderDialog({ type: "github", source_url: SOURCE_URL });+ const link = (await screen.findByRole("link")) as HTMLAnchorElement;+ expect(link.getAttribute("href")).toBe(SOURCE_URL);+ expect(link.getAttribute("target")).toBe("_blank");+ expect(link.getAttribute("rel")).toContain("noopener");+ });++ it("middle-truncates a long source URL but links the full one", async () => {+ const longUrl =+ "https://github.com/anthropics/a-very-long-repository-name/tree/main/deeply/nested/skill-directory";+ renderDialog({ type: "github", source_url: longUrl });+ const link = (await screen.findByRole("link")) as HTMLAnchorElement;+ expect(link.getAttribute("href")).toBe(longUrl);+ expect(link.textContent).toContain("…");+ expect((link.textContent ?? "").length).toBeLessThanOrEqual(60);+ });++ it("renders no link when the origin has no source_url", () => {+ renderDialog({ type: "manual" });+ expect(screen.queryByRole("link")).toBeNull();+ });++ // config.origin is persisted verbatim through the skill update API, so an+ // injected source_url must never surface as a live anchor in the dialog.+ it("renders no link when a non-import origin carries an injected source_url", () => {+ renderDialog({ type: "manual", source_url: SOURCE_URL });+ expect(screen.queryByRole("link")).toBeNull();+ });++ it("renders no link when the source_url host does not match the origin type", () => {+ renderDialog({+ type: "github",+ source_url: "https://evil.example/anthropics/skills",+ });+ expect(screen.queryByRole("link")).toBeNull();+ });+});diff --git a/packages/views/skills/components/refresh-skill-dialog.tsx b/packages/views/skills/components/refresh-skill-dialog.tsxindex 6defbc5fc8..0d5590a80f 100644--- a/packages/views/skills/components/refresh-skill-dialog.tsx+++ b/packages/views/skills/components/refresh-skill-dialog.tsx@@ -19,8 +19,14 @@ import {DialogHeader,DialogTitle,} from "@multica/ui/components/ui/dialog";+import {+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from "@multica/ui/components/ui/tooltip";+import { midTruncate } from "../../common/github-url";import { useT } from "../../i18n";-import type { OriginInfo } from "../lib/origin";+import { originSourceUrl, type OriginInfo } from "../lib/origin";/** Human name of the hosted source a refresh re-downloads from. */export function useRefreshSourceLabel(origin: OriginInfo | null): string {@@ -56,6 +62,9 @@ export function RefreshSkillDialog({const qc = useQueryClient();const [refreshing, setRefreshing] = useState(false);const source = useRefreshSourceLabel(origin);+ // Only a validated URL becomes a link; an injected or mismatched+ // source_url renders nothing rather than a live anchor in a confirm dialog.+ const sourceUrl = originSourceUrl(origin);const handleConfirm = async () => {setRefreshing(true);@@ -103,6 +112,23 @@ export function RefreshSkillDialog({})}</DialogDescription></DialogHeader>+ {sourceUrl && (+ <Tooltip>+ <TooltipTrigger+ render={+ <a+ href={sourceUrl}+ target="_blank"+ rel="noopener noreferrer"+ className="w-fit max-w-full truncate text-caption text-muted-foreground hover:underline"+ >+ {midTruncate(sourceUrl, 60)}+ </a>+ }+ />+ <TooltipContent side="top">{sourceUrl}</TooltipContent>+ </Tooltip>+ )}<div className="rounded-md bg-warning/10 px-3 py-2 text-caption text-muted-foreground">{t(($) => $.detail.refresh.dialog.warning)}</div>diff --git a/packages/views/skills/components/skill-detail-page.test.tsx b/packages/views/skills/components/skill-detail-page.test.tsxindex f96a51a452..92dc7dce9d 100644--- a/packages/views/skills/components/skill-detail-page.test.tsx+++ b/packages/views/skills/components/skill-detail-page.test.tsx@@ -425,3 +425,55 @@ describe("SkillDetailPage draft baseline (MUL-5645)", () => {).toBe("my unsaved edit");});});++describe("SkillDetailPage origin link", () => {+ const SOURCE_URL = "https://github.com/anthropics/skills/tree/main/animations";++ it("links the imported-origin chip to its source", async () => {+ skillRef.current = {+ ...baseSkill,+ config: { origin: { type: "github", source_url: SOURCE_URL } },+ };+ renderPage();+ const link = (await screen.findByRole("link", {+ name: "Imported · GitHub",+ })) as HTMLAnchorElement;+ expect(link.getAttribute("href")).toBe(SOURCE_URL);+ expect(link.getAttribute("target")).toBe("_blank");+ expect(link.getAttribute("rel")).toContain("noopener");+ });++ it("keeps manual origins as plain text", async () => {+ renderPage();+ expect(await screen.findByText("Created manually")).toBeTruthy();+ expect(+ screen.queryByRole("link", { name: "Created manually" }),+ ).toBeNull();+ });++ it("does not link an imported origin whose source_url is missing", async () => {+ skillRef.current = {+ ...baseSkill,+ config: { origin: { type: "github" } },+ };+ renderPage();+ expect(await screen.findByText("Imported · GitHub")).toBeTruthy();+ expect(+ screen.queryByRole("link", { name: "Imported · GitHub" }),+ ).toBeNull();+ });++ it("does not link a source_url whose host does not match the origin type", async () => {+ skillRef.current = {+ ...baseSkill,+ config: {+ origin: { type: "github", source_url: "https://evil.example/skills" },+ },+ };+ renderPage();+ expect(await screen.findByText("Imported · GitHub")).toBeTruthy();+ expect(+ screen.queryByRole("link", { name: "Imported · GitHub" }),+ ).toBeNull();+ });+});diff --git a/packages/views/skills/components/skill-detail-page.tsx b/packages/views/skills/components/skill-detail-page.tsxindex ff57162d52..73d943bdbe 100644--- a/packages/views/skills/components/skill-detail-page.tsx+++ b/packages/views/skills/components/skill-detail-page.tsx@@ -72,6 +72,7 @@ import { useSkillPermissions } from "@multica/core/permissions";import { CapabilityBanner } from "@multica/ui/components/common/capability-banner";import {isRefreshableOrigin,+ originSourceUrl,readOrigin,totalFileCount,type OriginInfo,@@ -307,6 +308,7 @@ function SkillIdentity({const timeAgo = useTimeAgo();const originLabel = useOriginLabel(origin, originRuntime);const isRuntimeOrigin = origin?.type === "runtime_local";+ const sourceUrl = originSourceUrl(origin);return (<div className="shrink-0 border-b px-4 py-3 sm:px-6">@@ -332,7 +334,25 @@ function SkillIdentity({) : (<Download className="h-3.5 w-3.5 shrink-0" aria-hidden="true" />)}- <span className="truncate">{originLabel}</span>+ {sourceUrl ? (+ <Tooltip>+ <TooltipTrigger+ render={+ <a+ href={sourceUrl}+ target="_blank"+ rel="noopener noreferrer"+ className="truncate hover:underline"+ >+ {originLabel}+ </a>+ }+ />+ <TooltipContent side="top">{sourceUrl}</TooltipContent>+ </Tooltip>+ ) : (+ <span className="truncate">{originLabel}</span>+ )}</span>)}<span className="inline-flex items-center gap-1.5">diff --git a/packages/views/skills/components/skills-page.source-link.test.tsx b/packages/views/skills/components/skills-page.source-link.test.tsxnew file mode 100644index 0000000000..9628427066--- /dev/null+++ b/packages/views/skills/components/skills-page.source-link.test.tsx@@ -0,0 +1,218 @@+// @vitest-environment jsdom++import React from "react";+import { beforeEach, describe, expect, it, vi } from "vitest";+import { fireEvent, screen } from "@testing-library/react";+import type { SkillSummary } from "@multica/core/types";+import { renderWithI18n } from "../../test/i18n";+import { NavigationProvider, type NavigationAdapter } from "../../navigation";++// Regression rig for the Source cell's anchor living inside a `useRowLink`+// row: the row handles BOTH click and auxclick, so the anchor must stop both+// from bubbling. Stopping only click let a middle click reach the row, whose+// preventDefault() cancelled the anchor's native open — the skill detail page+// opened in a background tab instead of the source page.++const mocks = vi.hoisted(() => ({+ skills: [] as SkillSummary[],+ viewState: {+ sortField: "name",+ sortDirection: "asc" as string,+ hiddenColumns: [] as string[],+ filters: {+ usage: [] as string[],+ origins: [] as string[],+ agents: [] as string[],+ creators: [] as string[],+ },+ toggleSort: vi.fn(),+ setSortField: vi.fn(),+ setSortDirection: vi.fn(),+ toggleColumn: vi.fn(),+ toggleFilter: vi.fn(),+ clearFilters: vi.fn(),+ },+}));++vi.mock("@tanstack/react-query", () => ({+ useQuery: (options: { queryKey?: readonly unknown[] }) => {+ if (options.queryKey?.[0] === "skills") {+ return {+ data: mocks.skills,+ isLoading: false,+ error: null,+ refetch: vi.fn(),+ };+ }+ return { data: [], isLoading: false, error: null, refetch: vi.fn() };+ },+}));++// Render every row so the anchor under test is always mounted.+vi.mock("@tanstack/react-virtual", () => ({+ useVirtualizer: ({ count }: { count: number }) => ({+ getVirtualItems: () =>+ Array.from({ length: count }, (_, index) => ({+ index,+ key: index,+ start: index * 48,+ end: (index + 1) * 48,+ size: 48,+ })),+ getTotalSize: () => count * 48,+ }),+}));++vi.mock("@multica/core/auth", () => ({+ useAuthStore: (selector: (state: unknown) => unknown) =>+ selector({ user: { id: "user-1" } }),+}));++vi.mock("@multica/core/hooks", () => ({+ useWorkspaceId: () => "ws-1",+}));++// Partial mock: SkillIcon resolves its icon from the real WORKSPACE_PAGES.+vi.mock("@multica/core/paths", async (importOriginal) => ({+ ...(await importOriginal<typeof import("@multica/core/paths")>()),+ useWorkspacePaths: () => ({+ skillDetail: (id: string) => `/acme/skills/${id}`,+ }),+}));++vi.mock("@multica/core/workspace/queries", () => ({+ skillListOptions: () => ({ queryKey: ["skills"] }),+ agentListOptions: () => ({ queryKey: ["agents"] }),+ memberListOptions: () => ({ queryKey: ["members"] }),+ selectSkillAssignments: () => new Map(),+}));++vi.mock("@multica/core/runtimes", () => ({+ runtimeListOptions: () => ({ queryKey: ["runtimes"] }),+ runtimeDisplayLabel: () => "runtime",+}));++vi.mock("@multica/core/workspace/avatar-url", () => ({+ resolvePublicFileUrl: (u: string | null) => u,+}));++vi.mock("@multica/core/skills/stores", () => ({+ useSkillsViewStore: (selector: (state: unknown) => unknown) =>+ selector(mocks.viewState),+ DEFAULT_HIDDEN_COLUMNS: [],+}));++// View-layer children with heavy / portal deps — stubbed to keep the test on+// the row/anchor event wiring.+vi.mock("@multica/ui/components/common/actor-avatar", () => ({+ ActorAvatar: () => null,+}));+vi.mock("@multica/ui/components/ui/tooltip", () => ({+ Tooltip: ({ children }: { children: React.ReactNode }) => <>{children}</>,+ TooltipTrigger: ({ render }: { render: React.ReactNode }) => <>{render}</>,+ TooltipContent: () => null,+}));+vi.mock("./create-skill-dialog", () => ({ CreateSkillDialog: () => null }));+vi.mock("./skill-list-toolbar", () => ({ SkillListToolbar: () => null }));+vi.mock("./skill-list-actions", () => ({+ SkillBatchToolbar: () => null,+ SkillRowActions: () => null,+}));++import SkillsPage from "./skills-page";++const SOURCE_URL = "https://github.com/anthropics/skills/tree/main/animations";++const importedSkill: SkillSummary = {+ id: "skill-1",+ workspace_id: "ws-1",+ name: "animations",+ description: "",+ config: { origin: { type: "github", source_url: SOURCE_URL } },+ created_by: "user-1",+ created_at: "2026-07-28T18:11:37Z",+ updated_at: "2026-07-28T18:14:40Z",+};++function makeAdapter(+ overrides: Partial<NavigationAdapter> = {},+): NavigationAdapter {+ return {+ push: vi.fn(),+ replace: vi.fn(),+ back: vi.fn(),+ pathname: "/acme/skills",+ searchParams: new URLSearchParams(),+ getShareableUrl: (p) => p,+ openInNewTab: vi.fn(),+ ...overrides,+ };+}++function renderPage(adapter: NavigationAdapter) {+ renderWithI18n(+ <NavigationProvider value={adapter}>+ <SkillsPage />+ </NavigationProvider>,+ );+}++function middleClick(target: Element): MouseEvent {+ const event = new MouseEvent("auxclick", {+ bubbles: true,+ button: 1,+ cancelable: true,+ });+ target.dispatchEvent(event);+ return event;+}++beforeEach(() => {+ vi.clearAllMocks();+ mocks.skills = [importedSkill];+});++describe("SkillsPage source link vs row navigation", () => {+ it("middle click on the source link keeps its native open (row must not hijack)", async () => {+ const adapter = makeAdapter();+ renderPage(adapter);++ const link = await screen.findByRole("link", { name: "From GitHub" });+ expect(link.getAttribute("href")).toBe(SOURCE_URL);++ const event = middleClick(link);++ // The anchor's native middle-click open must survive: the row's auxclick+ // handler (which calls preventDefault) must never see the event.+ expect(event.defaultPrevented).toBe(false);+ expect(adapter.openInNewTab).not.toHaveBeenCalled();+ expect(adapter.push).not.toHaveBeenCalled();+ });++ it("left click on the source link does not trigger row navigation", async () => {+ const adapter = makeAdapter();+ renderPage(adapter);++ fireEvent.click(+ await screen.findByRole("link", { name: "From GitHub" }),+ );++ expect(adapter.push).not.toHaveBeenCalled();+ expect(adapter.openInNewTab).not.toHaveBeenCalled();+ });++ // Sanity check that the rig exercises the row's auxclick handler at all —+ // without this, the assertions above could pass vacuously.+ it("middle click elsewhere on the row still background-tabs the skill", async () => {+ const adapter = makeAdapter();+ renderPage(adapter);++ const event = middleClick(await screen.findByText("animations"));++ expect(event.defaultPrevented).toBe(true);+ expect(adapter.openInNewTab).toHaveBeenCalledWith(+ "/acme/skills/skill-1",+ "animations",+ );+ });+});diff --git a/packages/views/skills/components/skills-page.tsx b/packages/views/skills/components/skills-page.tsxindex ccbdc577d1..487ec9c9ab 100644--- a/packages/views/skills/components/skills-page.tsx+++ b/packages/views/skills/components/skills-page.tsx@@ -50,14 +50,18 @@ import {TooltipTrigger,} from "@multica/ui/components/ui/tooltip";import { ActorAvatar } from "@multica/ui/components/common/actor-avatar";-import { useNavigation, useRowLink } from "../../navigation";+import {+ rowLinkInteractiveProps,+ useNavigation,+ useRowLink,+} from "../../navigation";import {CollectionPageHeader,CollectionPageHeaderAction,CollectionPageState,} from "../../layout/collection-page";import { canEditSkill } from "../hooks/use-can-edit-skill";-import { readOrigin, type OriginInfo } from "../lib/origin";+import { originSourceUrl, readOrigin, type OriginInfo } from "../lib/origin";import { CreateSkillDialog } from "./create-skill-dialog";import {useSkillsViewStore,@@ -348,10 +352,33 @@ function SourceCell({label = t(($) => $.table.source_github);}+ // Imported skills link to their upstream page; the anchor must not bubble+ // its click OR auxclick into the row's whole-row navigation.+ const sourceUrl = originSourceUrl(origin);+return (<ListGridCell className="hidden gap-1.5 text-caption text-muted-foreground @2xl:flex">{icon}- <span className="min-w-0 truncate">{label}</span>+ {sourceUrl ? (+ <Tooltip>+ <TooltipTrigger+ render={+ <a+ href={sourceUrl}+ target="_blank"+ rel="noopener noreferrer"+ {...rowLinkInteractiveProps}+ className="min-w-0 truncate hover:underline"+ >+ {label}+ </a>+ }+ />+ <TooltipContent side="top">{sourceUrl}</TooltipContent>+ </Tooltip>+ ) : (+ <span className="min-w-0 truncate">{label}</span>+ )}</ListGridCell>);}diff --git a/packages/views/skills/lib/origin.test.ts b/packages/views/skills/lib/origin.test.tsnew file mode 100644index 0000000000..57a1f81019--- /dev/null+++ b/packages/views/skills/lib/origin.test.ts@@ -0,0 +1,71 @@+import { describe, expect, it } from "vitest";+import { originSourceUrl, type OriginInfo } from "./origin";++// `origin` is persisted JSONB writable verbatim through the skill update API,+// so originSourceUrl is the only thing standing between a hand-edited+// source_url and a live href. These tests pin the fail-closed behaviour.+describe("originSourceUrl", () => {+ const github = (source_url?: string): OriginInfo => ({+ type: "github",+ source_url,+ });++ it("accepts a source_url on the declared origin's own host", () => {+ const url = "https://github.com/anthropics/skills/tree/main/animations";+ expect(originSourceUrl(github(url))).toBe(url);+ expect(+ originSourceUrl({ type: "skills_sh", source_url: "https://skills.sh/a/b/c" }),+ ).toBe("https://skills.sh/a/b/c");+ expect(+ originSourceUrl({ type: "clawhub", source_url: "https://clawhub.ai/owner/slug" }),+ ).toBe("https://clawhub.ai/owner/slug");+ });++ it("accepts http and www variants, matching the server allowlist", () => {+ expect(originSourceUrl(github("http://www.github.com/a/b"))).toBe(+ "http://www.github.com/a/b",+ );+ expect(originSourceUrl(github("https://WWW.GITHUB.COM/a/b"))).toBe(+ "https://WWW.GITHUB.COM/a/b",+ );+ });++ it("rejects a host that does not match the declared origin type", () => {+ expect(originSourceUrl(github("https://evil.example/anthropics/skills"))).toBeNull();+ expect(originSourceUrl(github("https://skills.sh/a/b/c"))).toBeNull();+ expect(+ originSourceUrl({ type: "clawhub", source_url: "https://github.com/a/b" }),+ ).toBeNull();+ // Lookalike hosts must not pass a substring/suffix check.+ expect(originSourceUrl(github("https://github.com.evil.example/a/b"))).toBeNull();+ expect(originSourceUrl(github("https://notgithub.com/a/b"))).toBeNull();+ });++ it("rejects non-http(s) schemes", () => {+ expect(originSourceUrl(github("data:text/html,<script>x</script>"))).toBeNull();+ expect(originSourceUrl(github("javascript:alert(1)"))).toBeNull();+ expect(originSourceUrl(github("ftp://github.com/a/b"))).toBeNull();+ });++ it("rejects malformed and scheme-less values", () => {+ expect(originSourceUrl(github("not a url"))).toBeNull();+ expect(originSourceUrl(github("github.com/a/b"))).toBeNull();+ // A bare ClawHub slug is server-refreshable but not linkable.+ expect(originSourceUrl({ type: "clawhub", source_url: "my-skill" })).toBeNull();+ });++ it("rejects non-import origins even with a well-formed URL", () => {+ expect(+ originSourceUrl({ type: "manual", source_url: "https://github.com/a/b" }),+ ).toBeNull();+ expect(+ originSourceUrl({ type: "runtime_local", source_url: "https://github.com/a/b" }),+ ).toBeNull();+ });++ it("returns null for a missing or empty source_url", () => {+ expect(originSourceUrl(null)).toBeNull();+ expect(originSourceUrl(github(undefined))).toBeNull();+ expect(originSourceUrl(github(""))).toBeNull();+ });+});diff --git a/packages/views/skills/lib/origin.ts b/packages/views/skills/lib/origin.tsindex cbffcbd736..1427fe044c 100644--- a/packages/views/skills/lib/origin.ts+++ b/packages/views/skills/lib/origin.ts@@ -45,6 +45,49 @@ export function isRefreshableOrigin(origin: OriginInfo): boolean {);}+// Hosts each hosted origin type may legitimately point at — the client-side+// mirror of the server's `detectImportSource` allowlist (skill.go). Keyed by+// origin type so a hand-edited config can't dress an arbitrary host up as a+// GitHub / Skills.sh / ClawHub link.+const ORIGIN_SOURCE_HOSTS: Partial<Record<OriginInfo["type"], readonly string[]>> = {+ github: ["github.com", "www.github.com"],+ skills_sh: ["skills.sh", "www.skills.sh"],+ clawhub: ["clawhub.ai", "www.clawhub.ai"],+};++/**+ * The origin's `source_url` validated for use as a link destination, or null.+ *+ * `origin` is persisted JSONB that anyone able to update the skill can write+ * verbatim (`PATCH /api/skills/:id` does not validate `config`), so before a+ * value becomes an `href` it must survive being treated as a destination:+ * http(s) only, and the host must match the declared origin type. Everything+ * else — manual/runtime_local origins, missing or malformed URLs, `data:` and+ * other schemes, host/type mismatches — returns null so callers fall back to+ * plain text.+ *+ * Deliberately stricter than `isRefreshableOrigin`: the server's refresh path+ * re-validates provenance itself and also accepts scheme-less values (e.g. a+ * bare ClawHub slug), which are refreshable but meaningless as an `href`.+ */+export function originSourceUrl(origin: OriginInfo | null): string | null {+ if (!origin) return null;+ const hosts = ORIGIN_SOURCE_HOSTS[origin.type];+ if (!hosts) return null;+ if (typeof origin.source_url !== "string" || origin.source_url.length === 0) {+ return null;+ }+ let parsed: URL;+ try {+ parsed = new URL(origin.source_url);+ } catch {+ return null;+ }+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;+ if (!hosts.includes(parsed.hostname.toLowerCase())) return null;+ return origin.source_url;+}+/*** SKILL.md is always present plus any additional attached files. Accepts a* `SkillSummary` because list endpoints don't return the `files` array — in