huskies: merge 626_refactor_introduce_services_bundle_and_migrate_appcontext_matrix_transport
This commit is contained in:
+35
-7
@@ -22,6 +22,7 @@ pub mod node_identity;
|
||||
pub(crate) mod pipeline_state;
|
||||
pub mod rebuild;
|
||||
mod service;
|
||||
pub mod services;
|
||||
mod state;
|
||||
mod store;
|
||||
mod workflow;
|
||||
@@ -560,10 +561,9 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
let watcher_rx_for_discord = watcher_tx.subscribe();
|
||||
// Subscribe to watcher events for the per-project event buffer (gateway polling).
|
||||
let watcher_rx_for_events = watcher_tx.subscribe();
|
||||
// Wrap perm_rx in Arc<Mutex> so it can be shared with both the WebSocket
|
||||
// handler (via AppContext) and the Matrix bot.
|
||||
// Wrap perm_rx in Arc<Mutex> so it can be shared across the Services
|
||||
// bundle (AppContext + Matrix bot) and the webhook-based transports.
|
||||
let perm_rx = Arc::new(tokio::sync::Mutex::new(perm_rx));
|
||||
let perm_rx_for_bot = Arc::clone(&perm_rx);
|
||||
let perm_rx_for_whatsapp = Arc::clone(&perm_rx);
|
||||
let perm_rx_for_slack = Arc::clone(&perm_rx);
|
||||
let perm_rx_for_discord = Arc::clone(&perm_rx);
|
||||
@@ -576,6 +576,36 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
// Clone for shutdown cleanup — kill orphaned PTY children before exiting.
|
||||
let agents_for_shutdown = Arc::clone(&agents);
|
||||
|
||||
// ── Construct the shared Services bundle ────────────────────────────
|
||||
//
|
||||
// A single `Arc<Services>` is built here and cloned into `AppContext`
|
||||
// and the Matrix `BotContext`. Bot-level fields (name, user-id, etc.)
|
||||
// come from `bot.toml` when present; otherwise sensible defaults apply.
|
||||
let bot_cfg_for_services = startup_root
|
||||
.as_ref()
|
||||
.and_then(|root| chat::transport::matrix::BotConfig::load(root));
|
||||
let services = Arc::new(services::Services {
|
||||
project_root: startup_root.clone().unwrap_or_default(),
|
||||
agents: Arc::clone(&agents),
|
||||
bot_name: bot_cfg_for_services
|
||||
.as_ref()
|
||||
.and_then(|c| c.display_name.clone())
|
||||
.unwrap_or_else(|| "Assistant".to_string()),
|
||||
bot_user_id: String::new(),
|
||||
ambient_rooms: Arc::new(std::sync::Mutex::new(
|
||||
bot_cfg_for_services
|
||||
.as_ref()
|
||||
.map(|c| c.ambient_rooms.iter().cloned().collect())
|
||||
.unwrap_or_default(),
|
||||
)),
|
||||
perm_rx: Arc::clone(&perm_rx),
|
||||
pending_perm_replies: Arc::new(tokio::sync::Mutex::new(std::collections::HashMap::new())),
|
||||
permission_timeout_secs: bot_cfg_for_services
|
||||
.as_ref()
|
||||
.map(|c| c.permission_timeout_secs)
|
||||
.unwrap_or(120),
|
||||
});
|
||||
|
||||
// Build WhatsApp webhook context if bot.toml configures transport = "whatsapp".
|
||||
let whatsapp_ctx: Option<Arc<chat::transport::whatsapp::WhatsAppWebhookContext>> = startup_root
|
||||
.as_ref()
|
||||
@@ -806,11 +836,10 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
state: app_state,
|
||||
store,
|
||||
workflow,
|
||||
agents,
|
||||
services: Arc::clone(&services),
|
||||
watcher_tx,
|
||||
reconciliation_tx,
|
||||
perm_tx,
|
||||
perm_rx,
|
||||
qa_app_process: Arc::new(std::sync::Mutex::new(None)),
|
||||
bot_shutdown: bot_shutdown_notifier.clone(),
|
||||
matrix_shutdown_tx: Some(Arc::clone(&matrix_shutdown_tx)),
|
||||
@@ -890,8 +919,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
let _ = chat::transport::matrix::spawn_bot(
|
||||
root,
|
||||
watcher_tx_for_bot,
|
||||
perm_rx_for_bot,
|
||||
Arc::clone(&startup_agents),
|
||||
Arc::clone(&services),
|
||||
matrix_shutdown_rx,
|
||||
None,
|
||||
vec![],
|
||||
|
||||
Reference in New Issue
Block a user