Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(agent-vault): open linked files from the skill preview and skills from any cell (#9053)
Saif Ur Rahman84789da7ed79
diff --git a/frontend/src/components/agent-vault/skills/SkillDescription.tsx b/frontend/src/components/agent-vault/skills/SkillDescription.tsxdeleted file mode 100644index 3d07a646e1..0000000000--- a/frontend/src/components/agent-vault/skills/SkillDescription.tsx+++ /dev/null@@ -1,11 +0,0 @@-import { Tooltip, TooltipContent, TooltipTrigger } from "@app/components/v3";--/** A skill's description cut to one line, with the full text on hover. */-export const SkillDescription = ({ description }: { description: string }) => (- <Tooltip>- <TooltipTrigger asChild>- <span className="block truncate text-sm">{description}</span>- </TooltipTrigger>- <TooltipContent className="max-w-md">{description}</TooltipContent>- </Tooltip>-);diff --git a/frontend/src/components/agent-vault/skills/SkillFilesEditor.tsx b/frontend/src/components/agent-vault/skills/SkillFilesEditor.tsxindex dd7c957964..c5c023b565 100644--- a/frontend/src/components/agent-vault/skills/SkillFilesEditor.tsx+++ b/frontend/src/components/agent-vault/skills/SkillFilesEditor.tsx@@ -12,6 +12,7 @@ import {} from "lucide-react";import { twMerge } from "tailwind-merge";+import { createNotification } from "@app/components/notifications";import {Badge,Button,@@ -45,6 +46,7 @@ import {joinSkillPath,newDraftFile,removeSkillPath,+ resolveSkillLinkPath,renameSkillFolders,renameSkillPaths,SKILL_MAX_FILES,@@ -197,6 +199,21 @@ export const SkillFilesEditor = ({const paths = useMemo(() => files.map((file) => file.path), [files]);const folderPaths = useMemo(() => getSkillFolders(paths, emptyFolders), [paths, emptyFolders]);const selected = files.find((file) => file.path === selectedPath) ?? files[0];++ const openLinkedFile = (href: string) => {+ if (href.startsWith("#")) {+ // Footnotes link to an element id in the same preview; a heading link has no id to land on.+ document.getElementById(href.slice(1))?.scrollIntoView({ block: "start" });+ return;+ }+ if (!selected) return;+ const target = resolveSkillLinkPath(selected.path, href);+ if (target && files.some((file) => file.path === target)) {+ onSelect(target);+ return;+ }+ createNotification({ text: `${target ?? href} isn't a file in this skill.`, type: "info" });+ };const isMarkdown = selected ? isMarkdownPath(selected.path) : false;const canPreview = isMarkdown && selected?.text !== null;const showRendered = canPreview && view === "preview";@@ -535,13 +552,13 @@ export const SkillFilesEditor = ({</Empty>)}{rendered && (- <div className="h-full thin-scrollbar overflow-y-auto p-4">+ <div key={selected?.path} className="h-full thin-scrollbar overflow-y-auto p-4">{rendered.frontmatter && (<pre className="mb-4 thin-scrollbar overflow-x-auto rounded-md border border-border bg-container p-3 font-mono text-xs leading-relaxed whitespace-pre-wrap text-label">{rendered.frontmatter}</pre>)}- <Markdown>{rendered.body}</Markdown>+ <Markdown onRelativeLinkClick={openLinkedFile}>{rendered.body}</Markdown></div>)}{/* Stays mounted while hidden, so each file keeps its undo history for as long as the editor is open. */}diff --git a/frontend/src/components/v3/generic/Markdown/Markdown.stories.tsx b/frontend/src/components/v3/generic/Markdown/Markdown.stories.tsxindex 8532242273..d0cabd21d0 100644--- a/frontend/src/components/v3/generic/Markdown/Markdown.stories.tsx+++ b/frontend/src/components/v3/generic/Markdown/Markdown.stories.tsx@@ -1,4 +1,5 @@import type { Meta, StoryObj } from "@storybook/react-vite";+import { expect, fn, userEvent, within } from "storybook/test";import { Markdown } from "./Markdown";@@ -55,3 +56,25 @@ Run these steps **before** tagging a release, and read [the guide](https://examp`}};++export const RelativeLinks: Story = {+ args: {+ children: "Read [the guide](references/guide.md) or [the docs](https://infisical.com/docs).",+ onRelativeLinkClick: fn()+ },+ play: async ({ args, canvasElement }) => {+ const canvas = within(canvasElement);+ const page = canvasElement.ownerDocument.defaultView!.location.href;+ const guide = canvas.getByRole("link", { name: "the guide" });++ await userEvent.click(guide);+ await expect(args.onRelativeLinkClick).toHaveBeenCalledWith("references/guide.md");+ await expect(canvasElement.ownerDocument.defaultView!.location.href).toBe(page);+ await expect(guide).toHaveAttribute("href", "#");++ const docs = canvas.getByRole("link", { name: "the docs" });+ await expect(docs).toHaveAttribute("href", "https://infisical.com/docs");+ await expect(docs).toHaveAttribute("target", "_blank");+ await expect(args.onRelativeLinkClick).toHaveBeenCalledTimes(1);+ }+};diff --git a/frontend/src/components/v3/generic/Markdown/Markdown.test.tsx b/frontend/src/components/v3/generic/Markdown/Markdown.test.tsxindex d444764ddd..cae06bf210 100644--- a/frontend/src/components/v3/generic/Markdown/Markdown.test.tsx+++ b/frontend/src/components/v3/generic/Markdown/Markdown.test.tsx@@ -31,3 +31,21 @@ describe("Markdown GitHub additions", () => {assert.ok(!markup.includes("<script"));});});++describe("Markdown links", () => {+ it("opens every link in a new tab by default", () => {+ const markup = renderToStaticMarkup(<Markdown>[guide](references/guide.md)</Markdown>);+ assert.match(markup, /<a[^>]*target="_blank"[^>]*href="references\/guide.md"/);+ });++ it("keeps relative links in the page when a handler takes them", () => {+ const markup = renderToStaticMarkup(+ <Markdown onRelativeLinkClick={() => {}}>+ [guide](references/guide.md) and [docs](https://infisical.com/docs)+ </Markdown>+ );+ assert.match(markup, /<a(?![^>]*target=)[^>]*href="#"/);+ assert.ok(!markup.includes("references/guide.md"));+ assert.match(markup, /<a[^>]*target="_blank"[^>]*href="https:\/\/infisical.com\/docs"/);+ });+});diff --git a/frontend/src/components/v3/generic/Markdown/Markdown.tsx b/frontend/src/components/v3/generic/Markdown/Markdown.tsxindex 43262bee6b..88859f287b 100644--- a/frontend/src/components/v3/generic/Markdown/Markdown.tsx+++ b/frontend/src/components/v3/generic/Markdown/Markdown.tsx@@ -1,4 +1,5 @@-import ReactMarkdown, { type Components } from "react-markdown";+import { type ComponentProps, createContext, useContext } from "react";+import ReactMarkdown, { type Components, type ExtraProps } from "react-markdown";import { CheckIcon } from "lucide-react";import remarkGfm from "remark-gfm";@@ -11,6 +12,61 @@ type MarkdownProps = {*/children: string;className?: string;+ /**+ * Called with the href of a link that has no scheme, such as `references/guide.md` or `#usage`, on a click or+ * middle-click, instead of the browser following it. Without it such a link resolves against the app's URL and+ * lands on a missing page.+ */+ onRelativeLinkClick?: (href: string) => void;+};++const linkClassName = "text-info underline underline-offset-4 hover:text-info/80";++const isAbsoluteHref = (href: string) => /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("//");++const RelativeLinkContext = createContext<MarkdownProps["onRelativeLinkClick"]>(undefined);++const MarkdownLink = ({+ node,+ className,+ children,+ href,+ ...props+}: ComponentProps<"a"> & ExtraProps) => {+ const onRelativeLinkClick = useContext(RelativeLinkContext);+ if (onRelativeLinkClick && href && !isAbsoluteHref(href)) {+ // The real href would still reach the browser through "Open in new tab" and copy link, so it stays out of the+ // anchor; "#" keeps the link focusable and opens this same page at worst.+ return (+ <a+ className={cn(linkClassName, className)}+ href="#"+ {...props}+ onClick={(event) => {+ event.preventDefault();+ onRelativeLinkClick(href);+ }}+ onAuxClick={(event) => {+ if (event.button !== 1) return;+ event.preventDefault();+ onRelativeLinkClick(href);+ }}+ >+ {children}+ </a>+ );+ }+ return (+ <a+ className={cn(linkClassName, className)}+ target="_blank"+ rel="noopener noreferrer"+ href={href}+ {...props}+ >+ {children}+ </a>+ );};const components: Components = {@@ -50,16 +106,7 @@ const components: Components = {p: ({ node, className, ...props }) => (<p className={cn("my-3 leading-relaxed first:mt-0 last:mb-0", className)} {...props} />),- a: ({ node, className, children, ...props }) => (- <a- className={cn("text-info underline underline-offset-4 hover:text-info/80", className)}- target="_blank"- rel="noopener noreferrer"- {...props}- >- {children}- </a>- ),+ a: MarkdownLink,ul: ({ node, className, ...props }) => (<ulclassName={cn(@@ -149,12 +196,14 @@ const components: Components = {)};-const Markdown = ({ children, className }: MarkdownProps) => (- <div data-slot="markdown" className={cn("min-w-0 text-sm text-foreground", className)}>- <ReactMarkdown components={components} remarkPlugins={[remarkGfm]} skipHtml>- {children}- </ReactMarkdown>- </div>+const Markdown = ({ children, className, onRelativeLinkClick }: MarkdownProps) => (+ <RelativeLinkContext.Provider value={onRelativeLinkClick}>+ <div data-slot="markdown" className={cn("min-w-0 text-sm text-foreground", className)}>+ <ReactMarkdown components={components} remarkPlugins={[remarkGfm]} skipHtml>+ {children}+ </ReactMarkdown>+ </div>+ </RelativeLinkContext.Provider>);export { Markdown, type MarkdownProps };diff --git a/frontend/src/helpers/agentVaultSkills.test.ts b/frontend/src/helpers/agentVaultSkills.test.tsindex f89719eda6..5c341957ae 100644--- a/frontend/src/helpers/agentVaultSkills.test.ts+++ b/frontend/src/helpers/agentVaultSkills.test.ts@@ -18,6 +18,7 @@ import {getSkillFolders,getSkillHeaderError,getSkillHeaderText,+ resolveSkillLinkPath,getSkillParentPath,getSkillPathError,isReservedSkillName,@@ -801,3 +802,31 @@ describe("large files in the save review", () => {expect([change.additions, change.deletions]).toEqual([1, 1]);});});++describe("resolveSkillLinkPath", () => {+ test("follows a link from the file's own folder", () => {+ expect(resolveSkillLinkPath("SKILL.md", "references/patterns.md")).toBe(+ "references/patterns.md"+ );+ expect(resolveSkillLinkPath("references/a.md", "b.md")).toBe("references/b.md");+ expect(resolveSkillLinkPath("references/a.md", "./b.md")).toBe("references/b.md");+ expect(resolveSkillLinkPath("references/a.md", "../scripts/run.sh")).toBe("scripts/run.sh");+ });++ test("reads a leading slash as the skill's root", () => {+ expect(resolveSkillLinkPath("references/a.md", "/SKILL.md")).toBe("SKILL.md");+ });++ test("drops the heading and query and decodes the name", () => {+ expect(resolveSkillLinkPath("SKILL.md", "references/my%20notes.md#setup")).toBe(+ "references/my notes.md"+ );+ expect(resolveSkillLinkPath("SKILL.md", "guide.md?raw=1")).toBe("guide.md");+ expect(resolveSkillLinkPath("SKILL.md", "100%.md")).toBe("100%.md");+ });++ test("returns null for a heading-only link or one that leaves the skill", () => {+ expect(resolveSkillLinkPath("SKILL.md", "#usage")).toBeNull();+ expect(resolveSkillLinkPath("SKILL.md", "../outside.md")).toBeNull();+ });+});diff --git a/frontend/src/helpers/agentVaultSkills.ts b/frontend/src/helpers/agentVaultSkills.tsindex 1743e001a7..569ed65a1f 100644--- a/frontend/src/helpers/agentVaultSkills.ts+++ b/frontend/src/helpers/agentVaultSkills.ts@@ -300,6 +300,33 @@ export const getSkillParentPath = (path: string) => {return slash === -1 ? "" : path.slice(0, slash);};+/**+ * The skill path a relative link in `fromPath` points at, the way an agent reading the folder would follow it.+ * A leading slash means the skill's root. Null for a link to a heading only, or one that climbs out of the skill.+ */+export const resolveSkillLinkPath = (fromPath: string, href: string): string | null => {+ const [target] = href.split(/[?#]/);+ if (!target) return null;+ let decoded = target;+ try {+ decoded = decodeURIComponent(target);+ } catch {+ // A stray % is part of the name.+ }+ const segments = decoded.startsWith("/")+ ? []+ : getSkillParentPath(fromPath).split("/").filter(Boolean);+ for (const segment of decoded.split("/")) {+ if (segment === "..") {+ if (segments.length === 0) return null;+ segments.pop();+ } else if (segment !== "" && segment !== ".") {+ segments.push(segment);+ }+ }+ return segments.length ? segments.join("/") : null;+};+export const getSkillBaseName = (path: string) => path.slice(path.lastIndexOf("/") + 1);const isSameOrInside = (path: string, folder: string) =>diff --git a/frontend/src/pages/agent-vault/AgentVaultAccessBundleDetailPage/components/SkillsCard.tsx b/frontend/src/pages/agent-vault/AgentVaultAccessBundleDetailPage/components/SkillsCard.tsxindex 1c8c03b0da..de3ec9107b 100644--- a/frontend/src/pages/agent-vault/AgentVaultAccessBundleDetailPage/components/SkillsCard.tsx+++ b/frontend/src/pages/agent-vault/AgentVaultAccessBundleDetailPage/components/SkillsCard.tsx@@ -2,7 +2,6 @@ import { useState } from "react";import { EyeIcon, MoreHorizontalIcon, PlusIcon, TrashIcon } from "lucide-react";import { CreateSkillSheet } from "@app/components/agent-vault/skills/CreateSkillSheet";-import { SkillDescription } from "@app/components/agent-vault/skills/SkillDescription";import { SkillSheet } from "@app/components/agent-vault/skills/SkillSheet";import { createNotification } from "@app/components/notifications";import {@@ -161,14 +160,12 @@ export const SkillsCard = ({ accessBundleId, accessBundleName, canManage }: Propto="/organizations/$orgId/agent-vault/access-bundles/$accessBundleId"params={{ orgId: currentOrg.id, accessBundleId }}search={(prev) => ({ ...prev, skillId: skill.id })}- title={skill.name}+ title={skill.description}>{skill.name}</RowLink></TableCell>- <TableCell isTruncatable>- <SkillDescription description={skill.description} />- </TableCell>+ <TableCell isTruncatable>{skill.description}</TableCell><TableCell variant="action"><DropdownMenu><DropdownMenuTrigger asChild>diff --git a/frontend/src/pages/agent-vault/AgentVaultSkillsPage/components/SkillsCard.tsx b/frontend/src/pages/agent-vault/AgentVaultSkillsPage/components/SkillsCard.tsxindex bf008da633..06f12092f3 100644--- a/frontend/src/pages/agent-vault/AgentVaultSkillsPage/components/SkillsCard.tsx+++ b/frontend/src/pages/agent-vault/AgentVaultSkillsPage/components/SkillsCard.tsx@@ -14,7 +14,6 @@ import { CreateSkillSheet } from "@app/components/agent-vault/skills/CreateSkillimport { DeleteSkillDialog } from "@app/components/agent-vault/skills/DeleteSkillDialog";import { downloadSkillVersion } from "@app/components/agent-vault/skills/downloadSkillVersion";import { SkillBundleBadges } from "@app/components/agent-vault/skills/SkillBundleBadges";-import { SkillDescription } from "@app/components/agent-vault/skills/SkillDescription";import { SkillSheet } from "@app/components/agent-vault/skills/SkillSheet";import { createNotification } from "@app/components/notifications";import {@@ -220,14 +219,12 @@ export const SkillsCard = () => {to="/organizations/$orgId/agent-vault/skills"params={{ orgId: currentOrg.id }}search={{ skillId: skill.id }}- title={skill.name}+ title={skill.description}>{skill.name}</RowLink></TableCell>- <TableCell isTruncatable>- <SkillDescription description={skill.description} />- </TableCell>+ <TableCell isTruncatable>{skill.description}</TableCell><TableCell><SkillBundleBadges accessBundles={skill.accessBundles} /></TableCell>