From 748eaed8fa4a34b7753950358496eb0337451103 Mon Sep 17 00:00:00 2001 From: Nico Wiedemann Date: Thu, 5 Nov 2026 02:52:11 +0100 Subject: [PATCH 1/2] Open a stash from a stashpad://stash link The cloud's show_stash now hands an agent in a terminal a stashpad://stash/ link instead of the stash's text, and the MCP Apps card has an "Open in Stashpad" button that opens the same link. The app registered the scheme but only answered the sign-in callback. deep-link.ts parses the link and listens both for the one the app was launched with (getCurrent) and for later ones (onOpenUrl, reached through the single-instance plugin on Windows and Linux, which also brings the window forward). Queue holds the id until the stash is loaded - a launch link arrives before the first load - then switches context if needed and reveals it, the same way following a reference does. Tests cover the parser and both delivery paths; the full suite and tsc pass. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 7 +++ src/lib/components/Queue.svelte | 33 +++++++++++ src/lib/utils/__tests__/deep-link.test.ts | 71 +++++++++++++++++++++++ src/lib/utils/deep-link.ts | 58 ++++++++++++++++++ 4 files changed, 169 insertions(+) create mode 100644 src/lib/utils/__tests__/deep-link.test.ts create mode 100644 src/lib/utils/deep-link.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a9d917..b42136a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,13 @@ popover, not for the person who wrote the commit. ## [Unreleased] +### 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/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; +} From ebba24eb3f92b79f43e1591aa4c7bf4dc7625890 Mon Sep 17 00:00:00 2001 From: Nico Wiedemann Date: Thu, 5 Nov 2026 02:54:31 +0100 Subject: [PATCH 2/2] chore: bump version to v1.11.4 Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 2 ++ package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b42136a..1fd27cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ 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 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",