Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions apps/mobile/src/features/threads/ThreadFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { KeyboardAwareLegendList } from "@legendapp/list/keyboard";
import { useViewabilityAmount, type LegendListRef } from "@legendapp/list/react-native";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
import { repairMarkdownFileLinks } from "@t3tools/client-runtime/repair-markdown-file-links";
import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
import {
type OrchestrationMessageContext,
Expand Down Expand Up @@ -908,17 +907,7 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
readonly skills?: ReadonlyArray<SelectableMarkdownSkill> | undefined;
}) {
const segments = useMemo(
() =>
splitCodexArtifactTemplateMarkdown(props.markdown).map((segment) =>
segment.kind === "markdown"
? {
...segment,
markdown: renderCodexFileCitationsAsMarkdown(
repairMarkdownFileLinks(segment.markdown),
),
}
: segment,
),
() => splitCodexArtifactTemplateMarkdown(props.markdown),
[props.markdown],
);

Expand All @@ -934,7 +923,7 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
}
if (segment.markdown.trim().length === 0) return null;

const markdown = segment.markdown;
const markdown = renderCodexFileCitationsAsMarkdown(segment.markdown);
return hasNativeSelectableMarkdownText() ? (
<SelectableMarkdownText
key={`markdown:${segment.sourceOffset}`}
Expand Down
4 changes: 1 addition & 3 deletions apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { parseScopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/en
import { useAtomValue } from "@effect/atom-react";
import { environmentThreadDetails } from "../../state/threads";
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
import { repairMarkdownFileLinks } from "@t3tools/client-runtime/repair-markdown-file-links";
import { Link } from "@tanstack/react-router";
import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
import { notificationChildThreadId } from "@t3tools/client-runtime/state/thread-execution";
Expand Down Expand Up @@ -2495,7 +2494,6 @@ function AttemptFoldTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "at
function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
const ctx = use(TimelineRowCtx);
const messageText = row.message.text || (row.message.streaming ? "" : "(empty response)");
const renderedText = useMemo(() => repairMarkdownFileLinks(messageText), [messageText]);

return (
<>
Expand All @@ -2509,7 +2507,7 @@ function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mess
listRef={ctx.listRef}
>
<ChatMarkdown
text={renderedText}
text={messageText}
cwd={ctx.markdownCwd}
threadRef={ctx.threadRef ?? undefined}
isStreaming={Boolean(row.message.streaming)}
Expand Down
4 changes: 0 additions & 4 deletions packages/client-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
"types": "./src/markdownLinks.ts",
"default": "./src/markdownLinks.ts"
},
"./repair-markdown-file-links": {
"types": "./src/repairMarkdownFileLinks.ts",
"default": "./src/repairMarkdownFileLinks.ts"
},
"./media-reference": {
"types": "./src/mediaReference.ts",
"default": "./src/mediaReference.ts"
Expand Down
112 changes: 0 additions & 112 deletions packages/client-runtime/src/markdownLinks.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { describe, expect, it } from "vite-plus/test";
import remarkParse from "remark-parse";
import { unified } from "unified";

import {
fileBasename,
Expand All @@ -11,116 +9,6 @@ import {
splitFilePathPosition,
workspaceRelativeFilePath,
} from "./markdownLinks.ts";
import { repairMarkdownFileLinks } from "./repairMarkdownFileLinks.ts";
import {
renderCodexDirectivesForCopy,
renderCodexFileCitationsAsMarkdown,
splitCodexArtifactTemplateMarkdown,
} from "./codexMarkdownDirectives.ts";

describe("repairMarkdownFileLinks", () => {
it.each([
"CONTRIBUTING.md",
"local/path/file.md",
"docs/My Folder/file.md",
"./scripts/deploy",
"~/notes/today.md",
"/home/me/My Folder/file.md",
"/tmp/reports/",
"C:\\Users\\me\\My Folder\\file.md",
"file:///home/me/file.md",
"src/main.ts:12:5",
])("repairs a complete local destination: %s", (path) => {
const source = `- [file](<${path})`;
const rendered = repairMarkdownFileLinks(source);
expect(rendered).toBe(`- [file](<${path}>)`);
expect(unified().use(remarkParse).parse(rendered).children[0]).toMatchObject({
type: "list",
children: [{ children: [{ children: [{ type: "link" }] }] }],
});
expect(repairMarkdownFileLinks(rendered)).toBe(rendered);
});

it.each([
"ordinary prose",
"[file](<CONTRIBUTING.md>)",
"[site](<https://example.com/docs)",
"[route](</chat/settings)",
"[prose](<not a file)",
"[file](<src/main.ts",
"[file](<src/main.ts>",
"[file](<./file(one).md)",
"[file](<./file.md))",
"[file](<./file)name.md)",
"[file](<./file\\).md)",
"![image](<./file.png)",
"\\\\![image](<./file.png)",
"\\\\\\\\![image](<./file.png)",
"\\[file](<./file.md)",
"\\\\\\[file](<./file.md)",
"`[file](<./file.md)`",
"``[file](<./file.md)``",
"```md\n[file](<./file.md)\n```",
"~~~md\n[file](<./file.md)\n~~~",
" [file](<./file.md)",
"<div>\n[file](<./file.md)\n</div>",
"HTML <span>[file](<./file.md)</span>",
'<span title="[file](<./file.md)">text</span>',
"[outer [file](<./file.md)](https://example.com)",
"[outer [file](<./file.md)][ref]\n\n[ref]: https://example.com",
'[ref]: ./file.md "[file](<./other.md)"',
':codex-file-citation{path="./[file](<./other.md)" purpose="output"}',
':codex-file-citation{path="./[file](<./other.md)',
'::artifact-template{skill_name="artifact-template-example" skill_directory="/tmp/skills/example" display_name="[file](<./file.md)" artifact_kind="document"}',
'::artifact-template{display_name="[file](<./file.md)',
])("preserves protected or uncertain syntax: %s", (source) => {
expect(repairMarkdownFileLinks(source)).toBe(source);
});

it("uses CommonMark backslash parity for link openers", () => {
expect(repairMarkdownFileLinks("\\\\[file](<./file.md)")).toBe("\\\\[file](<./file.md>)");
expect(repairMarkdownFileLinks("\\\\\\\\[file](<./file.md)")).toBe(
"\\\\\\\\[file](<./file.md>)",
);
expect(repairMarkdownFileLinks("\\![file](<./file.md)")).toBe("\\![file](<./file.md>)");
});

it("repairs ordinary segments after splitting mobile artifacts and preserves copy source", () => {
const link = "[file](<./file.md)";
const template =
'::artifact-template{skill_name="artifact-template-example" skill_directory="/tmp/skills/example" display_name="[file](<./file.md)" artifact_kind="document"}';
const citation = ':codex-file-citation{path="./report.md"}';
const source = `${link}\n\n${template}\n\n${citation}`;
const segments = splitCodexArtifactTemplateMarkdown(source);
const rendered = segments.map((segment) =>
segment.kind === "markdown"
? {
...segment,
markdown: renderCodexFileCitationsAsMarkdown(repairMarkdownFileLinks(segment.markdown)),
}
: segment,
);
expect(rendered[0]).toEqual({
kind: "markdown",
markdown: `${link.slice(0, -1)}>)\n\n`,
sourceOffset: 0,
});
expect(rendered[1]).toEqual(segments[1]);
expect(rendered[1]).toMatchObject({
kind: "artifact-template",
sourceOffset: link.length + 2,
template: { displayName: link, skillName: "artifact-template-example" },
});
expect(rendered[2]).toEqual({
kind: "markdown",
sourceOffset: source.indexOf("\n\n" + citation),
markdown: "\n\n[report.md](<./report.md>)",
});
expect(renderCodexDirectivesForCopy(source)).toBe(
`${link}\n\n${link} (Document template)\n\n[report.md](<./report.md>)`,
);
});
});

describe("isMarkdownFileLinkLabel", () => {
it.each([
Expand Down
84 changes: 0 additions & 84 deletions packages/client-runtime/src/repairMarkdownFileLinks.ts

This file was deleted.

Loading