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
8 changes: 8 additions & 0 deletions crates/sprout-relay/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ pub async fn handle_connection(socket: WebSocket, state: Arc<AppState>, addr: So

state.sub_registry.remove_connection(conn.conn_id);
state.conn_manager.deregister(conn.conn_id);
if let AuthState::Authenticated(ref auth_ctx) = *conn.auth_state.read().await {
let remaining = state
.conn_manager
.connection_ids_for_pubkey(auth_ctx.pubkey.to_bytes().as_slice());
if remaining.is_empty() {
let _ = state.pubsub.clear_presence(&auth_ctx.pubkey).await;
}
}
metrics::gauge!("sprout_ws_connections_active").decrement(1.0);
info!(conn_id = %conn_id, addr = %addr, "WebSocket connection closed");

Expand Down
24 changes: 1 addition & 23 deletions desktop/src-tauri/src/commands/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use tauri::State;
use crate::{
app_state::AppState,
events,
models::{
ProfileInfo, SearchUsersResponse, SetPresenceResponse, UserNotesResponse,
UsersBatchResponse,
},
models::{ProfileInfo, SearchUsersResponse, UserNotesResponse, UsersBatchResponse},
nostr_convert,
relay::{query_relay, submit_event},
};
Expand Down Expand Up @@ -270,25 +267,6 @@ pub async fn get_presence(
.collect())
}

#[tauri::command]
pub async fn set_presence(
status: PresenceStatus,
state: State<'_, AppState>,
) -> Result<SetPresenceResponse, String> {
let status_str = match status {
PresenceStatus::Online => "online",
PresenceStatus::Away => "away",
PresenceStatus::Offline => "offline",
};
let builder = events::build_presence(status_str)?;
submit_event(builder, &state).await?;

Ok(SetPresenceResponse {
status,
ttl_seconds: 60,
})
}

fn current_pubkey_hex(state: &AppState) -> Result<String, String> {
let keys = state.keys.lock().map_err(|e| e.to_string())?;
Ok(keys.public_key().to_hex())
Expand Down
9 changes: 0 additions & 9 deletions desktop/src-tauri/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,15 +690,6 @@ pub fn build_dm_hide(channel_id: &str) -> Result<EventBuilder, String> {
Ok(EventBuilder::new(Kind::Custom(41012), "").tags(tags))
}

/// Kind 20001 — ephemeral presence broadcast (`online` / `away` / `offline`).
pub fn build_presence(status: &str) -> Result<EventBuilder, String> {
match status {
"online" | "away" | "offline" => {}
other => return Err(format!("invalid presence status: {other}")),
};
Ok(EventBuilder::new(Kind::Custom(20001), status.to_string()))
}

/// Kind 30620 — replaceable workflow definition.
///
/// The `d` tag carries the workflow id; `h` tag carries the channel id; the
Expand Down
2 changes: 0 additions & 2 deletions desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ pub fn run() {
// this worktree's data directory. Must run before
// restore_managed_agents_on_launch (which reads managed-agents.json).
migration::sync_shared_agent_data(&app_handle);
migration::reconcile_provider_mcp_commands(&app_handle);
migration::reconcile_persona_pack_paths(&app_handle);

// Resolve persisted identity key (env var → file → generate+save).
Expand Down Expand Up @@ -585,7 +584,6 @@ pub fn run() {
get_user_notes,
search_users,
get_presence,
set_presence,
get_default_relay_url,
is_shared_identity,
get_relay_ws_url,
Expand Down
208 changes: 0 additions & 208 deletions desktop/src-tauri/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
//! `SPROUT_SHARE_IDENTITY=1` and `SPROUT_PRIVATE_KEY` is set. All dev
//! instances share the same physical files — edits in any worktree are
//! immediately visible to all others.
//!
//! **Provider reconciliation** (`reconcile_provider_mcp_commands`): Per-launch
//! fix-up of `mcp_command` values in `managed-agents.json` against the
//! discovery table. Ensures known providers always have their canonical
//! `mcp_command`; unknown/custom agents are left untouched.

use std::path::{Path, PathBuf};
use tauri::Manager;
Expand Down Expand Up @@ -264,54 +259,6 @@ pub fn sync_shared_agent_data(app: &tauri::AppHandle) {
}
}

fn reconcile_mcp_commands_in_file(path: &Path) {
patch_json_records(path, |obj| {
let agent_command = match obj.get("agent_command").and_then(|v| v.as_str()) {
Some(cmd) => cmd.to_string(),
None => return false,
};
let Some(provider) = crate::managed_agents::known_acp_provider(&agent_command) else {
return false;
};
let expected = provider.mcp_command.unwrap_or("");
let current = obj
.get("mcp_command")
.and_then(|v| v.as_str())
.unwrap_or("");
// Only clear the known stale default — never touch user-customized values.
if current == "sprout-mcp-server" {
eprintln!(
"sprout-desktop: provider-reconcile: {:?} ({:?}): mcp_command {:?} → {:?}",
obj.get("name").and_then(|v| v.as_str()).unwrap_or("?"),
agent_command,
current,
expected,
);
obj.insert(
"mcp_command".to_string(),
serde_json::Value::String(expected.to_string()),
);
true
} else {
false
}
});
}

/// Reconcile `mcp_command` values in managed-agents.json against the
/// discovery table. Known providers get their canonical mcp_command;
/// unknown/custom agents are left untouched.
pub fn reconcile_provider_mcp_commands(app: &tauri::AppHandle) {
let Ok(dir) = app.path().app_data_dir() else {
return;
};
let path = dir.join("agents/managed-agents.json");
if !path.exists() {
return;
}
reconcile_mcp_commands_in_file(&path);
}

fn reconcile_pack_paths_in_file(path: &Path, canonical_dir: &Path) {
let canonical_packs = canonical_dir.join("agents/packs");
patch_json_records(path, |obj| {
Expand Down Expand Up @@ -667,161 +614,6 @@ mod tests {
serde_json::from_str(&content).unwrap()
}

#[test]
fn reconcile_clears_mcp_command_for_goose() {
let dir = tempfile::tempdir().unwrap();
write_agents_json(
dir.path(),
&serde_json::json!([{
"name": "Scout",
"agent_command": "goose",
"mcp_command": "sprout-mcp-server"
}]),
);
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
let records = read_agents_json(dir.path());
assert_eq!(records[0]["mcp_command"], "");
}

#[test]
fn reconcile_clears_mcp_command_for_claude() {
let dir = tempfile::tempdir().unwrap();
write_agents_json(
dir.path(),
&serde_json::json!([{
"name": "Claude Agent",
"agent_command": "claude-agent-acp",
"mcp_command": "sprout-mcp-server"
}]),
);
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
let records = read_agents_json(dir.path());
assert_eq!(records[0]["mcp_command"], "");
}

#[test]
fn reconcile_preserves_sprout_dev_mcp() {
let dir = tempfile::tempdir().unwrap();
write_agents_json(
dir.path(),
&serde_json::json!([{
"name": "Solo",
"agent_command": "sprout-agent",
"mcp_command": "sprout-dev-mcp"
}]),
);
let before =
std::fs::read_to_string(dir.path().join("agents/managed-agents.json")).unwrap();
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
let after = std::fs::read_to_string(dir.path().join("agents/managed-agents.json")).unwrap();
assert_eq!(
before, after,
"file should not be rewritten when already correct"
);
}

#[test]
fn reconcile_fixes_sprout_agent_if_stale() {
let dir = tempfile::tempdir().unwrap();
write_agents_json(
dir.path(),
&serde_json::json!([{
"name": "Solo",
"agent_command": "sprout-agent",
"mcp_command": "sprout-mcp-server"
}]),
);
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
let records = read_agents_json(dir.path());
assert_eq!(records[0]["mcp_command"], "sprout-dev-mcp");
}

#[test]
fn reconcile_leaves_unknown_agent_untouched() {
let dir = tempfile::tempdir().unwrap();
write_agents_json(
dir.path(),
&serde_json::json!([{
"name": "Custom Bot",
"agent_command": "my-custom-agent",
"mcp_command": "my-custom-mcp"
}]),
);
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
let records = read_agents_json(dir.path());
assert_eq!(records[0]["mcp_command"], "my-custom-mcp");
}

#[test]
fn reconcile_is_idempotent() {
let dir = tempfile::tempdir().unwrap();
write_agents_json(
dir.path(),
&serde_json::json!([{
"name": "Scout",
"agent_command": "goose",
"mcp_command": "sprout-mcp-server"
}]),
);
let path = dir.path().join("agents/managed-agents.json");
reconcile_mcp_commands_in_file(&path);
let after_first = std::fs::read_to_string(&path).unwrap();
reconcile_mcp_commands_in_file(&path);
let after_second = std::fs::read_to_string(&path).unwrap();
assert_eq!(after_first, after_second);
}

#[test]
fn reconcile_handles_mixed_records() {
let dir = tempfile::tempdir().unwrap();
write_agents_json(
dir.path(),
&serde_json::json!([
{"name": "Scout", "agent_command": "goose", "mcp_command": "sprout-mcp-server"},
{"name": "Claude", "agent_command": "claude-agent-acp", "mcp_command": "sprout-mcp-server"},
{"name": "Solo", "agent_command": "sprout-agent", "mcp_command": "sprout-dev-mcp"},
{"name": "Custom", "agent_command": "my-bot", "mcp_command": "my-mcp"},
{"name": "Codex", "agent_command": "codex-acp", "mcp_command": "sprout-mcp-server"}
]),
);
reconcile_mcp_commands_in_file(&dir.path().join("agents/managed-agents.json"));
let records = read_agents_json(dir.path());
assert_eq!(records[0]["mcp_command"], "", "goose should be cleared");
assert_eq!(records[1]["mcp_command"], "", "claude should be cleared");
assert_eq!(
records[2]["mcp_command"], "sprout-dev-mcp",
"sprout-agent preserved"
);
assert_eq!(
records[3]["mcp_command"], "my-mcp",
"custom agent untouched"
);
assert_eq!(records[4]["mcp_command"], "", "codex should be cleared");
}

#[test]
fn reconcile_leaves_absent_mcp_command_untouched() {
let dir = tempfile::tempdir().unwrap();
let json = serde_json::json!([{"name": "Solo", "agent_command": "sprout-agent"}]);
write_agents_json(dir.path(), &json);
let path = dir.path().join("agents/managed-agents.json");
let before = std::fs::read_to_string(&path).unwrap();
reconcile_mcp_commands_in_file(&path);
assert_eq!(before, std::fs::read_to_string(&path).unwrap());
}

#[test]
fn reconcile_leaves_null_mcp_command_untouched() {
let dir = tempfile::tempdir().unwrap();
let json =
serde_json::json!([{"name":"Solo","agent_command":"sprout-agent","mcp_command":null}]);
write_agents_json(dir.path(), &json);
let path = dir.path().join("agents/managed-agents.json");
let before = std::fs::read_to_string(&path).unwrap();
reconcile_mcp_commands_in_file(&path);
assert_eq!(before, std::fs::read_to_string(&path).unwrap());
}

#[test]
fn sync_creates_packs_directory_symlink() {
let (_parent, canonical, worktree) = setup_sync_layout();
Expand Down
8 changes: 0 additions & 8 deletions desktop/src-tauri/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::collections::HashMap;

use serde::{Deserialize, Deserializer, Serialize};

use sprout_core::PresenceStatus;

#[derive(Serialize)]
pub struct IdentityInfo {
pub pubkey: String,
Expand Down Expand Up @@ -74,12 +72,6 @@ pub struct UserNotesResponse {
pub next_cursor: Option<UserNotesCursor>,
}

#[derive(Serialize, Deserialize)]
pub struct SetPresenceResponse {
pub status: PresenceStatus,
pub ttl_seconds: u64,
}

#[derive(Serialize, Deserialize)]
pub struct ChannelInfo {
pub id: String,
Expand Down
Loading