diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a9d917..1fd27cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,15 @@ popover, not for the person who wrote the commit. ## [Unreleased] +## [1.11.4] - 2026-11-05 + +### Added + +- **A `stashpad://stash/…` link opens that stash in the app.** When you ask an AI assistant to + show you a stash, it can now hand you a link instead of copying the whole text into the chat. + Clicking it brings Stashpad forward, switches to the stash's context and scrolls to it. The + link carries only the stash's id, so it shows nothing on a device that doesn't have the stash + ## [1.11.3] - 2026-10-27 ### Fixed diff --git a/package.json b/package.json index 92920f6..96930c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stashpad", - "version": "1.11.3", + "version": "1.11.4", "description": "The staging area for your AI context.", "author": { "name": "Nico Wiedemann", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 47bbca1..dee2b47 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -5557,7 +5557,7 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "stashpad" -version = "1.11.3" +version = "1.11.4" dependencies = [ "active-win-pos-rs", "aes-gcm", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 18a04c5..7b8fd87 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stashpad" -version = "1.11.3" +version = "1.11.4" description = "The staging area for your AI context." authors = ["Nico Wiedemann "] repository = "https://github.com/EarMaster/stashpad" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index b656536..648dbc4 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "stashpad", - "version": "1.11.3", + "version": "1.11.4", "identifier": "org.stashpad", "build": { "frontendDist": "../dist", diff --git a/src/lib/components/Queue.svelte b/src/lib/components/Queue.svelte index ecbde6a..a3d53aa 100644 --- a/src/lib/components/Queue.svelte +++ b/src/lib/components/Queue.svelte @@ -81,6 +81,7 @@ import { liveAttachments } from "$lib/utils/stash-filters"; import { reportError } from "$lib/utils/error-reporting"; import { log } from "$lib/utils/log"; + import { onStashLink } from "$lib/utils/deep-link"; let { transferMode, @@ -655,6 +656,27 @@ revealStash(ref.stash.id); } + /** + * A `stashpad://stash/` link (see `deep-link.ts`). Held until the stash is in the + * list, because a link that launched the app arrives before the first load finishes. + */ + let linkedStashId = $state(null); + + $effect(() => { + const id = linkedStashId; + if (!id) return; + const target = stashes.find((s) => s.id === id && !s.deleted); + if (!target) return; + linkedStashId = null; + const contextId = target.contextId || "default"; + if (contextId !== (untrack(() => currentContextId) || "default")) { + pendingRevealId = id; + onSwitchContext?.(contextId); + return; + } + tick().then(() => revealStash(id)); + }); + async function revealStash(id: string) { const target = stashes.find((s) => s.id === id); if (!target) return; @@ -1036,6 +1058,7 @@ // Tauri drag-drop event listeners for StashCard targeting let unlistenDrop: UnlistenFn | null = null; + let unlistenStashLink: (() => void) | null = null; let unlistenEnter: UnlistenFn | null = null; let unlistenOver: UnlistenFn | null = null; let unlistenLeave: UnlistenFn | null = null; @@ -1043,6 +1066,15 @@ onMount(async () => { window.addEventListener("keydown", handleSearchShortcut); + try { + unlistenStashLink = await onStashLink((id) => { + log.info(`[Queue] Opening stash ${id} from a link`); + linkedStashId = id; + }); + } catch (err) { + log.error("[Queue] Could not listen for stash links:", err); + } + // Listen for Tauri's native drag events to coordinate StashCard drop zones unlistenEnter = await listen<{ position: { x: number; y: number } }>( "tauri://drag-enter", @@ -1124,6 +1156,7 @@ onDestroy(() => { window.removeEventListener("keydown", handleSearchShortcut); + unlistenStashLink?.(); unlistenEnter?.(); unlistenOver?.(); unlistenLeave?.(); diff --git a/src/lib/utils/__tests__/deep-link.test.ts b/src/lib/utils/__tests__/deep-link.test.ts new file mode 100644 index 0000000..9120896 --- /dev/null +++ b/src/lib/utils/__tests__/deep-link.test.ts @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +// Copyright (C) 2026 Nico Wiedemann +// +// This file is part of Stashpad. +// Stashpad is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License, version 3, +// as published by the Free Software Foundation. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Affero General Public License for more details. +import { describe, it, expect, vi, beforeEach } from "vitest"; + +const plugin = vi.hoisted(() => ({ + onOpenUrl: vi.fn(), + getCurrent: vi.fn(), +})); +vi.mock("@tauri-apps/plugin-deep-link", () => plugin); + +import { parseStashLink, onStashLink } from "../deep-link"; + +const ID = "dbbc1f3c-bc08-4c0d-86d7-acb5c935542a"; + +describe("parseStashLink", () => { + it("reads the id from a stash link", () => { + expect(parseStashLink(`stashpad://stash/${ID}`)).toBe(ID); + expect(parseStashLink(`stashpad://stash/${ID}/`)).toBe(ID); + expect(parseStashLink(`stashpad://stash/${ID.toUpperCase()}`)).toBe(ID); + }); + + it("ignores every other link", () => { + expect(parseStashLink("stashpad://auth/callback?token=abc")).toBeNull(); + expect(parseStashLink("stashpad://stash/not-an-id")).toBeNull(); + expect(parseStashLink(`stashpad://stash/${ID}?x=1`)).toBeNull(); + expect(parseStashLink(`https://stashpad.org/stash/${ID}`)).toBeNull(); + }); +}); + +describe("onStashLink", () => { + beforeEach(() => { + plugin.onOpenUrl.mockReset(); + plugin.getCurrent.mockReset(); + }); + + it("hands over the launch link and later ones, and nothing else", async () => { + let later: (urls: string[]) => void = () => {}; + const stop = vi.fn(); + plugin.onOpenUrl.mockImplementation(async (handler) => { + later = handler; + return stop; + }); + plugin.getCurrent.mockResolvedValue([`stashpad://stash/${ID}`]); + + const seen: string[] = []; + const unlisten = await onStashLink((id) => seen.push(id)); + expect(seen).toEqual([ID]); + + later(["stashpad://auth/callback?token=x", `stashpad://stash/${ID}`]); + expect(seen).toEqual([ID, ID]); + + unlisten(); + expect(stop).toHaveBeenCalled(); + }); + + it("still listens when the launch link cannot be read", async () => { + plugin.onOpenUrl.mockResolvedValue(() => {}); + plugin.getCurrent.mockRejectedValue(new Error("no")); + await expect(onStashLink(() => {})).resolves.toBeTypeOf("function"); + }); +}); diff --git a/src/lib/utils/deep-link.ts b/src/lib/utils/deep-link.ts new file mode 100644 index 0000000..719fa36 --- /dev/null +++ b/src/lib/utils/deep-link.ts @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +// Copyright (C) 2026 Nico Wiedemann +// +// This file is part of Stashpad. +// Stashpad is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License, version 3, +// as published by the Free Software Foundation. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Affero General Public License for more details. +import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link"; +import { log } from "$lib/utils/log"; + +/** + * `stashpad://stash/` - open one stash in the app. + * + * The cloud's MCP server hands this link out: `show_stash` returns it to an agent in a + * terminal, which cannot show the stash card, and the card's "Open in Stashpad" button + * opens it. Either way the user lands on the stash in their own queue. + * + * Only a stash id travels in the link, never content, so a link pasted somewhere it should + * not be reveals nothing; the stash has to exist on this device for anything to happen. + */ +const STASH_LINK = + /^stashpad:\/\/stash\/([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})\/?$/; + +/** The stash id a link points at, or null for any other link. */ +export function parseStashLink(url: string): string | null { + const match = STASH_LINK.exec(url.trim()); + return match ? match[1].toLowerCase() : null; +} + +/** + * Call `handler` for every stash link that opens the app: the one it was launched with, + * if any, and each one after that while it runs. Returns the function that stops listening. + * + * A link that arrives while the app is running reaches `onOpenUrl` - on Windows and Linux + * through the single-instance plugin, which also brings the window forward. One that + * started the app is only available from `getCurrent`. + */ +export async function onStashLink(handler: (id: string) => void): Promise<() => void> { + const take = (urls: string[] | null) => { + for (const url of urls ?? []) { + const id = parseStashLink(url); + if (id) handler(id); + } + }; + + const stop = await onOpenUrl(take); + try { + take(await getCurrent()); + } catch (err) { + log.warn("[deep-link] Could not read the link the app was started with:", err); + } + return stop; +}