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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ desktop = { description = "Enable desktop GUI client (requires GTK system librar
# Internal crates
rustyclaw-core = { path = "crates/rustyclaw-core", version = "0.3.0" }
rustyclaw-tui = { path = "crates/rustyclaw-tui", version = "0.3.0" }
chat-system = { version = "0.1.2", default-features = false }
chat-system = { version = "0.1.3", default-features = false }

# Configuration and serialization
serde = { version = "1.0", features = ["derive"] }
Expand Down
7 changes: 2 additions & 5 deletions crates/rustyclaw-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ ssh = ["dep:russh", "dep:russh-keys", "dep:rand_core", "dep:sha2"]
qr = ["dep:image"]
# CLI-based messengers (tier 1) - no heavy deps, just HTTP
signal-cli = ["chat-system/signal-cli"]
matrix-cli = [] # Matrix CLI messenger using HTTP API (no external deps)
telegram-cli = []
discord-cli = []
slack-cli = []
all-messengers = ["whatsapp", "signal-cli", "matrix-cli", "telegram-cli", "discord-cli", "slack-cli"]
# matrix-cli removed - use matrix feature instead (chat-system 0.1.3 has all capabilities)
all-messengers = ["whatsapp", "signal-cli", "matrix"]
full = ["web-tools", "browser", "mcp", "all-messengers", "ssh", "steel-memory"]

[dependencies]
Expand Down
87 changes: 31 additions & 56 deletions crates/rustyclaw-core/src/gateway/messenger_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use super::{
ToolCallResult,
};

#[cfg(feature = "matrix-cli")]
use crate::messengers::MatrixCliMessenger;
#[cfg(feature = "matrix")]
use crate::messengers::MatrixMessenger;

/// Shared messenger manager for the gateway.
pub type SharedMessengerManager = Arc<Mutex<MessengerManager>>;
Expand Down Expand Up @@ -89,57 +89,10 @@ async fn create_messenger(config: &MessengerConfig) -> Result<Box<dyn Messenger>

let name = config.name.clone();
let mut messenger: Box<dyn Messenger> = match config.messenger_type.as_str() {
#[cfg(feature = "matrix-cli")]
"matrix-cli" => {
let homeserver = config
.homeserver
.clone()
.context("Matrix-CLI requires 'homeserver'")?;
let user_id = config
.user_id
.clone()
.context("Matrix-CLI requires 'user_id'")?;
let access_token = config
.access_token
.clone()
.context("Matrix-CLI requires 'access_token'")?;

let mut messenger = MatrixCliMessenger::with_token(
name.clone(),
homeserver,
user_id,
access_token,
None, // device_id
);

// Set state directory for sync token persistence
if let Some(dirs) = directories::ProjectDirs::from("", "", "rustyclaw") {
let state_dir = dirs.data_dir().join("matrix").join(&name);
messenger = messenger.with_state_dir(state_dir);
}

// Set allowed chats if configured
if !config.allowed_chats.is_empty() {
messenger = messenger.with_allowed_chats(config.allowed_chats.clone());
}

// Set DM config if present
if let Some(ref dm) = config.dm {
use crate::messengers::MatrixDmConfig;
let dm_config = MatrixDmConfig {
enabled: dm.enabled,
policy: dm.policy.clone().unwrap_or_else(|| "allowlist".to_string()),
allow_from: dm.allow_from.clone(),
};
messenger = messenger.with_dm_config(dm_config);
}

Box::new(messenger)
}
#[cfg(not(feature = "matrix-cli"))]
// matrix-cli type removed - use "matrix" type instead (chat-system 0.1.3)
"matrix-cli" => {
anyhow::bail!(
"Matrix-CLI messenger not compiled in. Rebuild with --features matrix-cli"
"matrix-cli messenger type is deprecated. Use 'matrix' type instead."
);
}
"irc" => build_irc_messenger(config, name)?,
Expand Down Expand Up @@ -404,17 +357,17 @@ fn build_matrix_messenger(config: &MessengerConfig, name: String) -> Result<Box<
.clone()
.context("Matrix requires 'user_id'")?;

let messenger = if let Some(access_token) = config.access_token.clone() {
crate::messengers::MatrixMessenger::with_access_token(
name,
let mut messenger = if let Some(access_token) = config.access_token.clone() {
MatrixMessenger::with_access_token(
name.clone(),
homeserver,
user_id,
access_token,
None,
)
} else {
crate::messengers::MatrixMessenger::new(
name,
MatrixMessenger::new(
name.clone(),
homeserver,
user_id,
config
Expand All @@ -424,6 +377,28 @@ fn build_matrix_messenger(config: &MessengerConfig, name: String) -> Result<Box<
)
};

// Set state directory for sync token persistence
if let Some(dirs) = directories::ProjectDirs::from("", "", "rustyclaw") {
let state_dir = dirs.data_dir().join("matrix").join(&name);
messenger = messenger.with_state_dir(state_dir);
}

// Set allowed chats if configured
if !config.allowed_chats.is_empty() {
messenger = messenger.with_allowed_chats(config.allowed_chats.clone());
}

// Set DM config if present
if let Some(ref dm) = config.dm {
use crate::messengers::MatrixDmConfig;
let dm_config = MatrixDmConfig {
enabled: dm.enabled,
policy: dm.policy.clone().unwrap_or_else(|| "allowlist".to_string()),
allow_from: dm.allow_from.clone(),
};
messenger = messenger.with_dm_config(dm_config);
}
Comment on lines +380 to +400
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Password-based Matrix configs bypass build_matrix_messenger, silently losing state_dir/allowed_chats/dm_config

The pre-existing generic_messenger_config function at crates/rustyclaw-core/src/gateway/messenger_handler.rs:198-215 has a "matrix" if config.access_token.is_none() arm that intercepts all password-based Matrix configs and routes them through GenericMessenger, returning early at line 84-87 before build_matrix_messenger is ever called. This means the new state_dir, allowed_chats, and dm_config setup code (lines 380-400) — migrated from the deleted MatrixCliMessenger — is only reached when access_token is set. Users migrating from matrix-cli to matrix type with password auth silently lose: (1) sync token persistence (causing re-processing of old messages on restart), (2) room allowlisting (bot responds in all rooms), and (3) DM handling configuration.

Prompt for agents
The build_matrix_messenger function (lines 349-403) adds state_dir, allowed_chats, and dm_config setup for MatrixMessenger, but this code is never reached for password-based Matrix configs. The reason is generic_messenger_config (line 198) has a match arm for "matrix" if config.access_token.is_none() that creates a GenericMessenger and returns early from create_messenger at line 84-87, bypassing build_matrix_messenger entirely.

To fix this, either:
1. Remove the "matrix" arm from generic_messenger_config (lines 198-215) so that all Matrix configs go through build_matrix_messenger, OR
2. Move the state_dir/allowed_chats/dm_config logic into the generic_messenger_config path for Matrix (though this may not be possible if GenericMessenger doesn't support those builder methods), OR
3. Add a guard condition to the generic_messenger_config "matrix" arm that also checks for allowed_chats/dm being set, falling through to build_matrix_messenger when those advanced features are configured.

Option 1 is the simplest and most correct approach given the PR's intent to consolidate matrix-cli features into the matrix type.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 82bb28d. Removed the "matrix" if config.access_token.is_none() arm from generic_messenger_config so all Matrix configs (both access_token and password-based) now go through build_matrix_messenger, which correctly applies state_dir, allowed_chats, and dm_config.


Ok(Box::new(messenger))
}

Expand Down
58 changes: 0 additions & 58 deletions crates/rustyclaw-core/src/messengers/console.rs

This file was deleted.

88 changes: 0 additions & 88 deletions crates/rustyclaw-core/src/messengers/discord.rs

This file was deleted.

Loading
Loading