poc-daemon: subscribe to channel notifications, drop config.rs
Wire poc-daemon into channel daemon notifications via subscribe_all(). Channel notifications (IRC, telegram, tmux) now flow through the existing notification pipeline instead of the dead module system. Remove claude/config.rs — daemon config is fully covered by channel config files in ~/.consciousness/channels/. Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
1941624249
commit
8c1fef3c69
5 changed files with 22 additions and 180 deletions
68
Cargo.lock
generated
68
Cargo.lock
generated
|
|
@ -2101,7 +2101,6 @@ dependencies = [
|
|||
"tokio",
|
||||
"tokio-scoped",
|
||||
"tokio-util",
|
||||
"toml",
|
||||
"tui-markdown",
|
||||
"tui-textarea-2",
|
||||
"uuid",
|
||||
|
|
@ -2172,7 +2171,7 @@ version = "3.5.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f"
|
||||
dependencies = [
|
||||
"toml_edit 0.25.10+spec-1.1.0",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2903,15 +2902,6 @@ dependencies = [
|
|||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
|
|
@ -3369,27 +3359,6 @@ dependencies = [
|
|||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.8.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime 0.6.11",
|
||||
"toml_edit 0.22.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "1.1.1+spec-1.1.0"
|
||||
|
|
@ -3399,20 +3368,6 @@ dependencies = [
|
|||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.22.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime 0.6.11",
|
||||
"toml_write",
|
||||
"winnow 0.7.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.25.10+spec-1.1.0"
|
||||
|
|
@ -3420,9 +3375,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "a82418ca169e235e6c399a84e395ab6debeb3bc90edc959bf0f48647c6a32d1b"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime 1.1.1+spec-1.1.0",
|
||||
"toml_datetime",
|
||||
"toml_parser",
|
||||
"winnow 1.0.1",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3431,15 +3386,9 @@ version = "1.1.2+spec-1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526"
|
||||
dependencies = [
|
||||
"winnow 1.0.1",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_write"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.5.3"
|
||||
|
|
@ -4229,15 +4178,6 @@ version = "0.53.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.7.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "1.0.1"
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ crossterm = { version = "0.29", features = ["event-stream"] }
|
|||
skillratings = "0.28"
|
||||
capnp-rpc = "0.20"
|
||||
tokio-util = { version = "0.7", features = ["compat"] }
|
||||
toml = "0.8"
|
||||
env_logger = "0.11"
|
||||
tokio-scoped = "0.2.0"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,97 +0,0 @@
|
|||
// Daemon configuration.
|
||||
//
|
||||
// Lives at ~/.consciousness/daemon.toml. Loaded on startup, updated at
|
||||
// runtime when modules change state (join channel, etc.).
|
||||
|
||||
use crate::thalamus::home;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn config_path() -> PathBuf {
|
||||
home().join(".consciousness/daemon.toml")
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct Config {
|
||||
#[serde(default)]
|
||||
pub irc: IrcConfig,
|
||||
#[serde(default)]
|
||||
pub telegram: TelegramConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct IrcConfig {
|
||||
pub enabled: bool,
|
||||
pub server: String,
|
||||
pub port: u16,
|
||||
pub tls: bool,
|
||||
pub nick: String,
|
||||
pub user: String,
|
||||
pub realname: String,
|
||||
pub channels: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for IrcConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
server: "irc.libera.chat".into(),
|
||||
port: 6697,
|
||||
tls: true,
|
||||
nick: "agent".into(),
|
||||
user: "agent".into(),
|
||||
realname: "agent".into(),
|
||||
channels: vec!["#bcachefs".into(), "#bcachefs-ai".into()],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TelegramConfig {
|
||||
pub enabled: bool,
|
||||
pub token: String,
|
||||
pub chat_id: i64,
|
||||
}
|
||||
|
||||
impl Default for TelegramConfig {
|
||||
fn default() -> Self {
|
||||
// Load token and chat_id from legacy files if they exist
|
||||
let token = std::fs::read_to_string(home().join(".consciousness/telegram/token"))
|
||||
.map(|s| s.trim().to_string())
|
||||
.unwrap_or_default();
|
||||
let chat_id = std::fs::read_to_string(home().join(".consciousness/telegram/chat_id"))
|
||||
.ok()
|
||||
.and_then(|s| s.trim().parse().ok())
|
||||
.unwrap_or(0);
|
||||
Self {
|
||||
enabled: !token.is_empty() && chat_id != 0,
|
||||
token,
|
||||
chat_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> Self {
|
||||
let path = config_path();
|
||||
match fs::read_to_string(&path) {
|
||||
Ok(data) => toml::from_str(&data).unwrap_or_else(|e| {
|
||||
log::warn!("bad config {}: {e}, using defaults", path.display());
|
||||
Self::default()
|
||||
}),
|
||||
Err(_) => {
|
||||
let config = Self::default();
|
||||
config.save();
|
||||
config
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save(&self) {
|
||||
let path = config_path();
|
||||
if let Ok(data) = toml::to_string_pretty(self) {
|
||||
let _ = fs::write(path, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@
|
|||
// The daemon protocol (daemon_capnp) and universal infrastructure
|
||||
// (channels, supervisor, notify) remain in thalamus/.
|
||||
|
||||
pub mod config;
|
||||
pub mod context;
|
||||
pub mod hook;
|
||||
pub mod idle;
|
||||
|
|
@ -443,7 +442,6 @@ async fn server_main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let pid = std::process::id();
|
||||
std::fs::write(pid_path(), pid.to_string()).ok();
|
||||
|
||||
let daemon_config = Rc::new(RefCell::new(config::Config::load()));
|
||||
|
||||
let state = Rc::new(RefCell::new(idle::State::new()));
|
||||
state.borrow_mut().load();
|
||||
|
|
@ -452,13 +450,22 @@ async fn server_main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
tokio::task::LocalSet::new()
|
||||
.run_until(async move {
|
||||
// Start modules
|
||||
let (_notify_tx, mut notify_rx) = tokio::sync::mpsc::unbounded_channel::<notify::Notification>();
|
||||
|
||||
// External modules (IRC, Telegram) now run as separate daemons.
|
||||
// They connect via the notification channel when implemented.
|
||||
let _irc_state: Option<()> = None;
|
||||
let _telegram_state: Option<()> = None;
|
||||
// Subscribe to channel daemon notifications
|
||||
let (notify_tx, mut notify_rx) = tokio::sync::mpsc::unbounded_channel::<notify::Notification>();
|
||||
{
|
||||
let channel_rx = crate::thalamus::channels::subscribe_all();
|
||||
let tx = notify_tx.clone();
|
||||
std::thread::spawn(move || {
|
||||
while let Ok(cn) = channel_rx.recv() {
|
||||
let _ = tx.send(notify::Notification {
|
||||
ntype: cn.channel,
|
||||
urgency: cn.urgency,
|
||||
message: cn.preview,
|
||||
timestamp: crate::thalamus::now(),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let listener = UnixListener::bind(&sock)?;
|
||||
#[cfg(unix)]
|
||||
|
|
@ -528,7 +535,6 @@ async fn server_main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
let daemon_impl = rpc::DaemonImpl::new(
|
||||
state.clone(),
|
||||
daemon_config.clone(),
|
||||
);
|
||||
let client: daemon_capnp::daemon::Client =
|
||||
capnp_rpc::new_client(daemon_impl);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
// notify::NotifyState, and module state. All state is owned by
|
||||
// RefCells on the LocalSet — no Send/Sync needed.
|
||||
|
||||
use super::config::Config;
|
||||
use super::idle;
|
||||
use crate::thalamus::{daemon_capnp, notify};
|
||||
use daemon_capnp::daemon;
|
||||
|
|
@ -15,16 +14,11 @@ use log::info;
|
|||
|
||||
pub struct DaemonImpl {
|
||||
state: Rc<RefCell<idle::State>>,
|
||||
// TODO: replace with named channel map
|
||||
_config: Rc<RefCell<Config>>,
|
||||
}
|
||||
|
||||
impl DaemonImpl {
|
||||
pub fn new(
|
||||
state: Rc<RefCell<idle::State>>,
|
||||
_config: Rc<RefCell<Config>>,
|
||||
) -> Self {
|
||||
Self { state, _config }
|
||||
pub fn new(state: Rc<RefCell<idle::State>>) -> Self {
|
||||
Self { state }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue