Skip to content

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

Go

feat(desktop): open chat sessions from multica://open/chat links (#11351)

kevinca4beda6099e
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 843bb80601..d5043a479b 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -341,7 +341,11 @@ function handleDeepLink(url: string): void {
return;
}
- if (parsed.hostname === "open" && parsed.pathname === "/issue") {
+ // multica://open/issue?url=… and multica://open/chat?url=…
+ if (
+ parsed.hostname === "open" &&
+ (parsed.pathname === "/issue" || parsed.pathname === "/chat")
+ ) {
// Keep the source instance in the payload. The authenticated renderer
// validates it against runtime config before opening a workspace tab.
dispatchToMainRenderer("issue:open", url);
diff --git a/apps/desktop/src/renderer/src/platform/issue-deep-link-bridge.test.tsx b/apps/desktop/src/renderer/src/platform/issue-deep-link-bridge.test.tsx
index 4184887ca3..169ea19eb5 100644
--- a/apps/desktop/src/renderer/src/platform/issue-deep-link-bridge.test.tsx
+++ b/apps/desktop/src/renderer/src/platform/issue-deep-link-bridge.test.tsx
@@ -118,6 +118,24 @@ describe("IssueDeepLinkBridge", () => {
expect(useTabStore.getState().byWorkspace[slug]!.tabs).toHaveLength(tabCount);
});
+ it("opens a chat session by link, reusing the open chat tab without adding another", () => {
+ const chatLink = (path: string) =>
+ `multica://open/chat?url=${encodeURIComponent(`https://tasks.example${path}`)}`;
+ useTabStore.getState().openTab("/acme/chat?session=s-old", "", { activate: true });
+ const chatTab = getActiveTab(useTabStore.getState())!;
+ useTabStore.getState().openTab("/acme/issues/ACM-1", "", { activate: true });
+ const tabCount = useTabStore.getState().byWorkspace.acme!.tabs.length;
+ render(ui());
+
+ act(() => receive!(chatLink("/acme/chat?session=s-new")));
+ act(() => receive!(chatLink("/acme/chat?session=s-new")));
+
+ const current = getActiveTab(useTabStore.getState())!;
+ expect(current.id).toBe(chatTab.id);
+ expect(current.url).toBe("/acme/chat?session=s-new");
+ expect(useTabStore.getState().byWorkspace.acme!.tabs).toHaveLength(tabCount);
+ });
+
it("applies the new comment in the workspace's existing window without moving the source", () => {
const oldPath = "/other/issues/OTH-2#comment-old";
const newPath = "/other/issues/OTH-2#comment-new";
diff --git a/apps/desktop/src/renderer/src/platform/navigation.tsx b/apps/desktop/src/renderer/src/platform/navigation.tsx
index 2b56bf2bb0..f99b8d74ae 100644
--- a/apps/desktop/src/renderer/src/platform/navigation.tsx
+++ b/apps/desktop/src/renderer/src/platform/navigation.tsx
@@ -133,7 +133,10 @@ export function routeContentLinkPath(
store.openTab(path, "", { activate: disposition === "foreground-tab" });
}
-/** A desktop deep link explicitly targets its URL, including a new comment. */
+/**
+ * A desktop deep link (an issue or a chat session) explicitly targets its URL,
+ * including a new comment or the chat session to select.
+ */
export function routeIssueDeepLinkPath(path: string): void {
const store = useTabStore.getState();
const slug = workspaceSlugForPath(path);
diff --git a/apps/desktop/src/shared/issue-deep-link.test.ts b/apps/desktop/src/shared/issue-deep-link.test.ts
index e4f6771d53..5d6185cd88 100644
--- a/apps/desktop/src/shared/issue-deep-link.test.ts
+++ b/apps/desktop/src/shared/issue-deep-link.test.ts
@@ -48,3 +48,43 @@ describe("parseIssueDeepLink", () => {
expect(parseIssueDeepLink(url, "https://tasks.example")).toBeNull();
});
});
+
+const chatLink = (url: string) => `multica://open/chat?url=${encodeURIComponent(url)}`;
+
+describe("parseIssueDeepLink for chats", () => {
+ it("opens the chat session named in the link", () => {
+ expect(parseIssueDeepLink(chatLink("https://tasks.example/acme/chat?session=01a1f1b6-b59b-7a48-beae-5a459ff72200"), "https://tasks.example")).toEqual({
+ kind: "chat",
+ workspaceSlug: "acme",
+ path: "/acme/chat?session=01a1f1b6-b59b-7a48-beae-5a459ff72200",
+ });
+ });
+
+ it("opens the chat page without a session, behind a base path", () => {
+ expect(parseIssueDeepLink(chatLink("http://localhost:3000/multica/acme/chat"), "http://localhost:3000/multica/")).toEqual({
+ kind: "chat", workspaceSlug: "acme", path: "/acme/chat",
+ });
+ });
+
+ it("keeps only the session from the chat address", () => {
+ expect(parseIssueDeepLink(chatLink("https://tasks.example/acme/chat?session=s-1&agent=a-1#x"), "https://tasks.example")).toEqual({
+ kind: "chat", workspaceSlug: "acme", path: "/acme/chat?session=s-1",
+ });
+ });
+
+ it("rejects a chat on a different instance", () => {
+ expect(parseIssueDeepLink(chatLink("https://other.example/acme/chat?session=s-1"), "https://tasks.example")).toEqual({ kind: "other-instance" });
+ });
+
+ it.each([
+ chatLink("https://tasks.example/acme/issues/ACM-42"),
+ link("https://tasks.example/acme/chat?session=s-1"),
+ chatLink("https://tasks.example/acme/chat/extra"),
+ chatLink("https://tasks.example/acme%2Fevil/chat"),
+ chatLink("https://tasks.example/acme/chat?session=../settings"),
+ chatLink("https://tasks.example/acme/chat?session="),
+ "multica://open/settings?url=https%3A%2F%2Ftasks.example%2Facme%2Fchat",
+ ])("ignores a link whose kind and address do not match: %s", (url) => {
+ expect(parseIssueDeepLink(url, "https://tasks.example")).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/shared/issue-deep-link.ts b/apps/desktop/src/shared/issue-deep-link.ts
index 2103fd9977..0856e4741a 100644
--- a/apps/desktop/src/shared/issue-deep-link.ts
+++ b/apps/desktop/src/shared/issue-deep-link.ts
@@ -1,21 +1,27 @@
import { parseIssueWindowPath } from "./issue-window";
+import { parseWorkspaceSlug } from "./workspace-window";
+/**
+ * `multica://open/issue?url=<issue page URL>` and
+ * `multica://open/chat?url=<chat page URL>`, the links another app uses to
+ * open an issue or a chat session in the desktop app.
+ */
export type IssueDeepLink =
- | { kind: "issue"; workspaceSlug: string; path: string }
+ | { kind: "issue" | "chat"; workspaceSlug: string; path: string }
| { kind: "other-instance" };
-/** Never interpret an issue identifier against a different server. */
+const CHAT_SESSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z-]{0,63}$/;
+
+/** Never interpret an issue identifier or a chat session against a different server. */
export function parseIssueDeepLink(
value: string,
appUrl: string,
): IssueDeepLink | null {
try {
const link = new URL(value);
- if (
- link.protocol !== "multica:" ||
- link.host !== "open" ||
- link.pathname !== "/issue"
- ) return null;
+ if (link.protocol !== "multica:" || link.host !== "open") return null;
+ const kind = link.pathname === "/issue" ? "issue" : link.pathname === "/chat" ? "chat" : null;
+ if (!kind) return null;
const url = new URL(link.searchParams.get("url") ?? "");
if (
!["http:", "https:"].includes(url.protocol) ||
@@ -27,16 +33,33 @@ export function parseIssueDeepLink(
if (url.origin !== app.origin || !url.pathname.startsWith(`${basePath}/`)) {
return { kind: "other-instance" };
}
- const target = parseIssueWindowPath(
- url.pathname.slice(basePath.length) + url.search + url.hash,
- );
+ const appPath = url.pathname.slice(basePath.length) + url.search + url.hash;
+ const target = kind === "issue" ? parseIssueWindowPath(appPath) : parseChatPath(appPath);
if (!target) return null;
- return {
- kind: "issue",
- workspaceSlug: target.workspaceSlug,
- path: target.path,
- };
+ return { kind, workspaceSlug: target.workspaceSlug, path: target.path };
+ } catch {
+ return null;
+ }
+}
+
+/**
+ * `/<workspace>/chat`, optionally with `?session=<id>`. Only the session is
+ * carried over: the chat page reads nothing else from its address.
+ */
+function parseChatPath(value: string): { workspaceSlug: string; path: string } | null {
+ const url = new URL(value, "https://desktop.multica.invalid");
+ if (url.origin !== "https://desktop.multica.invalid") return null;
+ const segments = url.pathname.split("/");
+ if (segments.length !== 3 || segments[0] !== "" || segments[2] !== "chat") return null;
+ let workspaceSlug: string;
+ try {
+ workspaceSlug = decodeURIComponent(segments[1] ?? "");
} catch {
return null;
}
+ if (!parseWorkspaceSlug(workspaceSlug)) return null;
+ const session = url.searchParams.get("session");
+ if (session === null) return { workspaceSlug, path: `/${workspaceSlug}/chat` };
+ if (!CHAT_SESSION_PATTERN.test(session)) return null;
+ return { workspaceSlug, path: `/${workspaceSlug}/chat?session=${session}` };
}