Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f6f68359c |
No files matched your search
@@ -384,64 +384,6 @@ describe("ChatMarkdown", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("renders path-shaped inline code as interactive file chips", async () => {
|
||||
const source = [
|
||||
"Call `appendFileSync` once per batch.",
|
||||
"Inspect `apps/server/src/provider/Layers/EventNdjsonLogger.ts:148` and keep `1.2.3` unchanged.",
|
||||
].join("\n\n");
|
||||
const screen = await render(
|
||||
<ChatMarkdown text={source} cwd="/repo/project" threadRef={threadRef} />,
|
||||
);
|
||||
|
||||
try {
|
||||
const link = page.getByRole("link", { name: "EventNdjsonLogger.ts · L148" });
|
||||
await expect.element(link).toHaveClass(/chat-markdown-file-link/);
|
||||
await expect
|
||||
.element(link)
|
||||
.toHaveAttribute(
|
||||
"href",
|
||||
"/repo/project/apps/server/src/provider/Layers/EventNdjsonLogger.ts:148",
|
||||
);
|
||||
|
||||
const inlineCodeValues = [
|
||||
...document.querySelectorAll<HTMLElement>(".chat-markdown :not(pre) > code"),
|
||||
].map((element) => element.textContent);
|
||||
expect(inlineCodeValues).toEqual(["appendFileSync", "1.2.3"]);
|
||||
|
||||
await link.click();
|
||||
await vi.waitFor(() => {
|
||||
expect(
|
||||
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef),
|
||||
).toMatchObject({
|
||||
isOpen: true,
|
||||
activeSurfaceId: "file:apps/server/src/provider/Layers/EventNdjsonLogger.ts",
|
||||
});
|
||||
});
|
||||
} finally {
|
||||
await screen.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("disambiguates inline-code file chips with duplicate basenames", async () => {
|
||||
const screen = await render(
|
||||
<ChatMarkdown
|
||||
text="Compare `apps/web/src/first/config.ts` with `packages/shared/src/second/config.ts`."
|
||||
cwd="/repo/project"
|
||||
/>,
|
||||
);
|
||||
|
||||
try {
|
||||
await expect
|
||||
.element(page.getByRole("link", { name: "config.ts · src/first" }))
|
||||
.toBeInTheDocument();
|
||||
await expect
|
||||
.element(page.getByRole("link", { name: "config.ts · src/second" }))
|
||||
.toBeInTheDocument();
|
||||
} finally {
|
||||
await screen.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("renders sanitized details with the design-system collapsible", async () => {
|
||||
const source = [
|
||||
"<details open>",
|
||||
|
||||
@@ -54,7 +54,6 @@ import {
|
||||
import {
|
||||
normalizeMarkdownLinkDestination,
|
||||
resolveMarkdownFileLinkMeta,
|
||||
resolveMarkdownInlineCodeFileLinkMeta,
|
||||
rewriteMarkdownFileUriHref,
|
||||
} from "../markdown-links";
|
||||
import { readLocalApi } from "../localApi";
|
||||
@@ -162,8 +161,6 @@ function extractPreCodeMeta(node: unknown): string | undefined {
|
||||
type MarkdownAstNode = {
|
||||
type?: string;
|
||||
meta?: unknown;
|
||||
value?: unknown;
|
||||
url?: string;
|
||||
data?: {
|
||||
hProperties?: Record<string, unknown>;
|
||||
};
|
||||
@@ -189,25 +186,6 @@ function remarkPreserveCodeMeta() {
|
||||
};
|
||||
}
|
||||
|
||||
function remarkLinkInlineCodeFilePaths(options: { readonly cwd: string | undefined }) {
|
||||
return (tree: MarkdownAstNode) => {
|
||||
const visit = (node: MarkdownAstNode) => {
|
||||
if (node.type === "inlineCode" && typeof node.value === "string") {
|
||||
const value = node.value;
|
||||
if (resolveMarkdownInlineCodeFileLinkMeta(value, options.cwd)) {
|
||||
node.type = "link";
|
||||
node.url = value.trim();
|
||||
node.children = [{ type: "text", value }];
|
||||
delete node.value;
|
||||
}
|
||||
}
|
||||
node.children?.forEach(visit);
|
||||
};
|
||||
|
||||
visit(tree);
|
||||
};
|
||||
}
|
||||
|
||||
function nodeToPlainText(node: ReactNode): string {
|
||||
if (typeof node === "string" || typeof node === "number") {
|
||||
return String(node);
|
||||
@@ -689,8 +667,6 @@ interface MarkdownFileLinkProps {
|
||||
}
|
||||
|
||||
const MARKDOWN_LINK_HREF_PATTERN = /\[[^\]]*]\(([^)\s]+)(?:\s+["'][^"']*["'])?\)/g;
|
||||
const MARKDOWN_INLINE_CODE_PATTERN = /(?<!`)(`{1,2})(?!`)([\s\S]*?)(?<!`)\1(?!`)/g;
|
||||
const MARKDOWN_FENCED_CODE_BLOCK_PATTERN = /^(`{3,}|~{3,})[^\n]*\n[\s\S]*?^\1\s*$/gm;
|
||||
const MARKDOWN_FILE_LINK_CLASS_NAME =
|
||||
"chat-markdown-file-link cursor-pointer transition-colors hover:bg-accent/70";
|
||||
|
||||
@@ -764,17 +740,6 @@ function extractMarkdownLinkHrefs(text: string): string[] {
|
||||
return hrefs;
|
||||
}
|
||||
|
||||
function extractMarkdownInlineCodeValues(text: string): string[] {
|
||||
const stripped = text.replace(MARKDOWN_FENCED_CODE_BLOCK_PATTERN, "");
|
||||
const values: string[] = [];
|
||||
for (const match of stripped.matchAll(MARKDOWN_INLINE_CODE_PATTERN)) {
|
||||
const value = match[2]?.trim();
|
||||
if (!value) continue;
|
||||
values.push(value);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
function normalizeMarkdownLinkHrefKey(href: string): string {
|
||||
const normalizedHref = normalizeMarkdownLinkDestination(href);
|
||||
return rewriteMarkdownFileUriHref(normalizedHref) ?? normalizedHref;
|
||||
@@ -1225,14 +1190,6 @@ function ChatMarkdown({
|
||||
metaByHref.set(normalizedHref, meta);
|
||||
}
|
||||
}
|
||||
for (const value of extractMarkdownInlineCodeValues(text)) {
|
||||
const normalizedHref = normalizeMarkdownLinkHrefKey(value);
|
||||
if (metaByHref.has(normalizedHref)) continue;
|
||||
const meta = resolveMarkdownInlineCodeFileLinkMeta(normalizedHref, cwd);
|
||||
if (meta) {
|
||||
metaByHref.set(normalizedHref, meta);
|
||||
}
|
||||
}
|
||||
return metaByHref;
|
||||
}, [cwd, text]);
|
||||
const fileLinkParentSuffixByPath = useMemo(() => {
|
||||
@@ -1263,10 +1220,7 @@ function ChatMarkdown({
|
||||
},
|
||||
a({ node, href, children, ...props }) {
|
||||
const normalizedHref = href ? normalizeMarkdownLinkHrefKey(href) : "";
|
||||
const fileLinkMeta = normalizedHref
|
||||
? (markdownFileLinkMetaByHref.get(normalizedHref) ??
|
||||
resolveMarkdownFileLinkMeta(normalizedHref, cwd))
|
||||
: null;
|
||||
const fileLinkMeta = normalizedHref ? markdownFileLinkMetaByHref.get(normalizedHref) : null;
|
||||
if (!fileLinkMeta) {
|
||||
const faviconHost = resolveExternalLinkHost(href);
|
||||
const isSameDocumentLink = href?.startsWith("#") ?? false;
|
||||
@@ -1373,7 +1327,6 @@ function ChatMarkdown({
|
||||
}),
|
||||
[
|
||||
diffThemeName,
|
||||
cwd,
|
||||
fileLinkParentSuffixByPath,
|
||||
isStreaming,
|
||||
markdownFileLinkMetaByHref,
|
||||
@@ -1394,13 +1347,8 @@ function ChatMarkdown({
|
||||
<ReactMarkdown
|
||||
remarkPlugins={
|
||||
lineBreaks
|
||||
? [
|
||||
remarkGfm,
|
||||
remarkBreaks,
|
||||
[remarkLinkInlineCodeFilePaths, { cwd }],
|
||||
remarkPreserveCodeMeta,
|
||||
]
|
||||
: [remarkGfm, [remarkLinkInlineCodeFilePaths, { cwd }], remarkPreserveCodeMeta]
|
||||
? [remarkGfm, remarkBreaks, remarkPreserveCodeMeta]
|
||||
: [remarkGfm, remarkPreserveCodeMeta]
|
||||
}
|
||||
rehypePlugins={[rehypeRaw, [rehypeSanitize, CHAT_MARKDOWN_SANITIZE_SCHEMA]]}
|
||||
components={markdownComponents}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import type { DesktopUpdateState } from "@t3tools/contracts";
|
||||
import type { ComponentProps } from "react";
|
||||
import { ExternalLinkIcon } from "lucide-react";
|
||||
|
||||
import {
|
||||
getDesktopUpdateLatestVersion,
|
||||
getDesktopUpdateReleaseNotesUrl,
|
||||
} from "./desktopUpdate.logic";
|
||||
import { readLocalApi } from "../localApi";
|
||||
import { stackedThreadToast, toastManager } from "./ui/toast";
|
||||
import { TooltipPopup } from "./ui/tooltip";
|
||||
|
||||
type DesktopUpdateTooltipPopupProps = {
|
||||
state: DesktopUpdateState | null;
|
||||
summary: string;
|
||||
side?: ComponentProps<typeof TooltipPopup>["side"];
|
||||
};
|
||||
|
||||
function getDesktopUpdateTooltipTitle(state: DesktopUpdateState | null): string {
|
||||
if (!state) return "Update Available";
|
||||
if (state.status === "downloaded") return "Restart to Update";
|
||||
if (state.status === "downloading") return "Downloading Update";
|
||||
if (state.status === "error") return "Update Needs Attention";
|
||||
if (state.status === "available") return "Update Available";
|
||||
return "Application Update";
|
||||
}
|
||||
|
||||
function openReleaseNotes(state: DesktopUpdateState | null) {
|
||||
const api = readLocalApi();
|
||||
const url = getDesktopUpdateReleaseNotesUrl(state);
|
||||
void api?.shell.openExternal(url).catch((error: unknown) => {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Could not open release notes",
|
||||
description: error instanceof Error ? error.message : "Unable to open GitHub Releases.",
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function DesktopUpdateTooltipPopup({
|
||||
state,
|
||||
summary,
|
||||
side = "top",
|
||||
}: DesktopUpdateTooltipPopupProps) {
|
||||
const latestVersion = state ? getDesktopUpdateLatestVersion(state) : null;
|
||||
|
||||
return (
|
||||
<TooltipPopup side={side} className="w-72 text-left">
|
||||
<div className="flex flex-col gap-3 py-1">
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="text-sm font-semibold text-popover-foreground">
|
||||
{getDesktopUpdateTooltipTitle(state)}
|
||||
</div>
|
||||
<div className="text-xs leading-snug text-muted-foreground">{summary}</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 text-xs">
|
||||
<span className="text-muted-foreground">Current Version</span>
|
||||
<span className="min-w-0 truncate font-mono text-popover-foreground">
|
||||
{state?.currentVersion ?? "Unknown"}
|
||||
</span>
|
||||
<span className="text-muted-foreground">Latest Version</span>
|
||||
<span className="min-w-0 truncate font-mono text-popover-foreground">
|
||||
{latestVersion ?? "Unknown"}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex h-8 w-fit items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-xs font-medium text-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
|
||||
onClick={() => openReleaseNotes(state)}
|
||||
>
|
||||
Release Notes
|
||||
<ExternalLinkIcon className="size-3" />
|
||||
</button>
|
||||
</div>
|
||||
</TooltipPopup>
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import {
|
||||
getDesktopUpdateActionError,
|
||||
getDesktopUpdateButtonTooltip,
|
||||
getDesktopUpdateInstallConfirmationMessage,
|
||||
getDesktopUpdateLatestVersion,
|
||||
getDesktopUpdateReleaseNotesUrl,
|
||||
isDesktopUpdateButtonDisabled,
|
||||
resolveDesktopUpdateButtonAction,
|
||||
shouldShowArm64IntelBuildWarning,
|
||||
@@ -290,3 +292,47 @@ describe("getDesktopUpdateButtonTooltip", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("desktop update release notes helpers", () => {
|
||||
it("resolves the latest version from downloaded or available state", () => {
|
||||
expect(
|
||||
getDesktopUpdateLatestVersion({
|
||||
...baseState,
|
||||
availableVersion: "1.1.0",
|
||||
downloadedVersion: "1.1.1",
|
||||
}),
|
||||
).toBe("1.1.1");
|
||||
expect(getDesktopUpdateLatestVersion({ ...baseState, availableVersion: "1.1.0" })).toBe(
|
||||
"1.1.0",
|
||||
);
|
||||
});
|
||||
|
||||
it("links stable updates to their GitHub release tag", () => {
|
||||
expect(
|
||||
getDesktopUpdateReleaseNotesUrl({
|
||||
...baseState,
|
||||
channel: "latest",
|
||||
availableVersion: "1.1.0",
|
||||
}),
|
||||
).toBe("https://github.com/pingdotgg/t3code/releases/tag/v1.1.0");
|
||||
});
|
||||
|
||||
it("links nightly updates to their GitHub release tag", () => {
|
||||
expect(
|
||||
getDesktopUpdateReleaseNotesUrl({
|
||||
...baseState,
|
||||
channel: "nightly",
|
||||
availableVersion: "1.1.0-nightly.20260501.17",
|
||||
}),
|
||||
).toBe("https://github.com/pingdotgg/t3code/releases/tag/nightly-v1.1.0-nightly.20260501.17");
|
||||
});
|
||||
|
||||
it("falls back to the releases page when no latest version is known", () => {
|
||||
expect(getDesktopUpdateReleaseNotesUrl(null)).toBe(
|
||||
"https://github.com/pingdotgg/t3code/releases",
|
||||
);
|
||||
expect(getDesktopUpdateReleaseNotesUrl(baseState)).toBe(
|
||||
"https://github.com/pingdotgg/t3code/releases",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,8 @@ import type { DesktopUpdateActionResult, DesktopUpdateState } from "@t3tools/con
|
||||
|
||||
export type DesktopUpdateButtonAction = "download" | "install" | "none";
|
||||
|
||||
const DESKTOP_UPDATE_RELEASES_URL = "https://github.com/pingdotgg/t3code/releases";
|
||||
|
||||
export function resolveDesktopUpdateButtonAction(
|
||||
state: DesktopUpdateState,
|
||||
): DesktopUpdateButtonAction {
|
||||
@@ -76,6 +78,20 @@ export function getDesktopUpdateButtonTooltip(state: DesktopUpdateState): string
|
||||
return "Up to date";
|
||||
}
|
||||
|
||||
export function getDesktopUpdateLatestVersion(state: DesktopUpdateState): string | null {
|
||||
return state.downloadedVersion ?? state.availableVersion;
|
||||
}
|
||||
|
||||
export function getDesktopUpdateReleaseNotesUrl(state: DesktopUpdateState | null): string {
|
||||
const latestVersion = state ? getDesktopUpdateLatestVersion(state) : null;
|
||||
if (!state || !latestVersion) {
|
||||
return DESKTOP_UPDATE_RELEASES_URL;
|
||||
}
|
||||
|
||||
const tag = state.channel === "nightly" ? `nightly-v${latestVersion}` : `v${latestVersion}`;
|
||||
return `${DESKTOP_UPDATE_RELEASES_URL}/tag/${encodeURIComponent(tag)}`;
|
||||
}
|
||||
|
||||
export function getDesktopUpdateInstallConfirmationMessage(
|
||||
state: Pick<DesktopUpdateState, "availableVersion" | "downloadedVersion">,
|
||||
): string {
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
isDesktopUpdateButtonDisabled,
|
||||
resolveDesktopUpdateButtonAction,
|
||||
} from "../../components/desktopUpdate.logic";
|
||||
import { DesktopUpdateTooltipPopup } from "../../components/DesktopUpdateTooltip";
|
||||
import { ProviderModelPicker } from "../chat/ProviderModelPicker";
|
||||
import { TraitsPicker } from "../chat/TraitsPicker";
|
||||
import { isElectron } from "../../env";
|
||||
@@ -311,7 +312,9 @@ function AboutVersionSection() {
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
{buttonTooltip ? <TooltipPopup>{buttonTooltip}</TooltipPopup> : null}
|
||||
{buttonTooltip ? (
|
||||
<DesktopUpdateTooltipPopup state={updateState} summary={buttonTooltip} />
|
||||
) : null}
|
||||
</Tooltip>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
shouldToastDesktopUpdateActionResult,
|
||||
} from "../desktopUpdate.logic";
|
||||
import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
|
||||
import { DesktopUpdateTooltipPopup } from "../DesktopUpdateTooltip";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
|
||||
export function SidebarUpdatePill() {
|
||||
@@ -158,7 +159,7 @@ export function SidebarUpdatePill() {
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
<TooltipPopup side="top">{tooltip}</TooltipPopup>
|
||||
<DesktopUpdateTooltipPopup state={state} summary={tooltip} side="top" />
|
||||
</Tooltip>
|
||||
{action === "download" && (
|
||||
<Tooltip>
|
||||
|
||||
@@ -3,7 +3,6 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
import {
|
||||
resolveMarkdownFileLinkMeta,
|
||||
resolveMarkdownFileLinkTarget,
|
||||
resolveMarkdownInlineCodeFileLinkMeta,
|
||||
rewriteMarkdownFileUriHref,
|
||||
} from "./markdown-links";
|
||||
|
||||
@@ -128,35 +127,3 @@ describe("resolveMarkdownFileLinkTarget", () => {
|
||||
expect(resolveMarkdownFileLinkTarget("/chat/settings")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveMarkdownInlineCodeFileLinkMeta", () => {
|
||||
it("resolves path-shaped inline code with source positions", () => {
|
||||
expect(
|
||||
resolveMarkdownInlineCodeFileLinkMeta(
|
||||
"apps/server/src/provider/Layers/EventNdjsonLogger.ts:148",
|
||||
"/repo/project",
|
||||
),
|
||||
).toMatchObject({
|
||||
basename: "EventNdjsonLogger.ts",
|
||||
line: 148,
|
||||
targetPath: "/repo/project/apps/server/src/provider/Layers/EventNdjsonLogger.ts:148",
|
||||
workspaceRelativePath: "apps/server/src/provider/Layers/EventNdjsonLogger.ts",
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves bare filenames only when they include a source position", () => {
|
||||
expect(resolveMarkdownInlineCodeFileLinkMeta("script.ts:10", "/repo/project")).toMatchObject({
|
||||
basename: "script.ts",
|
||||
line: 10,
|
||||
targetPath: "/repo/project/script.ts:10",
|
||||
});
|
||||
expect(resolveMarkdownInlineCodeFileLinkMeta("script.ts", "/repo/project")).toBeNull();
|
||||
});
|
||||
|
||||
it("leaves ordinary code and ambiguous slash values alone", () => {
|
||||
expect(resolveMarkdownInlineCodeFileLinkMeta("sink.write()", "/repo/project")).toBeNull();
|
||||
expect(resolveMarkdownInlineCodeFileLinkMeta("1.2.3", "/repo/project")).toBeNull();
|
||||
expect(resolveMarkdownInlineCodeFileLinkMeta("1/2", "/repo/project")).toBeNull();
|
||||
expect(resolveMarkdownInlineCodeFileLinkMeta("client/server", "/repo/project")).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -211,28 +211,3 @@ export function resolveMarkdownFileLinkMeta(
|
||||
...(columnNumber !== undefined ? { column: columnNumber } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline code is used for many non-path values, so only promote references
|
||||
* with unambiguous path syntax. Markdown links remain more permissive because
|
||||
* the link destination itself already signals intent.
|
||||
*/
|
||||
export function resolveMarkdownInlineCodeFileLinkMeta(
|
||||
value: string,
|
||||
cwd?: string,
|
||||
): MarkdownFileLinkMeta | null {
|
||||
const candidate = value.trim();
|
||||
const hasSourcePosition =
|
||||
POSITION_SUFFIX_PATTERN.test(candidate) || /#L\d+(?:C\d+)?$/i.test(candidate);
|
||||
if (!/[\\/]/.test(candidate) && !hasSourcePosition) {
|
||||
return null;
|
||||
}
|
||||
const meta = resolveMarkdownFileLinkMeta(candidate, cwd);
|
||||
if (!meta) {
|
||||
return null;
|
||||
}
|
||||
if (!/[A-Za-z]/.test(meta.basename) || (!meta.basename.includes(".") && !hasSourcePosition)) {
|
||||
return null;
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
Reference in new issue
Block a user