Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(rich-content): render bare in-app project/issue URLs as chips (MUL-5499) (#6141)

Jiayuan Zhangd4ae220cc1f1
diff --git a/apps/mobile/lib/markdown/markdown.tsx b/apps/mobile/lib/markdown/markdown.tsx
index 3fb980480d..258febdf91 100644
--- a/apps/mobile/lib/markdown/markdown.tsx
+++ b/apps/mobile/lib/markdown/markdown.tsx
@@ -142,6 +142,7 @@ export function Markdown({
// return without falling through to Linking.
//
// mention://issue/<uuid> → navigate to that issue detail
+ // mention://project/<uuid> → navigate to that project detail
// mention://member/<uuid> → no-op (no member profile screen yet)
// mention://agent/<uuid> → no-op (no agent profile screen yet)
// mention://squad/<uuid> → no-op (no squad profile screen yet)
@@ -153,8 +154,12 @@ export function Markdown({
if (slash < 0) return;
const type = rest.slice(0, slash);
const id = rest.slice(slash + 1);
- if (type === "issue" && id && wsSlug) {
- router.push(`/${wsSlug}/issue/${id}`);
+ if (id && wsSlug) {
+ // Route segments are singular on mobile (`/issue/`, `/project/`)
+ // while the mention type and web's route are the same word — keep
+ // the mapping explicit so a new type can't silently no-op.
+ if (type === "issue") router.push(`/${wsSlug}/issue/${id}`);
+ else if (type === "project") router.push(`/${wsSlug}/project/${id}`);
}
return;
}
diff --git a/packages/views/common/rich-content-sanitize-contract.test.tsx b/packages/views/common/rich-content-sanitize-contract.test.tsx
index 5a715697b8..801a6d42a5 100644
--- a/packages/views/common/rich-content-sanitize-contract.test.tsx
+++ b/packages/views/common/rich-content-sanitize-contract.test.tsx
@@ -73,7 +73,10 @@ vi.mock("../editor/link-hover-card", () => ({
LinkHoverCard: () => null,
}));
-vi.mock("../editor/utils/link-handler", () => ({
+// Partial: only navigation is stubbed. The pure URL predicates stay real so
+// the sanitize contract is asserted against the renderer's real dispatch.
+vi.mock("../editor/utils/link-handler", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("../editor/utils/link-handler")>()),
openLink: vi.fn(),
isMentionHref: (href?: string) => Boolean(href?.startsWith("mention://")),
}));
diff --git a/packages/views/editor/link-hover-card.tsx b/packages/views/editor/link-hover-card.tsx
index 06eecc6ae7..2099729555 100644
--- a/packages/views/editor/link-hover-card.tsx
+++ b/packages/views/editor/link-hover-card.tsx
@@ -69,9 +69,16 @@ function useLinkHover(containerRef: React.RefObject<HTMLElement | null>, disable
if (!link) return;
const href = link.getAttribute("href");
if (!href || isMentionHref(href)) return;
- // Issue mention cards render as <a class="issue-mention"> — they
- // display their own rich info, a URL hover card is redundant.
- if (link.classList.contains("issue-mention")) return;
+ // Mention chips render as <a class="issue-mention"> / <a
+ // class="project-mention"> — they display their own rich info, so a URL
+ // hover card is redundant, and the URL it would offer to copy is an
+ // in-app path rather than the shareable link the user expects.
+ if (
+ link.classList.contains("issue-mention") ||
+ link.classList.contains("project-mention")
+ ) {
+ return;
+ }
clearTimeout(hideTimer.current);
showTimer.current = window.setTimeout(() => {
diff --git a/packages/views/editor/readonly-content.test.tsx b/packages/views/editor/readonly-content.test.tsx
index dfef34be2e..46505af892 100644
--- a/packages/views/editor/readonly-content.test.tsx
+++ b/packages/views/editor/readonly-content.test.tsx
@@ -60,7 +60,10 @@ vi.mock("./link-hover-card", () => ({
LinkHoverCard: () => null,
}));
-vi.mock("./utils/link-handler", () => ({
+// Partial: only navigation is stubbed. The pure URL predicates stay real so
+// these autolink fixtures assert the renderer's actual link/chip dispatch.
+vi.mock("./utils/link-handler", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("./utils/link-handler")>()),
openLink: vi.fn(),
isMentionHref: (href?: string) => Boolean(href?.startsWith("mention://")),
}));
diff --git a/packages/views/editor/styles/prose.css b/packages/views/editor/styles/prose.css
index a00627444a..6ae595900d 100644
--- a/packages/views/editor/styles/prose.css
+++ b/packages/views/editor/styles/prose.css
@@ -377,13 +377,18 @@
text-decoration-color: var(--brand);
}
-/* Issue mention cards — inline cards that sit within text flow */
-.rich-text-editor a.issue-mention {
+/* Mention chips — inline cards that sit within text flow. The chip already
+ carries its own affordance (border, icon, hover background), so the generic
+ link color and underline above would be a second, competing one drawn
+ through the card. Every chip-shaped mention belongs here. */
+.rich-text-editor a.issue-mention,
+.rich-text-editor a.project-mention {
color: inherit;
text-decoration: none;
}
-.rich-text-editor a.issue-mention:hover {
+.rich-text-editor a.issue-mention:hover,
+.rich-text-editor a.project-mention:hover {
text-decoration: none;
}
diff --git a/packages/views/editor/utils/link-handler.test.ts b/packages/views/editor/utils/link-handler.test.ts
index c559f9f587..064d42a6b2 100644
--- a/packages/views/editor/utils/link-handler.test.ts
+++ b/packages/views/editor/utils/link-handler.test.ts
@@ -1,5 +1,9 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
-import { openLink, toInternalAppPath } from "./link-handler";
+import {
+ openLink,
+ parseWorkspaceEntityLink,
+ toInternalAppPath,
+} from "./link-handler";
const APP_ORIGIN = "https://app.multica.ai";
@@ -107,3 +111,131 @@ describe("openLink", () => {
expect(navigatedPaths()).toEqual(["/other/issues/MUL-1"]);
});
});
+
+describe("parseWorkspaceEntityLink", () => {
+ const PROJECT_ID = "8f14e45f-ceea-4d0e-a1a2-9b1c0d3e4f5a";
+ const ISSUE_ID = "1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed";
+
+ it("parses an absolute project URL on the app origin", () => {
+ expect(
+ parseWorkspaceEntityLink(
+ `${APP_ORIGIN}/acme/projects/${PROJECT_ID}`,
+ APP_ORIGIN,
+ ),
+ ).toEqual({ kind: "project", id: PROJECT_ID, slug: "acme" });
+ });
+
+ it("parses an absolute issue URL on the app origin", () => {
+ expect(
+ parseWorkspaceEntityLink(`${APP_ORIGIN}/acme/issues/${ISSUE_ID}`, APP_ORIGIN),
+ ).toEqual({ kind: "issue", id: ISSUE_ID, slug: "acme" });
+ });
+
+ it("parses a site-relative path without needing an app origin", () => {
+ expect(parseWorkspaceEntityLink(`/acme/projects/${PROJECT_ID}`)).toEqual({
+ kind: "project",
+ id: PROJECT_ID,
+ slug: "acme",
+ });
+ });
+
+ it("reports a null slug for the slugless legacy form", () => {
+ expect(parseWorkspaceEntityLink(`/projects/${PROJECT_ID}`)).toEqual({
+ kind: "project",
+ id: PROJECT_ID,
+ slug: null,
+ });
+ });
+
+ it("returns null for another origin", () => {
+ expect(
+ parseWorkspaceEntityLink(
+ `https://evil.example/acme/projects/${PROJECT_ID}`,
+ APP_ORIGIN,
+ ),
+ ).toBeNull();
+ });
+
+ // A leading slash does not mean "this site". Both of these name another host
+ // and a browser follows them there, so the parser has to resolve the href
+ // rather than test its prefix.
+ it("returns null for a host-bearing href that still starts with a slash", () => {
+ expect(
+ parseWorkspaceEntityLink(`//evil.example/projects/${PROJECT_ID}`, APP_ORIGIN),
+ ).toBeNull();
+ // Backslashes are normalised to slashes, so this names evil.example too —
+ // and it slips past a `//` prefix test.
+ expect(
+ parseWorkspaceEntityLink(`/\\evil.example/projects/${PROJECT_ID}`, APP_ORIGIN),
+ ).toBeNull();
+ });
+
+ it("returns null for a non-http scheme", () => {
+ expect(parseWorkspaceEntityLink("javascript:alert(1)", APP_ORIGIN)).toBeNull();
+ });
+
+ // The slugless form resolves against the current workspace either way; the
+ // two spellings must not disagree about that.
+ it("treats the slugless form the same whether or not it carries the origin", () => {
+ expect(
+ parseWorkspaceEntityLink(`${APP_ORIGIN}/projects/${PROJECT_ID}`, APP_ORIGIN),
+ ).toEqual({ kind: "project", id: PROJECT_ID, slug: null });
+ });
+
+ it("returns null for a list page", () => {
+ expect(parseWorkspaceEntityLink("/acme/projects")).toBeNull();
+ });
+
+ it("returns null for a deeper route under the entity", () => {
+ expect(
+ parseWorkspaceEntityLink(`/acme/projects/${PROJECT_ID}/settings`),
+ ).toBeNull();
+ });
+
+ it("returns null for an entity route this parser has no chip for", () => {
+ expect(parseWorkspaceEntityLink(`/acme/agents/${PROJECT_ID}`)).toBeNull();
+ });
+
+ // A query string or fragment addresses something narrower than the entity
+ // page, and a chip cannot carry it.
+ it("returns null when the link carries a query string or fragment", () => {
+ expect(
+ parseWorkspaceEntityLink(`/acme/projects/${PROJECT_ID}?tab=issues`),
+ ).toBeNull();
+ expect(
+ parseWorkspaceEntityLink(`/acme/issues/${ISSUE_ID}#comment-3`),
+ ).toBeNull();
+ });
+
+ // `copyLink` / `openInNewTab` build `paths.issueDetail(identifier || id)` and
+ // the issue route rewrites a UUID URL back to the identifier, so this — not
+ // the UUID form — is what a user actually copies out of the app.
+ it("parses an issue addressed by identifier", () => {
+ expect(parseWorkspaceEntityLink("/acme/issues/MUL-1")).toEqual({
+ kind: "issue",
+ id: "MUL-1",
+ slug: "acme",
+ });
+ });
+
+ // A project has no shorthand, so an identifier-shaped id under /projects/
+ // addresses nothing this parser could resolve.
+ it("returns null for an identifier-shaped project id", () => {
+ expect(parseWorkspaceEntityLink("/acme/projects/MUL-1")).toBeNull();
+ });
+
+ it("returns null for an id that is neither a UUID nor an identifier", () => {
+ expect(parseWorkspaceEntityLink("/acme/issues/roadmap")).toBeNull();
+ // Lowercase is not the identifier form — matching it would turn ordinary
+ // hyphenated path segments into entity references.
+ expect(parseWorkspaceEntityLink("/acme/issues/mul-1")).toBeNull();
+ });
+
+ it("returns null when the slug position holds a reserved slug", () => {
+ expect(parseWorkspaceEntityLink(`/login/projects/${PROJECT_ID}`)).toBeNull();
+ });
+
+ it("returns null for a malformed percent-escape", () => {
+ expect(parseWorkspaceEntityLink("/acme/projects/%E0%A4%A")).toBeNull();
+ });
+});
diff --git a/packages/views/editor/utils/link-handler.ts b/packages/views/editor/utils/link-handler.ts
index 0fb42a1a4d..0ee3231b03 100644
--- a/packages/views/editor/utils/link-handler.ts
+++ b/packages/views/editor/utils/link-handler.ts
@@ -6,6 +6,7 @@
*/
import { isGlobalPath, isReservedSlug } from "@multica/core/paths";
+import { isIssueIdentifier } from "@multica/ui/markdown";
/**
* Top-level workspace-scoped routes. Used to detect "/{route}/..." paths that
@@ -89,6 +90,151 @@ export function toInternalAppPath(
return `${target.pathname}${target.search}${target.hash}`;
}
+/** An in-app entity page addressed by a link — the two kinds that have a chip. */
+export interface WorkspaceEntityRef {
+ kind: "issue" | "project";
+ /**
+ * Entity id, decoded from the path. A UUID for either kind, or — for an
+ * issue only — a bare identifier (`MUL-123`). Callers dispatch on the shape
+ * with `isIssueIdentifier`: an identifier still has to be resolved to a real
+ * issue before it can be rendered as a chip.
+ */
+ id: string;
+ /**
+ * Workspace slug the link names, or `null` for the slug-less legacy form
+ * (`/projects/<uuid>`), which `openLink` resolves against the current
+ * workspace. A caller that renders workspace-scoped data MUST compare a
+ * non-null slug against the current one — the entity itself is only
+ * resolvable inside the workspace that owns it.
+ */
+ slug: string | null;
+}
+
+const ENTITY_ROUTE_SEGMENTS: Record<string, WorkspaceEntityRef["kind"]> = {
+ issues: "issue",
+ projects: "project",
+};
+
+const UUID_RE =
+ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
+
+/**
+ * Does this path segment address one entity of `kind`?
+ *
+ * A project is only ever addressed by UUID — it has no shorthand. An issue has
+ * both, and the identifier form is the one that matters most: `copyLink` and
+ * `openInNewTab` both build `paths.issueDetail(identifier || id)`, and the
+ * issue route rewrites a UUID URL back to the identifier, so `MUL-123` is what
+ * a user actually copies out of the app or the address bar. Accepting only the
+ * UUID here would leave the shape people really paste as a raw URL.
+ *
+ * Identifier-shaped ids are candidates, not hits: the caller resolves one
+ * against the current workspace and keeps the plain link when it misses.
+ */
+function isEntityId(kind: WorkspaceEntityRef["kind"], id: string): boolean {
+ return UUID_RE.test(id) || (kind === "issue" && isIssueIdentifier(id));
+}
+
+function decodeSegment(segment: string): string | null {
+ try {
+ return decodeURIComponent(segment);
+ } catch {
+ return null;
+ }
+}
+
+/**
+ * Stand-in origin for resolving a href that carries no origin of its own. The
+ * `.invalid` TLD is reserved as permanently unresolvable (RFC 2606), so no
+ * deployment can ever be served from it and no href can use it to pass as one.
+ */
+const RELATIVE_BASE = "https://link.invalid";
+
+/**
+ * Resolve a link to the path it addresses on THIS deployment; `null` when it
+ * addresses anywhere else.
+ *
+ * Resolving through `URL` rather than testing the string is what makes the
+ * answer trustworthy. A leading slash does not mean "this site":
+ * `//other.example/x` and `/\other.example/x` both start with one and both name
+ * another host, which is where a browser goes. A parser sees the host; a prefix
+ * test cannot, and no amount of extra prefixes closes the gap — that is why the
+ * shape of this check matters more than the cases it currently rejects.
+ *
+ * With no `appOrigin` (a platform that cannot report one), only a genuinely
+ * relative href resolves: anything carrying a host of its own fails the
+ * comparison, which is the safe direction.
+ */
+function toSameOriginPath(
+ href: string,
+ appOrigin?: string | null,
+): string | null {
+ const base = appOrigin || RELATIVE_BASE;
+ let target: URL;
+ let expected: URL;
+ try {
+ target = new URL(href, base);
+ expected = new URL(base);
+ } catch {
+ return null;
+ }
+ // Opaque origins (`javascript:`, `data:`) stringify to "null" and can never
+ // equal a real one, so they fall out here too.
+ if (target.origin !== expected.origin) return null;
+ return `${target.pathname}${target.search}${target.hash}`;
+}
+
+/**
+ * Parse a link that addresses exactly one issue or project page on this
+ * deployment; `null` for everything else — external URLs, list pages, deeper
+ * routes, and links carrying a query string or fragment.
+ *
+ * Accepts a site-relative path and an absolute URL pointing back at this
+ * deployment's app origin. Both go through the same origin comparison, so the
+ * two forms cannot disagree about what counts as in-app.
+ */
+export function parseWorkspaceEntityLink(
+ href: string,
+ appOrigin?: string | null,
+): WorkspaceEntityRef | null {
+ const path = toSameOriginPath(href, appOrigin);
+ if (!path) return null;
+ // A query string or fragment addresses something more specific than the
+ // entity page (a saved filter, an anchored comment). Collapsing that to a
+ // plain entity reference would silently drop it.
+ if (path.includes("?") || path.includes("#")) return null;
+
+ const segments: string[] = [];
+ for (const raw of path.split("/").filter(Boolean)) {
+ const decoded = decodeSegment(raw);
+ if (decoded === null) return null;
+ segments.push(decoded);
+ }
+
+ // `/{slug}/{route}/{id}` — what every in-app "copy link" produces.
+ // `/{route}/{id}` — slug-less legacy content, current-workspace by
+ // definition since `openLink` prepends the current slug to it.
+ let slug: string | null;
+ let route: string | undefined;
+ let id: string | undefined;
+ if (segments.length === 3) {
+ const [first, second, third] = segments;
+ if (!first || isReservedSlug(first.toLowerCase())) return null;
+ slug = first;
+ route = second;
+ id = third;
+ } else if (segments.length === 2) {
+ slug = null;
+ [route, id] = segments;
+ } else {
+ return null;
+ }
+
+ const kind = route ? ENTITY_ROUTE_SEGMENTS[route] : undefined;
+ if (!kind || !id || !isEntityId(kind, id)) return null;
+ return { kind, id, slug };
+}
+
/**
* Open a link — internal paths dispatch multica:navigate, external open new tab.
*
diff --git a/packages/views/issues/components/issue-mention-card.tsx b/packages/views/issues/components/issue-mention-card.tsx
index ff26729b54..3fd88804c7 100644
--- a/packages/views/issues/components/issue-mention-card.tsx
+++ b/packages/views/issues/components/issue-mention-card.tsx
@@ -27,7 +27,7 @@ export function IssueMentionCard({ issueId, fallbackLabel }: IssueMentionCardPro
href={p.issueDetail(issueId)}
target={openInNewTab ? "_blank" : undefined}
newTabTitle={fallbackLabel}
- className="issue-mention not-prose align-middle"
+ className="issue-mention align-middle"
>
<IssueChip
issueId={issueId}
diff --git a/packages/views/projects/components/index.ts b/packages/views/projects/components/index.ts
index 9f4fab9485..dcc12f8490 100644
--- a/packages/views/projects/components/index.ts
+++ b/packages/views/projects/components/index.ts
@@ -2,4 +2,5 @@ export { ProjectsPage } from "./projects-page";
export { ProjectDetail } from "./project-detail";
export { ProjectPicker } from "./project-picker";
export { ProjectChip } from "./project-chip";
+export { ProjectMentionCard } from "./project-mention-card";
export { LocalDirectoryHint } from "./local-directory-hint";
diff --git a/packages/views/projects/components/project-mention-card.tsx b/packages/views/projects/components/project-mention-card.tsx
new file mode 100644
index 0000000000..5c6281227c
--- /dev/null
+++ b/packages/views/projects/components/project-mention-card.tsx
@@ -0,0 +1,52 @@
+"use client";
+
+import { AppLink } from "../../navigation";
+import { useWorkspacePaths } from "@multica/core/paths";
+import { ProjectChip } from "./project-chip";
+
+interface ProjectMentionCardProps {
+ projectId: string;
+ /** Fallback text when the project is not resolvable (e.g. its title). */
+ fallbackLabel?: string;
+}
+
+/**
+ * Navigable chip — wraps ProjectChip in an AppLink pointing at the project's
+ * detail page. Counterpart of IssueMentionCard, and deliberately shaped like
+ * it: `ProjectChip` is presentational, so whatever wraps it decides that a
+ * mention is a link, and that decision belongs in one place.
+ *
+ * It was in none until now — the wrapper lived inline in the readonly
+ * renderer — and the cost showed up as gaps that landed on project mentions
+ * alone: `.project-mention` never got the CSS rule cancelling generic link
+ * chrome, and the link hover card never learned to skip it. A named component
+ * is where the next such rule has somewhere obvious to go.
+ *
+ * Rendered as a real anchor: a mention must be reachable by Tab, activatable by
+ * Enter, and expose a URL to copy or open in a new tab. A `<span onClick>`
+ * looks identical and works for a mouse, which is exactly why that regression
+ * is easy to miss (see project-mention-a11y.test.tsx).
+ *
+ * AppLink owns plain-click, modifier-click and the desktop new-tab adapter, so
+ * none of that is reimplemented here. Unlike an issue there is no "open in new
+ * tab" preference to honour — that setting is scoped to issue links.
+ */
+export function ProjectMentionCard({
+ projectId,
+ fallbackLabel,
+}: ProjectMentionCardProps) {
+ const p = useWorkspacePaths();
+ return (
+ <AppLink
+ href={p.projectDetail(projectId)}
+ newTabTitle={fallbackLabel}
+ className="project-mention inline-flex"
+ >
+ <ProjectChip
+ projectId={projectId}
+ fallbackLabel={fallbackLabel}
+ className="cursor-pointer hover:bg-accent transition-colors"
+ />
+ </AppLink>
+ );
+}
diff --git a/packages/views/rich-content/entity-link-unfurl.test.tsx b/packages/views/rich-content/entity-link-unfurl.test.tsx
new file mode 100644
index 0000000000..bce5c281c7
--- /dev/null
+++ b/packages/views/rich-content/entity-link-unfurl.test.tsx
@@ -0,0 +1,195 @@
+/**
+ * Bare in-app entity URLs render as chips (MUL-5499).
+ *
+ * A project has no `MUL-123` shorthand — only a UUID and a free-text title — so
+ * the link copied out of the app IS how people reference one. This fixture pins
+ * the three conditions that decide whether such a link becomes a chip, because
+ * each of them fails silently: an over-eager rule eats an author's link label,
+ * and a cross-workspace unfurl replaces a working link with a chip that can
+ * never resolve.
+ *
+ * The real RichLink / preprocessing pipeline is exercised; only the chips
+ * themselves are stubbed, so the assertions are about which branch the renderer
+ * took, not about chip internals.
+ */
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { render } from "@testing-library/react";
+import { NavigationProvider } from "../navigation/context";
+import type { NavigationAdapter } from "../navigation/types";
+import type { Issue } from "@multica/core/types";
+
+// Identifier → issue lookup, set per test. `null` is the honest default: a
+// miss, a still-loading query and a cross-workspace identifier all look the
+// same to the renderer.
+let resolvedIssue: Issue | null = null;
+
+vi.mock("../issues/hooks", () => ({
+ useResolveIssueIdentifier: () => resolvedIssue,
+}));
+
+beforeEach(() => {
+ resolvedIssue = null;
+});
+
+vi.mock("../i18n", async () => {
+ const editor = (await import("../locales/en/editor.json")).default;
+ return {
+ useT: () => ({
+ t: (select: (bundle: typeof editor) => string) => select(editor),
+ }),
+ useTimeAgo: () => "just now",
+ };
+});
+
+vi.mock("@multica/core/api", () => ({
+ api: { getAttachmentTextContent: vi.fn() },
+ PreviewTooLargeError: class extends Error {},
+ PreviewUnsupportedError: class extends Error {},
+}));
+
+// Partial mock: only the workspace-context hooks are stubbed. The pure path
+// helpers (isReservedSlug / isGlobalPath) stay real — the URL parser under test
+// depends on the same reserved-slug list the backend enforces, and stubbing it
+// would make the assertions meaningless.
+vi.mock("@multica/core/paths", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@multica/core/paths")>()),
+ useWorkspacePaths: () => ({
+ issueDetail: (id: string) => `/acme/issues/${id}`,
+ projectDetail: (id: string) => `/acme/projects/${id}`,
+ }),
+ useWorkspaceSlug: () => "acme",
+}));
+
+vi.mock("../issues/components/issue-mention-card", () => ({
+ IssueMentionCard: ({ issueId }: { issueId: string }) => (
+ <span data-testid="issue-chip">{issueId}</span>
+ ),
+}));
+
+vi.mock("../projects/components/project-chip", () => ({
+ ProjectChip: ({ projectId }: { projectId: string }) => (
+ <span data-testid="project-chip">{projectId}</span>
+ ),
+}));
+
+vi.mock("../editor/link-hover-card", () => ({
+ useLinkHover: () => ({}),
+ LinkHoverCard: () => null,
+}));
+
+import { RichContent } from "./rich-content";
+
+const APP_ORIGIN = "https://app.multica.ai";
+const PROJECT_ID = "8f14e45f-ceea-4d0e-a1a2-9b1c0d3e4f5a";
+const ISSUE_ID = "1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed";
+
+function adapter(): NavigationAdapter {
+ return {
+ push: vi.fn(),
+ replace: vi.fn(),
+ back: vi.fn(),
+ pathname: "/",
+ searchParams: new URLSearchParams(),
+ // The real platform adapters return an absolute URL; useAppOrigin derives
+ // the deployment origin from it, and without that nothing is "in-app".
+ getShareableUrl: (p) => `${APP_ORIGIN}${p}`,
+ };
+}
+
+function renderContent(content: string) {
+ return render(
+ <NavigationProvider value={adapter()}>
+ <RichContent content={content} />
+ </NavigationProvider>,
+ );
+}
+
+describe("bare entity URLs in readonly content", () => {
+ it("renders a pasted project URL as a project chip linking to the project", () => {
+ const { container, getByTestId } = renderContent(
+ `Tracked under ${APP_ORIGIN}/acme/projects/${PROJECT_ID} for now.`,
+ );
+
+ expect(getByTestId("project-chip").textContent).toBe(PROJECT_ID);
+ expect(
+ container.querySelector(`a[href="/acme/projects/${PROJECT_ID}"]`),
+ ).not.toBeNull();
+ });
+
+ it("renders a pasted issue URL as an issue chip", () => {
+ const { getByTestId } = renderContent(
+ `See ${APP_ORIGIN}/acme/issues/${ISSUE_ID} for context.`,
+ );
+
+ expect(getByTestId("issue-chip").textContent).toBe(ISSUE_ID);
+ });
+
+ // The identifier form — NOT the UUID one — is what leaves the app:
+ // `copyLink` and `openInNewTab` build `paths.issueDetail(identifier || id)`,
+ // and the issue route rewrites a UUID URL back to the identifier, so this is
+ // the shape in the address bar too.
+ it("renders a pasted identifier-form issue URL as an issue chip", () => {
+ resolvedIssue = { id: ISSUE_ID, identifier: "MUL-1" } as Issue;
+
+ const { getByTestId } = renderContent(
+ `Blocked by ${APP_ORIGIN}/acme/issues/MUL-1 for now.`,
+ );
+
+ expect(getByTestId("issue-chip").textContent).toBe(ISSUE_ID);
+ });
+
+ it("keeps the link when an identifier-form issue URL resolves to nothing", () => {
+ // A miss means the issue is gone or lives in a workspace this user cannot
+ // see. The autolink path degrades to plain text there; a URL must not —
+ // the author wrote a link, and dropping it would strip the only pointer.
+ const { container, queryByTestId } = renderContent(
+ `${APP_ORIGIN}/acme/issues/MUL-404`,
+ );
+
+ expect(queryByTestId("issue-chip")).toBeNull();
+ expect(
+ container.querySelector(`a[href="${APP_ORIGIN}/acme/issues/MUL-404"]`),
+ ).not.toBeNull();
+ });
+
+ it("leaves a link the author labelled alone", () => {
+ // Replacing this with a chip would throw away "Roadmap" — the author said
+ // what they wanted the link to read as.
+ const { container, queryByTestId } = renderContent(
+ `[Roadmap](${APP_ORIGIN}/acme/projects/${PROJECT_ID})`,
+ );
+
+ expect(queryByTestId("project-chip")).toBeNull();
+ const anchor = container.querySelector("a");
+ expect(anchor?.textContent).toBe("Roadmap");
+ });
+
+ it("leaves a link into another workspace as a plain link", () => {
+ // The chip resolves its title in the CURRENT workspace, so unfurling here
+ // would swap a working link for a permanently empty chip.
+ const { container, queryByTestId } = renderContent(
+ `${APP_ORIGIN}/other-ws/projects/${PROJECT_ID}`,
+ );
+
+ expect(queryByTestId("project-chip")).toBeNull();
+ expect(
+ container.querySelector(
+ `a[href="${APP_ORIGIN}/other-ws/projects/${PROJECT_ID}"]`,
+ ),
+ ).not.toBeNull();
+ });
+
+ it("leaves a project list URL as a plain link", () => {
+ const { queryByTestId } = renderContent(`${APP_ORIGIN}/acme/projects`);
+ expect(queryByTestId("project-chip")).toBeNull();
+ });
+
+ it("leaves an external URL as a plain link", () => {
+ const { queryByTestId, container } = renderContent(
+ `https://github.com/multica-ai/multica/pull/1`,
+ );
+ expect(queryByTestId("project-chip")).toBeNull();
+ expect(queryByTestId("issue-chip")).toBeNull();
+ expect(container.querySelector("a")).not.toBeNull();
+ });
+});
diff --git a/packages/views/rich-content/rich-content.tsx b/packages/views/rich-content/rich-content.tsx
index 6ea121bdb9..9f0f469666 100644
--- a/packages/views/rich-content/rich-content.tsx
+++ b/packages/views/rich-content/rich-content.tsx
@@ -39,7 +39,7 @@ import remarkMath from "remark-math";
import rehypeRaw from "rehype-raw";
import rehypeSanitize from "rehype-sanitize";
import { cn } from "@multica/ui/lib/utils";
-import { useWorkspacePaths, useWorkspaceSlug } from "@multica/core/paths";
+import { useWorkspaceSlug } from "@multica/core/paths";
import { useConfigStore } from "@multica/core/config";
import type { Attachment } from "@multica/core/types";
import {
@@ -48,12 +48,17 @@ import {
markdownSanitizeSchema,
markdownUrlTransform,
} from "@multica/ui/markdown";
-import { AppLink, useAppOrigin } from "../navigation";
+import { useAppOrigin } from "../navigation";
import { IssueMentionCard } from "../issues/components/issue-mention-card";
import { useResolveIssueIdentifier } from "../issues/hooks";
-import { ProjectChip } from "../projects/components/project-chip";
+import { ProjectMentionCard } from "../projects/components/project-mention-card";
import { useLinkHover, LinkHoverCard } from "../editor/link-hover-card";
-import { openLink, isMentionHref } from "../editor/utils/link-handler";
+import {
+ openLink,
+ isMentionHref,
+ parseWorkspaceEntityLink,
+ type WorkspaceEntityRef,
+} from "../editor/utils/link-handler";
import { preprocessMarkdown } from "../editor/utils/preprocess";
import { highlightToHtml } from "../editor/utils/highlight-markdown";
import { AttachmentDownloadProvider } from "../editor/attachment-download-context";
@@ -111,46 +116,43 @@ function IssueMentionLink({ issueId, label }: { issueId: string; label?: string
}
/**
- * Autolinked bare identifier (e.g. `MUL-123`) routed through
- * `mention://issue/<identifier>` by the preprocessor. Resolves to a real issue
- * in the current workspace; renders a navigable mention on a hit, plain text on
- * a miss / while loading / cross-workspace.
+ * An issue addressed by identifier (e.g. `MUL-123`) rather than by UUID.
+ * Resolves it against the current workspace and renders a navigable mention on
+ * a hit.
+ *
+ * Two entry points reach this, and they need DIFFERENT misses, which is why the
+ * fallback is a prop rather than baked in:
+ * - the autolink preprocessor, which routes bare prose through
+ * `mention://issue/<identifier>` — a miss must go back to being the plain
+ * text the author typed;
+ * - a bare in-app issue URL, whose miss must stay the original anchor. The
+ * author wrote a link; degrading it to text would strip a working link off
+ * an issue this workspace simply cannot see.
+ *
+ * A miss covers not-found, still-loading, and cross-workspace alike.
*/
-function AutolinkedIssueMentionLink({ identifier }: { identifier: string }) {
+function IdentifierIssueMentionLink({
+ identifier,
+ fallback,
+}: {
+ identifier: string;
+ fallback: ReactNode;
+}) {
const issue = useResolveIssueIdentifier(identifier);
- if (!issue) return <>{identifier}</>;
+ if (!issue) return <>{fallback}</>;
return <IssueMentionLink issueId={issue.id} label={identifier} />;
}
/**
- * Project mention chip.
- *
- * Rendered as a real anchor via AppLink, matching IssueMentionCard: a mention is
- * a link, so it must be reachable by Tab and activatable by Enter, and expose a
- * URL to copy / open in a new tab. A `<span onClick>` looks identical and works
- * for a mouse, which is exactly why the regression is easy to miss — the readonly
- * renderer used one, and unifying the surfaces would have propagated it to Chat,
- * which previously had the accessible version.
- *
- * AppLink also owns plain-click, modifier-click and the desktop new-tab adapter,
- * so none of that is reimplemented here. The wrapper only shields surrounding
- * click handlers (e.g. collapsed-comment expanders) from mention clicks.
+ * Project mention chip. Navigation and accessibility are owned by the AppLink
+ * inside ProjectMentionCard; the wrapper only shields surrounding click
+ * handlers (e.g. collapsed-comment expanders) from mention clicks — the same
+ * shape as IssueMentionLink above.
*/
function ProjectMentionLink({ projectId, label }: { projectId: string; label?: string }) {
- const p = useWorkspacePaths();
return (
<span className="inline align-middle" onClick={(e) => e.stopPropagation()}>
- <AppLink
- href={p.projectDetail(projectId)}
- newTabTitle={label}
- className="project-mention not-prose inline-flex"
- >
- <ProjectChip
- projectId={projectId}
- fallbackLabel={label}
- className="cursor-pointer hover:bg-accent transition-colors"
- />
- </AppLink>
+ <ProjectMentionCard projectId={projectId} fallbackLabel={label} />
</span>
);
}
@@ -161,6 +163,40 @@ function childrenToLabel(children: ReactNode): string | undefined {
return undefined;
}
+/**
+ * Decide whether a link should render as an entity chip instead of a raw URL.
+ *
+ * Pasting a link copied out of the app is how people reference a project:
+ * projects carry only a UUID and a free-text title, so unlike an issue they have
+ * no `MUL-123` shorthand for the autolink preprocessor to detect — the URL IS
+ * the reference. Rendering it as the same chip the `mention://project/<uuid>`
+ * form produces closes that gap without inventing a new text form. Issue URLs
+ * go through the same path for symmetry.
+ *
+ * Three conditions, each load-bearing:
+ * - BARE: the visible text is the URL itself, which is what the linkify
+ * preprocessor emits for a pasted URL. `[路线图](…/projects/<id>)` carries a
+ * label the author chose, and replacing it with a chip would discard it.
+ * - SAME WORKSPACE: a chip resolves its title against the CURRENT workspace,
+ * so unfurling a link into another workspace would turn a working link into
+ * a permanently empty chip. A slug-less path is current-workspace already.
+ * - Whatever `parseWorkspaceEntityLink` enforces: an exact entity route, an id
+ * that addresses one entity (a UUID, or an issue identifier), and no query
+ * string or fragment.
+ */
+function unfurlableEntityLink(
+ href: string,
+ children: ReactNode,
+ currentSlug: string | null,
+ appOrigin: string | null,
+): WorkspaceEntityRef | null {
+ if (childrenToLabel(children) !== href) return null;
+ const entity = parseWorkspaceEntityLink(href, appOrigin);
+ if (!entity) return null;
+ if (entity.slug !== null && entity.slug !== currentSlug) return null;
+ return entity;
+}
+
function RichLink({ href, children }: { href?: string; children?: ReactNode }) {
const slug = useWorkspaceSlug();
const appOrigin = useAppOrigin();
@@ -175,7 +211,12 @@ function RichLink({ href, children }: { href?: string; children?: ReactNode }) {
// A bare identifier (from the autolink preprocessor) is carried as the id
// segment; a real mention carries a UUID. Dispatch on the id shape.
if (isIssueIdentifier(match[2])) {
- return <AutolinkedIssueMentionLink identifier={match[2]} />;
+ return (
+ <IdentifierIssueMentionLink
+ identifier={match[2]}
+ fallback={match[2]}
+ />
+ );
}
return <IssueMentionLink issueId={match[2]} label={childrenToLabel(children)} />;
}
@@ -186,9 +227,11 @@ function RichLink({ href, children }: { href?: string; children?: ReactNode }) {
return <span className="mention">{children}</span>;
}
- // Regular links — open directly on click. A URL pointing back at this
- // deployment routes in-app rather than out to the browser.
- return (
+ // Regular link — open directly on click. A URL pointing back at this
+ // deployment routes in-app rather than out to the browser. Built first
+ // because it is also what an unfurl falls back to when the entity behind the
+ // URL cannot be resolved.
+ const plainLink = (
<a
href={href}
onClick={(e) => {
@@ -199,6 +242,25 @@ function RichLink({ href, children }: { href?: string; children?: ReactNode }) {
{children}
</a>
);
+
+ // A bare in-app entity URL renders as the chip its mention form would.
+ const entity = href
+ ? unfurlableEntityLink(href, children, slug, appOrigin)
+ : null;
+ if (entity?.kind === "issue") {
+ // `MUL-123` is the shape "Copy link" produces, so it is the shape most
+ // pasted issue URLs carry; it needs a lookup, and keeps the link on a miss.
+ return isIssueIdentifier(entity.id) ? (
+ <IdentifierIssueMentionLink identifier={entity.id} fallback={plainLink} />
+ ) : (
+ <IssueMentionLink issueId={entity.id} />
+ );
+ }
+ if (entity?.kind === "project") {
+ return <ProjectMentionLink projectId={entity.id} />;
+ }
+
+ return plainLink;
}
// ---------------------------------------------------------------------------
diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.go
index e2f0e4d3d7..b99ea0267a 100644
--- a/server/internal/daemon/execenv/runtime_config_sections.go
+++ b/server/internal/daemon/execenv/runtime_config_sections.go
@@ -583,6 +583,10 @@ func writeMentions(b *strings.Builder) {
b.WriteString("## Mentions\n\n")
b.WriteString("Mention links are **side-effecting actions**:\n\n")
b.WriteString("- `[MUL-123](mention://issue/<issue-id>)` — clickable link (no side effect)\n")
+ // Projects have no `MUL-123`-style identifier to autolink, so unless the
+ // agent writes this form (or pastes the project URL, which the reader's
+ // client unfurls into the same chip) a project reference stays dead text.
+ b.WriteString("- `[Project Name](mention://project/<project-id>)` — clickable link (no side effect)\n")
b.WriteString("- `[@Name](mention://member/<user-id>)` — **notifies a human**\n")
b.WriteString("- `[@Name](mention://agent/<agent-id>)` — **enqueues a new run for that agent**\n\n")
b.WriteString("### When NOT to use a mention link\n\n")
diff --git a/server/internal/service/builtin_skills/multica-mentioning/SKILL.md b/server/internal/service/builtin_skills/multica-mentioning/SKILL.md
index 7ce4ef1401..af634c7ea2 100644
--- a/server/internal/service/builtin_skills/multica-mentioning/SKILL.md
+++ b/server/internal/service/builtin_skills/multica-mentioning/SKILL.md
@@ -32,6 +32,15 @@ So the link target is a real entity UUID (or `all`), never a display name. The
label between the brackets is free text — that is where the human-readable name
goes.
+One `mention://` form deliberately sits OUTSIDE this parser:
+`[Label](mention://project/<uuid>)`. `project` is absent from the type group
+above, so the backend never parses it and it can enqueue nothing — it is a
+render-only link every client makes navigable (a chip on web and desktop, an
+ordinary link that opens the project on tap on mobile). That is the whole point:
+a project reference should never be able to start a run. Use it freely to point
+at a project (see the multica-projects-and-resources skill); everything else in
+this document is about the four types (plus `all`) the parser does recognize.
+
## Step 1 — look up the UUID with `--output json`
A name is not a UUID. Look the UUID up first, from the matching list command:
diff --git a/server/internal/service/builtin_skills/multica-mentioning/references/mentioning-source-map.md b/server/internal/service/builtin_skills/multica-mentioning/references/mentioning-source-map.md
index c05516a4c3..f85153a607 100644
--- a/server/internal/service/builtin_skills/multica-mentioning/references/mentioning-source-map.md
+++ b/server/internal/service/builtin_skills/multica-mentioning/references/mentioning-source-map.md
@@ -15,6 +15,7 @@ a pointer.
| `ParseMentions` extracts and dedups `{Type, ID}` from `m[2]`/`m[3]` | `server/internal/util/mention.go:24-37` |
| `Mention.Type` doc enum = "member", "agent", "issue", or "all" (squad added in regex) | `server/internal/util/mention.go:7` |
| `HasMentionAll` reports whether any parsed mention is `all` | `server/internal/util/mention.go:40-47` |
+| **`project` is NOT in the type group** — `[Label](mention://project/<uuid>)` never parses, so it can enqueue nothing. It is a render-only link every client makes navigable — a chip on web/desktop (`RichLink` in `packages/views/rich-content/rich-content.tsx`), an ordinary enriched link whose tap is routed on mobile (`onLinkPress` in `apps/mobile/lib/markdown/markdown.tsx`, which renders no chip) | `server/internal/util/mention.go:16` |
### Parser behavior tests (pin the example shapes the skill uses)
diff --git a/server/internal/service/builtin_skills/multica-projects-and-resources/SKILL.md b/server/internal/service/builtin_skills/multica-projects-and-resources/SKILL.md
index 1a0563a5f0..bc663ec423 100644
--- a/server/internal/service/builtin_skills/multica-projects-and-resources/SKILL.md
+++ b/server/internal/service/builtin_skills/multica-projects-and-resources/SKILL.md
@@ -55,6 +55,26 @@ For `github_repo`, non-JSON `--ref` sets `resource_ref.ref`, the default checkou
`--start-date` / `--due-date` are optional calendar days (`YYYY-MM-DD`, like issue dates). On `project update`, pass an empty string (`--start-date ""`) to clear a date; an unset flag leaves it untouched.
+## Referring to a project in a comment
+
+A project has no `MUL-123`-style identifier, so writing its title as prose
+produces dead text — there is nothing for the reader's client to autolink. Use
+the mention-link form instead, with the project UUID from
+`multica project list --output json`:
+
+ [Roadmap](mention://project/<project-id>)
+
+Every client makes it navigable, with different presentation: web and desktop
+render a chip carrying the project's icon and current title, while mobile
+renders an ordinary link that opens the project on tap. Unlike `@agent` /
+`@squad`, it is a pure link: `util.MentionRe` does not even include `project`,
+so it enqueues nothing and notifies nobody — the same no-side-effect contract
+as an `issue` mention.
+
+Prefer this form over pasting the project's URL. Web and desktop do unfurl a
+bare in-app project URL into that same chip, but mobile does not — there a
+pasted URL is handed to the system browser and takes the reader out of the app.
+
## When to add a resource
Add/update a project resource when the user asks for durable project context: "把这个 GitHub repo 绑到项目上", "以后都用这个 repo", "agent 总是拿不到这个项目的仓库", or "这个项目要在我的本地目录里跑".
diff --git a/server/internal/service/builtin_skills/multica-projects-and-resources/references/projects-and-resources-source-map.md b/server/internal/service/builtin_skills/multica-projects-and-resources/references/projects-and-resources-source-map.md
index b488bfbdf4..ca9b17990e 100644
--- a/server/internal/service/builtin_skills/multica-projects-and-resources/references/projects-and-resources-source-map.md
+++ b/server/internal/service/builtin_skills/multica-projects-and-resources/references/projects-and-resources-source-map.md
@@ -10,4 +10,5 @@
- `server/pkg/db/queries/project_resource.sql` is the CRUD query surface for `project_resource` rows.
- Project resources are written into `.multica/project/resources.json` for agent workdirs.
- `github_repo.resource_ref.ref` is lifted into daemon `RepoData.Ref` by `server/internal/handler/daemon.go`; `server/internal/daemon/daemon.go` stores it per task, and `server/internal/daemon/health.go` uses it as the default `/repo/checkout` ref when the checkout request does not explicitly pass one.
+- Referring to a project in a comment: `[Label](mention://project/<uuid>)` is a render-only link. `util.MentionRe` (`server/internal/util/mention.go`) does NOT include `project` in its type group, so the backend never parses it and it can enqueue nothing — deliberately weaker than `agent` / `squad`. Presentation differs by client and the skill says so: web and desktop render a chip in `RichLink` (`packages/views/rich-content/rich-content.tsx`) and the editor's `MentionView` (`packages/views/editor/extensions/mention-view.tsx`), while mobile has no chip — `apps/mobile/lib/markdown/markdown.tsx` leaves the default enriched-link styling and only routes the tap (`onLinkPress`). Unfurling a bare in-app project/issue URL is web/desktop only, via `parseWorkspaceEntityLink` (`packages/views/editor/utils/link-handler.ts`), which requires same origin (resolved through `URL`, not a prefix test), no query/fragment, the current workspace slug, and an id that addresses one entity — a UUID, or an issue identifier (`MUL-123`), which is the form `copyLink` produces and which falls back to the plain link when it resolves to nothing (MUL-5499). On mobile a bare URL still goes to `Linking.openURL`. The agent-facing line lives in the runtime brief's Mentions section (`writeMentions`, `server/internal/daemon/execenv/runtime_config_sections.go`).
- A project's `description` is injected as durable context for every task in the project. The claim handler (`server/internal/handler/daemon.go`) reads `proj.Description` onto the claim response (`ProjectDescription`, `server/internal/handler/agent.go`); the daemon carries it through `Task` (`server/internal/daemon/types.go`) and `TaskContextForEnv` (`server/internal/daemon/execenv/execenv.go`) into the brief's `## Project Context` section (`server/internal/daemon/execenv/runtime_config.go`) and into `.multica/project/resources.json` as `project_description` (`server/internal/daemon/execenv/context.go`).