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
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,41 @@ popover, not for the person who wrote the commit.

## [Unreleased]

## [1.12.0] - 2026-11-07

### Added

- **Type `@` to reference a file from your project.** Link a context to its project folder in
the context manager, and typing `@` in a stash suggests the files in it. Picking one writes
`@src/app.ts` into the stash, the same form Claude Code uses (paths with spaces are quoted),
so an AI tool working in that project can open the file directly. Files ignored by
`.gitignore` are left out. The link is saved only on this device and is never synced, so
each computer can point at its own copy of the project
- **Stashes show when a referenced file has moved.** In a context with a linked folder, an
`@path` that no longer exists is shown dashed and underlined, and hovering it suggests a file
of the same name elsewhere in the project. The stash text itself is never changed
- **Hovering an `@path` previews the file.** The card looks like an attachment's: an image shows
the picture, a text file its opening lines. Only files the picker lists can be previewed, and
files named like secrets (`.env`, `*.pem`, SSH keys) show a note instead of their contents.
Videos in a project folder show only their name
- Exporting a context includes its project folder. Importing restores the link when that folder
exists on this device, and skips it otherwise. Signing out asks whether to keep this device's
folder links, and keeps them by default
- **A context can draft its own description from its project folder.** With a folder linked and
AI set up, a "Suggest description" button in the context manager reads the folder's README,
`AGENTS.md` and project files (`package.json`, `Cargo.toml` and similar, each cut short) plus
the names in its top level, and asks your AI provider to summarise them. First you see exactly
which files would be sent and to which provider, and nothing leaves your machine until you
confirm; with Apple Intelligence it stays on the device. The result is only a proposal: you
can edit it, then use it as the description or discard it
- **Auto-switch rules can match the name of the context's project folder.** Write `{folder}` in
a rule's value, for example `{folder} - Visual Studio Code`, and it stands for the name of the
folder linked to that context on this device. One rule then works for every project, and each
computer can keep its folder wherever it likes. A rule that uses it matches nothing, rather
than everything, on a computer where the context has no folder, and the context manager says
so beside the rule. In a regular expression the folder name is taken literally, so a folder
called `c++` is not read as a pattern

## [1.11.6] - 2026-11-05

### 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.6",
"version": "1.12.0",
"description": "The staging area for your AI context.",
"author": {
"name": "Nico Wiedemann",
Expand Down
4 changes: 4 additions & 0 deletions screenshots/mock-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export function installMockBackend(overrides: Partial<DemoState> = {}): void {
return 'You are a precise engineering assistant. Rewrite the note as a task.';
case 'write_reference_file':
return `/home/dev/.stashpad/cache/${payload?.contextId}/${payload?.stashId}/refs/${payload?.targetId}.md`;
case 'get_context_folders':
return [];
case 'list_context_files':
return { files: [], truncated: false };
case 'get_system_prompt_path_str':
return '/home/dev/.stashpad/system-prompt.md';
case 'e2ee_status':
Expand Down
65 changes: 62 additions & 3 deletions src-tauri/Cargo.lock

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

5 changes: 4 additions & 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.6"
version = "1.12.0"
description = "The staging area for your AI context."
authors = ["Nico Wiedemann <nico.wiedemann@gmail.com>"]
repository = "https://github.com/EarMaster/stashpad"
Expand Down Expand Up @@ -74,6 +74,9 @@ tokio = { version = "1.50.0", features = ["time", "macros"] }
# not need, and every archive we read or write uses deflate.
zip = { version = "2", default-features = false, features = ["deflate"] }
serde_yaml = "0.9"
# Walks a context's linked project folder for the editor's `@path` picker. ripgrep's walker,
# so .gitignore, .ignore and git's excludes are honoured without reimplementing them.
ignore = "0.4.30"

# Apple Intelligence (Foundation Models) - macOS 26+ only
# keyring ships NO default features and, without one, silently compiles its in-memory
Expand Down
103 changes: 91 additions & 12 deletions src-tauri/src/ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ use std::time::Duration;
use serde::{Deserialize, Serialize};
use tauri::State;

use crate::models::AiConfig;
use crate::state::SettingsState;
use crate::uierror::UiError;

/// The preset id the settings store for Apple Intelligence, which has no endpoint and runs
/// on this machine.
const APPLE_INTELLIGENCE_PRESET: &str = "apple-intelligence";

const AI_TIMEOUT: Duration = Duration::from_secs(120);
const AI_CONNECT_TIMEOUT: Duration = Duration::from_secs(15);

Expand Down Expand Up @@ -88,14 +93,13 @@ async fn post_chat(
.map_err(|e| format!("The AI provider sent an unreadable answer: {}", e).into())
}

/// Improve a stash's text with the saved provider. The frontend supplies the prompt and the
/// text; the endpoint, model and key come from the saved settings only.
#[tauri::command]
pub async fn ai_enhance(
settings_state: State<'_, Arc<SettingsState>>,
system_prompt: String,
user_content: String,
) -> Result<String, UiError> {
/// The saved AI configuration, if AI is switched on and set up.
///
/// An endpoint-less configuration is fine for Apple Intelligence and not for anything else,
/// so the endpoint and model are checked by the callers that need them.
pub(crate) fn usable_config(
settings_state: &State<'_, Arc<SettingsState>>,
) -> Result<AiConfig, UiError> {
let config = settings_state
.lock_settings()
.ai_config
Expand All @@ -104,24 +108,59 @@ pub async fn ai_enhance(
if !config.enabled {
return Err("AI configuration is disabled".into());
}
if config.endpoint.trim().is_empty() || config.model.trim().is_empty() {
if !is_apple_intelligence(&config)
&& (config.endpoint.trim().is_empty() || config.model.trim().is_empty())
{
return Err("AI configuration is incomplete".into());
}
Ok(config)
}

pub(crate) fn is_apple_intelligence(config: &AiConfig) -> bool {
config.preset_id.as_deref() == Some(APPLE_INTELLIGENCE_PRESET)
}

/// The host a request goes to, for telling the user where their text is headed. Falls back to
/// the endpoint as written when it is not a URL.
pub(crate) fn provider_host(endpoint: &str) -> String {
reqwest::Url::parse(endpoint.trim())
.ok()
.and_then(|url| url.host_str().map(str::to_string))
.unwrap_or_else(|| endpoint.trim().to_string())
}

/// One reply from the saved provider - or from Apple Intelligence, which the webview used to
/// be the only caller of. The backend is the one that holds the key, so this is the single
/// place a request that is not the settings form's own test is made.
pub(crate) async fn complete(
settings_state: &State<'_, Arc<SettingsState>>,
system_prompt: &str,
user_content: &str,
max_tokens: u32,
) -> Result<String, UiError> {
let config = usable_config(settings_state)?;
if is_apple_intelligence(&config) {
return crate::utils::apple_intelligence_enhance(
user_content.to_string(),
system_prompt.to_string(),
)
.await;
}

let request = ChatRequest {
model: &config.model,
messages: vec![
ChatMessage {
role: "system",
content: &system_prompt,
content: system_prompt,
},
ChatMessage {
role: "user",
content: &user_content,
content: user_content,
},
],
temperature: Some(0.3),
max_tokens: 1024,
max_tokens,
stream: false,
};
let data = post_chat(&config.endpoint, &config.api_key, &request).await?;
Expand All @@ -131,6 +170,22 @@ pub async fn ai_enhance(
.ok_or_else(|| "No content in API response".into())
}

/// Improve a stash's text with the saved provider. The frontend supplies the prompt and the
/// text; the endpoint, model and key come from the saved settings only.
#[tauri::command]
pub async fn ai_enhance(
settings_state: State<'_, Arc<SettingsState>>,
system_prompt: String,
user_content: String,
) -> Result<String, UiError> {
let config = usable_config(&settings_state)?;
// Apple Intelligence is reached through its own command, with no endpoint to post to.
if is_apple_intelligence(&config) {
return Err("AI configuration is incomplete".into());
}
complete(&settings_state, &system_prompt, &user_content, 1024).await
}

/// The settings a connection test runs against: what the form currently shows, which may not
/// be saved yet.
#[derive(Deserialize)]
Expand Down Expand Up @@ -199,6 +254,30 @@ mod tests {
));
}

#[test]
fn the_provider_host_is_what_the_user_is_told() {
assert_eq!(provider_host("https://api.openai.com/v1"), "api.openai.com");
assert_eq!(provider_host(" http://localhost:11434/v1/ "), "localhost");
assert_eq!(provider_host("not a url"), "not a url");
}

#[test]
fn only_the_apple_preset_runs_on_device() {
let mut config = AiConfig {
enabled: true,
endpoint: String::new(),
api_key: String::new(),
model: String::new(),
preset_id: Some("apple-intelligence".to_string()),
has_api_key: false,
};
assert!(is_apple_intelligence(&config));
config.preset_id = Some("openai".to_string());
assert!(!is_apple_intelligence(&config));
config.preset_id = None;
assert!(!is_apple_intelligence(&config));
}

#[test]
fn the_chat_url_is_built_once() {
assert_eq!(
Expand Down
Loading
Loading