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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <nico.wiedemann@gmail.com>"]
repository = "https://github.com/EarMaster/stashpad"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 33 additions & 0 deletions src/lib/components/Queue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -655,6 +656,27 @@
revealStash(ref.stash.id);
}

/**
* A `stashpad://stash/<id>` 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<string | null>(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;
Expand Down Expand Up @@ -1036,13 +1058,23 @@

// 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;

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",
Expand Down Expand Up @@ -1124,6 +1156,7 @@

onDestroy(() => {
window.removeEventListener("keydown", handleSearchShortcut);
unlistenStashLink?.();
unlistenEnter?.();
unlistenOver?.();
unlistenLeave?.();
Expand Down
71 changes: 71 additions & 0 deletions src/lib/utils/__tests__/deep-link.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
58 changes: 58 additions & 0 deletions src/lib/utils/deep-link.ts
Original file line number Diff line number Diff line change
@@ -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/<id>` - 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;
}
Loading