consciousness/src/lib.rs

97 lines
2.7 KiB
Rust
Raw Normal View History

#![cfg_attr(feature = "nightly-diagnostics", feature(async_fn_track_caller))]
// consciousness — unified crate for memory, agents, and subconscious processes
//
// thought/ — shared cognitive substrate (tools, context, memory ops)
// hippocampus/ — memory storage, retrieval, consolidation
// subconscious/ — autonomous agents (reflect, surface, consolidate, ...)
// user/ — interactive agent (TUI, tools, API clients)
/// Debug logging macro — writes to ~/.consciousness/logs/daemon/debug.log
#[macro_export]
macro_rules! dbglog {
($($arg:tt)*) => {{
use std::io::Write;
let log_dir = std::path::PathBuf::from(
std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()))
.join(".consciousness/logs/daemon");
let _ = std::fs::create_dir_all(&log_dir);
if let Ok(mut f) = std::fs::OpenOptions::new()
.create(true).append(true)
.open(log_dir.join("debug.log"))
{
let _ = writeln!(f, $($arg)*);
}
}};
}
salience: add gRPC client + TLS plumbing for stateful vllm sessions Adds the client-side of a stateful gRPC protocol against vllm, plus the TLS trust machinery so we can talk to self-signed vllm servers. Protocol (proto/salience.proto): Bidi-streaming Session RPC carries OpenSession / AppendTokens / Generate / Cancel from client and SessionReady / PrefillProgress / Token / GenerateDone / Error from server. Separate Fork unary RPC for cheap branching (prefix cache shares KV automatically). Plus ListSessions, CloseSession, GetReadoutManifest admin RPCs. Per-token readouts ship as packed f32 ([n_layers * n_concepts] per token, flat). Logprobs use range-selected positions plus a top-k parameter — empty ranges means no logprobs, any range means emit sampled-token logprob at those positions, top_k > 0 adds alternatives. Client (src/agent/api/salience.rs): Tonic-generated types under pb::, a connect() helper, with_auth() for bearer metadata, and a Session handle wrapping the bidi stream: open() handshakes SessionReady; append() is fire-and-forget; generate() returns impl Stream<Item = Event> that drains inbound until Done or terminating Error. One generate at a time per session. Peak picker (src/agent/salience.rs): Pure function over ReadoutEntry traces. Per-concept z-score against trace global stats; contiguous above-threshold regions emit one peak at the local max. Configurable sigma threshold and min-std safety floor. Deterministic tie-break on offset then concept name. 12 unit tests covering empty traces, flat channels, single/multi spikes, contiguous humps, multi-concept independence, trailing runs, sub-threshold noise, layer-out-of-range, manifest shape mismatch, and threshold tunability. TLS (src/agent/api/http.rs): HttpClient::build now also loads every .pem file under ~/.consciousness/certs/ into the rustls root store — so dropping a <host>.pem in that directory is enough to trust a new self- signed server; no code changes per new host. Also installs the rustls default crypto provider explicitly via OnceLock: tonic's tls features pulled in both ring and aws-lc-rs on the resolver path, and rustls 0.23 refuses to auto-pick when either could win. Build (build.rs, Cargo.toml): tonic-build generates Rust types from proto/salience.proto at cargo-build time, using a vendored protoc binary (protoc-bin-vendored) so no system install is required. New runtime deps: tonic, prost, async-stream, tokio-stream, rustls-pemfile. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-23 02:21:07 -04:00
// Logging (target-routed file logger)
pub mod logging;
2026-04-04 02:46:32 -04:00
// User interface (TUI, CLI)
pub mod user;
2026-04-04 02:46:32 -04:00
// Cognitive layer (session state machine, DMN, identity)
pub mod mind;
// Shared cognitive infrastructure — used by both agent and subconscious
pub mod agent;
// Memory graph
pub mod hippocampus;
// Autonomous agents
pub mod subconscious;
// Unified configuration
pub mod config;
pub mod config_writer;
// Session state
pub mod session;
// Shared utilities
pub mod util;
// Lock hold time tracking
pub mod locks;
// Re-export tracked locks as the default — swap to tokio::sync to disable tracking
pub use locks::TrackedMutex as Mutex;
pub use locks::TrackedMutexGuard as MutexGuard;
pub use locks::TrackedRwLock as RwLock;
pub use locks::TrackedRwLockReadGuard as RwLockReadGuard;
pub use locks::TrackedRwLockWriteGuard as RwLockWriteGuard;
// CLI handlers
pub mod cli;
// TUI for memory-search
// tui moved to src/user/tui/ (consciousness binary screens)
// Thalamus — universal notification routing and channel infrastructure
pub mod thalamus;
// MCP server — exposes memory tools over Unix socket
pub mod mcp_server;
// Re-export at crate root — capnp codegen emits `crate::daemon_capnp::` paths
pub use thalamus::daemon_capnp;
// Generated capnp bindings
pub mod memory_capnp {
include!(concat!(env!("OUT_DIR"), "/schema/memory_capnp.rs"));
}
pub mod channel_capnp {
include!(concat!(env!("OUT_DIR"), "/schema/channel_capnp.rs"));
}
// Re-exports — all existing crate::X paths keep working
pub use hippocampus::{
store, graph, lookups, query,
spectral, neuro, counters,
transcript, memory,
};
use hippocampus::query::engine as search;
use hippocampus::query::parser as query_parser;