story-kit: merge 275_story_matrix_bot_surfaces_claude_code_permission_prompts_to_chat

This commit is contained in:
Dave
2026-03-18 09:28:51 +00:00
parent 110815c1c5
commit 10a5bea2b1
4 changed files with 256 additions and 26 deletions

View File

@@ -21,9 +21,11 @@ pub mod notifications;
pub use config::BotConfig;
use crate::http::context::PermissionForward;
use crate::io::watcher::WatcherEvent;
use std::path::Path;
use tokio::sync::broadcast;
use std::sync::Arc;
use tokio::sync::{Mutex as TokioMutex, broadcast, mpsc};
/// Attempt to start the Matrix bot.
///
@@ -35,8 +37,16 @@ use tokio::sync::broadcast;
/// posts stage-transition messages to all configured rooms whenever a work
/// item moves between pipeline stages.
///
/// `perm_rx` is the permission-request receiver shared with the MCP
/// `prompt_permission` tool. The bot locks it during active chat sessions
/// to surface permission prompts to the Matrix room and relay user decisions.
///
/// Must be called from within a Tokio runtime context (e.g., from `main`).
pub fn spawn_bot(project_root: &Path, watcher_tx: broadcast::Sender<WatcherEvent>) {
pub fn spawn_bot(
project_root: &Path,
watcher_tx: broadcast::Sender<WatcherEvent>,
perm_rx: Arc<TokioMutex<mpsc::UnboundedReceiver<PermissionForward>>>,
) {
let config = match BotConfig::load(project_root) {
Some(c) => c,
None => {
@@ -54,7 +64,7 @@ pub fn spawn_bot(project_root: &Path, watcher_tx: broadcast::Sender<WatcherEvent
let root = project_root.to_path_buf();
let watcher_rx = watcher_tx.subscribe();
tokio::spawn(async move {
if let Err(e) = bot::run_bot(config, root, watcher_rx).await {
if let Err(e) = bot::run_bot(config, root, watcher_rx, perm_rx).await {
crate::slog!("[matrix-bot] Fatal error: {e}");
}
});