From 118e727ca9e012d1fc9d1f11be2f5753ab97a702 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 7 May 2026 00:38:57 +0100 Subject: [PATCH] Wire Void Discord memory organs --- epiphany-core/Cargo.toml | 1 + .../src/bin/epiphany-face-discord.rs | 373 ++++++++++- epiphany-core/src/bin/epiphany-mvp-status.rs | 8 +- epiphany-core/src/bin/epiphany-void-memory.rs | 620 ++++++++++++++++++ notes/fresh-workspace-handoff.md | 13 +- state/agents/README.md | 16 + state/face-discord.toml | 4 + state/ledgers.msgpack | Bin 55265 -> 55540 bytes state/map.yaml | 6 +- state/void-memory.toml | 25 + 10 files changed, 1037 insertions(+), 29 deletions(-) create mode 100644 epiphany-core/src/bin/epiphany-void-memory.rs create mode 100644 state/void-memory.toml diff --git a/epiphany-core/Cargo.toml b/epiphany-core/Cargo.toml index 7dc289f0..e7e1a67c 100644 --- a/epiphany-core/Cargo.toml +++ b/epiphany-core/Cargo.toml @@ -18,6 +18,7 @@ codex-protocol = { path = "../vendor/codex/codex-rs/protocol" } cultcache-rs = { path = "../vendor/cultcache-rs" } cultnet-rs = { path = "../vendor/cultnet-rs" } ignore = "0.4.23" +postgres = "0.19" reqwest = { version = "0.12", features = ["blocking", "json"] } serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/epiphany-core/src/bin/epiphany-face-discord.rs b/epiphany-core/src/bin/epiphany-face-discord.rs index d5e36680..c07156b0 100644 --- a/epiphany-core/src/bin/epiphany-face-discord.rs +++ b/epiphany-core/src/bin/epiphany-face-discord.rs @@ -22,6 +22,9 @@ struct FaceConfig { allowed_channel_id: Option, allowed_channel_id_env: Option, bot_token_env: Option, + persona_name: Option, + persona_avatar_url: Option, + webhook_cache_path: Option, } fn main() -> Result<()> { @@ -37,6 +40,9 @@ fn main() -> Result<()> { let mut status = "ready".to_string(); let mut mood = "attentive".to_string(); let mut limit = 8_usize; + let mut persona_name: Option = None; + let mut persona_avatar_url: Option = None; + let mut reply_to_message_id: Option = None; while let Some(arg) = args.next() { match arg.as_str() { @@ -48,6 +54,13 @@ fn main() -> Result<()> { "--status" => status = next_value(&mut args, "--status")?, "--mood" => mood = next_value(&mut args, "--mood")?, "--limit" => limit = next_value(&mut args, "--limit")?.parse()?, + "--persona-name" => persona_name = Some(next_value(&mut args, "--persona-name")?), + "--persona-avatar-url" => { + persona_avatar_url = Some(next_value(&mut args, "--persona-avatar-url")?) + } + "--reply-to-message-id" => { + reply_to_message_id = Some(next_value(&mut args, "--reply-to-message-id")?) + } _ => return Err(anyhow!("unknown argument {arg:?}")), } } @@ -71,7 +84,15 @@ fn main() -> Result<()> { "post" => { let config = load_config(&config_path)?; let content = read_content(content)?; - run_post(&content, &config, &artifact_dir, channel_id)? + run_post( + &content, + &config, + &artifact_dir, + channel_id, + persona_name, + persona_avatar_url, + reply_to_message_id, + )? } "latest" => serde_json::json!({ "ok": true, @@ -129,6 +150,9 @@ fn run_post( config: &FaceConfig, artifact_dir: &Path, channel_id: Option, + persona_name: Option, + persona_avatar_url: Option, + reply_to_message_id: Option, ) -> Result { ensure_content(content, "Face chat")?; let configured_channel_id = allowed_channel_id(config); @@ -178,44 +202,247 @@ fn run_post( "draftPath": path, })); }; - let response = Client::new() - .post(format!( - "{DISCORD_API}/channels/{configured_channel_id}/messages" - )) - .header("Authorization", format!("Bot {token}")) - .header("User-Agent", "EpiphanyFace/0.1") - .json(&serde_json::json!({ "content": content.trim() })) - .send() - .context("Discord post failed")?; - if !response.status().is_success() { - return Err(anyhow!( - "Discord post failed with HTTP {}: {}", - response.status(), - response.text().unwrap_or_default() - )); - } - let payload: Value = response.json().context("Discord response was not JSON")?; + let persona = resolve_persona(config, persona_name, persona_avatar_url)?; + let posted = post_discord_message( + &token, + &configured_channel_id, + content.trim(), + reply_to_message_id.as_deref(), + persona.as_ref(), + config, + artifact_dir, + )?; let path = write_draft( content, config, artifact_dir, "posted", &format!( - "posted message {}", - payload - .get("id") - .and_then(Value::as_str) - .unwrap_or("unknown") + "posted message {} via {}", + posted.message_id, posted.transport ), )?; Ok(serde_json::json!({ "ok": true, "posted": true, - "messageId": payload.get("id"), + "messageId": posted.message_id, + "transport": posted.transport, + "persona": persona.map(|persona| serde_json::json!({ + "name": persona.name, + "avatarUrl": persona.avatar_url, + })), "draftPath": path, })) } +#[derive(Clone, Debug)] +struct FacePersona { + name: String, + avatar_url: Option, +} + +#[derive(Clone, Debug)] +struct PostedDiscordMessage { + message_id: String, + transport: &'static str, +} + +fn resolve_persona( + config: &FaceConfig, + persona_name: Option, + persona_avatar_url: Option, +) -> Result> { + let name = trim_optional(persona_name).or_else(|| trim_optional(config.persona_name.clone())); + let avatar_url = trim_optional(persona_avatar_url) + .or_else(|| trim_optional(config.persona_avatar_url.clone())); + if name.is_none() && avatar_url.is_none() { + return Ok(None); + } + let Some(name) = name else { + return Err(anyhow!( + "persona-name is required when posting with a persona avatar" + )); + }; + Ok(Some(FacePersona { + name: name.chars().take(80).collect(), + avatar_url, + })) +} + +fn post_discord_message( + token: &str, + channel_id: &str, + content: &str, + reply_to_message_id: Option<&str>, + persona: Option<&FacePersona>, + config: &FaceConfig, + artifact_dir: &Path, +) -> Result { + if let Some(persona) = persona { + return post_discord_persona_message( + token, + channel_id, + content, + reply_to_message_id, + persona, + config, + artifact_dir, + ); + } + + let response = Client::new() + .post(format!("{DISCORD_API}/channels/{channel_id}/messages")) + .header("Authorization", format!("Bot {token}")) + .header("User-Agent", "EpiphanyFace/0.1") + .json(&serde_json::json!({ + "content": content, + "message_reference": reply_to_message_id.map(|message_id| serde_json::json!({ + "message_id": message_id, + "fail_if_not_exists": false, + })), + "allowed_mentions": {"parse": []}, + })) + .send() + .context("Discord post failed")?; + let payload = decode_discord_json(response, "Discord message post")?; + Ok(PostedDiscordMessage { + message_id: required_discord_id(&payload, "Discord message post")?, + transport: "bot", + }) +} + +fn post_discord_persona_message( + token: &str, + channel_id: &str, + content: &str, + reply_to_message_id: Option<&str>, + persona: &FacePersona, + config: &FaceConfig, + artifact_dir: &Path, +) -> Result { + let target = resolve_webhook_target(token, channel_id)?; + let cache_path = persona_webhook_cache_path(config, artifact_dir); + let mut webhook = cached_persona_webhook(&cache_path, &target.webhook_channel_id)?; + if webhook.is_none() { + let created = create_persona_webhook(token, &target.webhook_channel_id)?; + write_cached_persona_webhook(&cache_path, &target.webhook_channel_id, &created)?; + webhook = Some(created); + } + let webhook = webhook.context("persona webhook should exist")?; + match execute_persona_webhook(&webhook, &target, content, reply_to_message_id, persona) { + Ok(posted) => Ok(posted), + Err(error) if is_stale_webhook_error(&error) => { + clear_cached_persona_webhook(&cache_path, &target.webhook_channel_id)?; + let refreshed = create_persona_webhook(token, &target.webhook_channel_id)?; + write_cached_persona_webhook(&cache_path, &target.webhook_channel_id, &refreshed)?; + execute_persona_webhook(&refreshed, &target, content, reply_to_message_id, persona) + } + Err(error) => Err(error), + } +} + +#[derive(Clone, Debug)] +struct WebhookTarget { + webhook_channel_id: String, + thread_id: Option, +} + +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +struct CachedWebhookRecord { + id: String, + token: String, + channel_id: String, + name: String, + created_at: String, +} + +fn resolve_webhook_target(token: &str, channel_id: &str) -> Result { + let response = Client::new() + .get(format!("{DISCORD_API}/channels/{channel_id}")) + .header("Authorization", format!("Bot {token}")) + .header("User-Agent", "EpiphanyFace/0.1") + .send() + .context("Discord channel lookup failed")?; + let payload = decode_discord_json(response, "Discord channel lookup")?; + let channel_type = payload["type"] + .as_i64() + .ok_or_else(|| anyhow!("Discord channel lookup returned no numeric type"))?; + let id = required_discord_id(&payload, "Discord channel lookup")?; + if matches!(channel_type, 10 | 11 | 12) { + let parent_id = payload["parent_id"].as_str().ok_or_else(|| { + anyhow!("Discord thread {id} has no parent channel for webhook routing") + })?; + return Ok(WebhookTarget { + webhook_channel_id: parent_id.to_string(), + thread_id: Some(id), + }); + } + Ok(WebhookTarget { + webhook_channel_id: id, + thread_id: None, + }) +} + +fn create_persona_webhook(token: &str, channel_id: &str) -> Result { + let response = Client::new() + .post(format!("{DISCORD_API}/channels/{channel_id}/webhooks")) + .header("Authorization", format!("Bot {token}")) + .header("User-Agent", "EpiphanyFace/0.1") + .json(&serde_json::json!({"name": "Epiphany Persona Pipe"})) + .send() + .context("Discord webhook creation failed")?; + let payload = decode_discord_json(response, "Discord webhook creation")?; + let id = required_discord_id(&payload, "Discord webhook creation")?; + let token = payload["token"] + .as_str() + .ok_or_else(|| anyhow!("Discord webhook creation returned no executable token"))?; + Ok(CachedWebhookRecord { + id, + token: token.to_string(), + channel_id: channel_id.to_string(), + name: "Epiphany Persona Pipe".to_string(), + created_at: now_iso(), + }) +} + +fn execute_persona_webhook( + webhook: &CachedWebhookRecord, + target: &WebhookTarget, + content: &str, + reply_to_message_id: Option<&str>, + persona: &FacePersona, +) -> Result { + let mut url = format!( + "{DISCORD_API}/webhooks/{}/{}?wait=true", + webhook.id, webhook.token + ); + if let Some(thread_id) = &target.thread_id { + url.push_str("&thread_id="); + url.push_str(thread_id); + } + let response = Client::new() + .post(url) + .header("User-Agent", "EpiphanyFace/0.1") + .json(&serde_json::json!({ + "content": content, + "username": persona.name, + "avatar_url": persona.avatar_url, + "message_reference": reply_to_message_id.map(|message_id| serde_json::json!({ + "message_id": message_id, + "fail_if_not_exists": false, + })), + "allowed_mentions": {"parse": []}, + })) + .send() + .context("Discord webhook execution failed")?; + let payload = decode_discord_json(response, "Discord webhook execution")?; + Ok(PostedDiscordMessage { + message_id: required_discord_id(&payload, "Discord webhook execution")?, + transport: "webhook", + }) +} + fn run_smoke() -> Result { let temp_dir = scoped_temp_dir("epiphany-face-discord-smoke")?; let config = FaceConfig { @@ -223,6 +450,9 @@ fn run_smoke() -> Result { allowed_channel_id: None, allowed_channel_id_env: Some("EPIPHANY_FACE_AQUARIUM_CHANNEL_ID_TEST".to_string()), bot_token_env: Some("DISCORD_BOT_TOKEN_TEST".to_string()), + persona_name: Some("Smoke Face".to_string()), + persona_avatar_url: Some("https://example.invalid/face.png".to_string()), + webhook_cache_path: Some(temp_dir.join("webhook-cache.json")), }; unsafe { env::remove_var("EPIPHANY_FACE_AQUARIUM_CHANNEL_ID_TEST"); @@ -246,6 +476,9 @@ fn run_smoke() -> Result { &config, &temp_dir, None, + None, + None, + None, )?; unsafe { env::set_var("EPIPHANY_FACE_AQUARIUM_CHANNEL_ID_TEST", "123"); @@ -255,6 +488,9 @@ fn run_smoke() -> Result { &config, &temp_dir, Some("456".to_string()), + Some("Wrong Face".to_string()), + None, + None, )?; let ok = draft["ok"] == true && bubble["ok"] == true @@ -289,6 +525,8 @@ fn write_draft( "reason": reason, "allowed_channel_name": if config.allowed_channel_name.is_empty() { "#aquarium" } else { &config.allowed_channel_name }, "allowed_channel_id": allowed_channel_id(config), + "persona_name": config.persona_name, + "persona_avatar_url": config.persona_avatar_url, "content": content.trim(), }); let path = artifact_dir.join(format!("face-chat-{}-{}.json", now_stamp(), short_id())); @@ -354,6 +592,87 @@ fn latest_face_artifacts(artifact_dir: &Path, limit: usize) -> Vec { .collect() } +fn persona_webhook_cache_path(config: &FaceConfig, artifact_dir: &Path) -> PathBuf { + config + .webhook_cache_path + .clone() + .unwrap_or_else(|| artifact_dir.join("discord-webhook-cache.json")) +} + +fn cached_persona_webhook(path: &Path, channel_id: &str) -> Result> { + let cache = read_persona_webhook_cache(path)?; + let Some(value) = cache.get(channel_id) else { + return Ok(None); + }; + let record: CachedWebhookRecord = serde_json::from_value(value.clone()) + .with_context(|| format!("cached persona webhook for channel {channel_id} is malformed"))?; + Ok((record.channel_id == channel_id).then_some(record)) +} + +fn read_persona_webhook_cache(path: &Path) -> Result> { + match fs::read_to_string(path) { + Ok(raw) => { + let value: Value = serde_json::from_str(strip_bom(&raw)) + .with_context(|| format!("failed to decode {}", path.display()))?; + Ok(value.as_object().cloned().unwrap_or_default()) + } + Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(serde_json::Map::new()), + Err(error) => Err(error).with_context(|| format!("failed to read {}", path.display())), + } +} + +fn write_cached_persona_webhook( + path: &Path, + channel_id: &str, + webhook: &CachedWebhookRecord, +) -> Result<()> { + let mut cache = read_persona_webhook_cache(path)?; + cache.insert(channel_id.to_string(), serde_json::to_value(webhook)?); + write_json(path, &Value::Object(cache)) +} + +fn clear_cached_persona_webhook(path: &Path, channel_id: &str) -> Result<()> { + let mut cache = read_persona_webhook_cache(path)?; + if cache.remove(channel_id).is_some() { + write_json(path, &Value::Object(cache))?; + } + Ok(()) +} + +fn decode_discord_json(response: reqwest::blocking::Response, context: &str) -> Result { + let status = response.status(); + let body = response + .text() + .with_context(|| format!("{context} response body read failed"))?; + if !status.is_success() { + return Err(anyhow!("{context} failed with HTTP {status}: {body}")); + } + serde_json::from_str(&body).with_context(|| format!("{context} response was not JSON")) +} + +fn required_discord_id(payload: &Value, context: &str) -> Result { + payload["id"] + .as_str() + .map(str::to_string) + .ok_or_else(|| anyhow!("{context} returned no id")) +} + +fn is_stale_webhook_error(error: &anyhow::Error) -> bool { + let message = error.to_string(); + message.contains("Discord webhook execution failed with HTTP 401") + || message.contains("Discord webhook execution failed with HTTP 404") +} + +fn trim_optional(value: Option) -> Option { + value + .map(|value| value.trim().to_string()) + .filter(|value| !value.is_empty()) +} + +fn strip_bom(value: &str) -> &str { + value.strip_prefix('\u{feff}').unwrap_or(value) +} + fn load_config(path: &Path) -> Result { let raw = fs::read_to_string(path).with_context(|| format!("failed to read {}", path.display()))?; @@ -377,6 +696,9 @@ fn load_config(path: &Path) -> Result { .as_str() .map(str::to_string), bot_token_env: payload["bot_token_env"].as_str().map(str::to_string), + persona_name: payload["persona_name"].as_str().map(str::to_string), + persona_avatar_url: payload["persona_avatar_url"].as_str().map(str::to_string), + webhook_cache_path: payload["webhook_cache_path"].as_str().map(PathBuf::from), }); } Ok(FaceConfig { @@ -385,6 +707,9 @@ fn load_config(path: &Path) -> Result { allowed_channel_id: toml_string(&raw, "allowed_channel_id"), allowed_channel_id_env: toml_string(&raw, "allowed_channel_id_env"), bot_token_env: toml_string(&raw, "bot_token_env"), + persona_name: toml_string(&raw, "persona_name"), + persona_avatar_url: toml_string(&raw, "persona_avatar_url"), + webhook_cache_path: toml_string(&raw, "webhook_cache_path").map(PathBuf::from), }) } diff --git a/epiphany-core/src/bin/epiphany-mvp-status.rs b/epiphany-core/src/bin/epiphany-mvp-status.rs index 087623e3..d4104ac5 100644 --- a/epiphany-core/src/bin/epiphany-mvp-status.rs +++ b/epiphany-core/src/bin/epiphany-mvp-status.rs @@ -241,8 +241,13 @@ fn run_status(args: &Args) -> Result { "status": "ready", "artifactDir": face_dir, "latestArtifacts": latest_face.get("latestArtifacts").cloned().unwrap_or_else(|| json!([])), - "availableActions": ["faceBubble", "characterTurn"], + "availableActions": ["faceBubble", "characterTurn", "discordPersonaPost"], }); + let void_memory = native_json( + "epiphany-void-memory", + &["status", "--config", "state/void-memory.toml"], + ) + .unwrap_or_else(|error| json!({"ok": false, "error": error.to_string()})); let status = json!({ "threadId": thread_id, "read": read, @@ -258,6 +263,7 @@ fn run_status(args: &Args) -> Result { "coordinator": coordinator, "heartbeat": heartbeat, "face": face, + "voidMemory": void_memory, }); Ok(sanitize_for_operator(status)) } diff --git a/epiphany-core/src/bin/epiphany-void-memory.rs b/epiphany-core/src/bin/epiphany-void-memory.rs new file mode 100644 index 00000000..40ba6252 --- /dev/null +++ b/epiphany-core/src/bin/epiphany-void-memory.rs @@ -0,0 +1,620 @@ +use anyhow::Context; +use anyhow::Result; +use anyhow::anyhow; +use postgres::NoTls; +use reqwest::blocking::Client; +use reqwest::blocking::ClientBuilder; +use reqwest::header::HeaderMap; +use reqwest::header::HeaderValue; +use serde::Deserialize; +use serde_json::Value; +use serde_json::json; +use std::env; +use std::fs; +use std::path::Path; +use std::path::PathBuf; +use std::time::Duration; + +const STATUS_SCHEMA_VERSION: &str = "epiphany.void_memory_status.v0"; +const SEARCH_SCHEMA_VERSION: &str = "epiphany.void_memory_search.v0"; +const CONTEXT_SCHEMA_VERSION: &str = "epiphany.void_message_context.v0"; +const DEFAULT_CONFIG: &str = "state/void-memory.toml"; +const MAX_LIMIT: usize = 20; + +fn main() -> Result<()> { + let mut args = env::args().skip(1); + let Some(command) = args.next() else { + return usage(); + }; + let mut config_path = PathBuf::from(DEFAULT_CONFIG); + let mut query: Option = None; + let mut message_id: Option = None; + let mut limit = 5_usize; + let mut before = 4_usize; + let mut after = 4_usize; + let mut guild_id: Option = None; + let mut channel_id: Option = None; + let mut author_id: Option = None; + let mut repo_name: Option = None; + let mut path_prefix: Option = None; + let mut language: Option = None; + + while let Some(arg) = args.next() { + match arg.as_str() { + "--config" => config_path = PathBuf::from(take(&mut args, "--config")?), + "--query" => query = Some(take(&mut args, "--query")?), + "--message-id" => message_id = Some(take(&mut args, "--message-id")?), + "--limit" => limit = take(&mut args, "--limit")?.parse()?, + "--before" => before = take(&mut args, "--before")?.parse()?, + "--after" => after = take(&mut args, "--after")?.parse()?, + "--guild-id" => guild_id = Some(take(&mut args, "--guild-id")?), + "--channel-id" => channel_id = Some(take(&mut args, "--channel-id")?), + "--author-id" => author_id = Some(take(&mut args, "--author-id")?), + "--repo-name" => repo_name = Some(take(&mut args, "--repo-name")?), + "--path-prefix" => path_prefix = Some(take(&mut args, "--path-prefix")?), + "--language" => language = Some(take(&mut args, "--language")?), + other => return Err(anyhow!("unknown argument {other:?}")), + } + } + + limit = limit.clamp(1, MAX_LIMIT); + before = before.min(MAX_LIMIT); + after = after.min(MAX_LIMIT); + let config = BridgeConfig::load(&config_path)?; + let output = match command.as_str() { + "status" => run_status(&config), + "search-history" => run_search( + &config, + query.context("missing --query")?, + limit, + SearchCorpus::History { + guild_id, + channel_id, + author_id, + }, + ), + "search-sources" => run_search( + &config, + query.context("missing --query")?, + limit, + SearchCorpus::Source { + repo_name, + path_prefix, + language, + }, + ), + "message-context" => run_message_context( + &config, + message_id.context("missing --message-id")?, + before, + after, + ), + "smoke" => run_smoke(), + _ => return usage(), + }?; + println!("{}", serde_json::to_string_pretty(&output)?); + Ok(()) +} + +#[derive(Clone, Debug)] +struct BridgeConfig { + database_dsn_env: Option, + database_dsn: String, + qdrant_url: String, + qdrant_api_key_env: Option, + qdrant_history_collection: String, + qdrant_source_collection: String, + qdrant_timeout_ms: u64, + ollama_base_url: String, + ollama_model: String, + ollama_timeout_ms: u64, + history_query_instruction: String, + source_query_instruction: String, + archive_path: PathBuf, +} + +impl BridgeConfig { + fn load(path: &Path) -> Result { + let raw = fs::read_to_string(path) + .with_context(|| format!("failed to read {}", path.display()))?; + Ok(Self { + database_dsn_env: toml_string(&raw, "database_dsn_env"), + database_dsn: toml_string(&raw, "database_dsn") + .unwrap_or_else(|| "postgres://voidbot:voidbot@localhost:5432/voidbot".to_string()), + qdrant_url: normalize_base_url( + &toml_string(&raw, "qdrant_url") + .unwrap_or_else(|| "http://127.0.0.1:6333".to_string()), + ), + qdrant_api_key_env: toml_string(&raw, "qdrant_api_key_env"), + qdrant_history_collection: toml_string(&raw, "qdrant_history_collection") + .unwrap_or_else(|| "voidbot_discord_history_chunks".to_string()), + qdrant_source_collection: toml_string(&raw, "qdrant_source_collection") + .unwrap_or_else(|| "voidbot_repository_source_chunks".to_string()), + qdrant_timeout_ms: toml_number(&raw, "qdrant_timeout_ms").unwrap_or(30000), + ollama_base_url: normalize_base_url( + &toml_string(&raw, "ollama_base_url") + .unwrap_or_else(|| "http://127.0.0.1:11434".to_string()), + ), + ollama_model: toml_string(&raw, "ollama_model") + .unwrap_or_else(|| "qwen3-embedding:0.6b".to_string()), + ollama_timeout_ms: toml_number(&raw, "ollama_timeout_ms").unwrap_or(30000), + history_query_instruction: toml_string(&raw, "history_query_instruction") + .unwrap_or_else(|| "Given a Discord history question, retrieve relevant messages and discussion snippets that answer it.".to_string()), + source_query_instruction: toml_string(&raw, "source_query_instruction") + .unwrap_or_else(|| "Given a source-tree, codebase, or lore question, retrieve relevant files, code snippets, and lore passages that answer it.".to_string()), + archive_path: PathBuf::from( + toml_string(&raw, "archive_path") + .unwrap_or_else(|| r"E:\Projects\VoidBot\.voidbot\rag\messages.json".to_string()), + ), + }) + } + + fn database_dsn(&self) -> String { + self.database_dsn_env + .as_ref() + .and_then(|name| env::var(name).ok()) + .filter(|value| !value.trim().is_empty()) + .unwrap_or_else(|| self.database_dsn.clone()) + } + + fn qdrant_api_key(&self) -> Option { + self.qdrant_api_key_env + .as_ref() + .and_then(|name| env::var(name).ok()) + .filter(|value| !value.trim().is_empty()) + } +} + +enum SearchCorpus { + History { + guild_id: Option, + channel_id: Option, + author_id: Option, + }, + Source { + repo_name: Option, + path_prefix: Option, + language: Option, + }, +} + +fn run_status(config: &BridgeConfig) -> Result { + let postgres = postgres_status(config); + let qdrant = qdrant_status(config); + let archive = archive_status(&config.archive_path); + Ok(json!({ + "schemaVersion": STATUS_SCHEMA_VERSION, + "ok": postgres["ok"].as_bool().unwrap_or(false) + || qdrant["history"]["ok"].as_bool().unwrap_or(false) + || archive["ok"].as_bool().unwrap_or(false), + "postgres": postgres, + "qdrant": qdrant, + "archive": archive, + "notes": [ + "Void currently keeps raw Discord archives file-backed under .voidbot while Qdrant owns semantic history/source vectors.", + "Postgres is checked for live Void state organs: jobs, audit events, interaction memory, identity profiles, and rate limits." + ], + })) +} + +fn run_search( + config: &BridgeConfig, + query: String, + limit: usize, + corpus: SearchCorpus, +) -> Result { + let (collection, instruction, filter, corpus_name) = match corpus { + SearchCorpus::History { + guild_id, + channel_id, + author_id, + } => ( + config.qdrant_history_collection.as_str(), + config.history_query_instruction.as_str(), + qdrant_filter([ + ("corpusKind", Some("discord_history".to_string())), + ("guildId", guild_id), + ("channelId", channel_id), + ("authorId", author_id), + ]), + "discord_history", + ), + SearchCorpus::Source { + repo_name, + path_prefix, + language, + } => ( + config.qdrant_source_collection.as_str(), + config.source_query_instruction.as_str(), + qdrant_filter([ + ("corpusKind", Some("repository_source".to_string())), + ("repoName", repo_name), + ("pathPrefixes", path_prefix.map(normalize_path_prefix)), + ("language", language), + ]), + "repository_source", + ), + }; + let vector = embed_query(config, instruction, &query)?; + let hits = query_qdrant(config, collection, &vector, limit, filter)?; + Ok(json!({ + "schemaVersion": SEARCH_SCHEMA_VERSION, + "ok": true, + "corpus": corpus_name, + "query": query, + "collection": collection, + "results": hits, + })) +} + +fn run_message_context( + config: &BridgeConfig, + message_id: String, + before: usize, + after: usize, +) -> Result { + let archive = load_archive(&config.archive_path)?; + let Some(anchor) = archive + .messages + .iter() + .find(|message| message.id == message_id) + else { + return Ok(json!({ + "schemaVersion": CONTEXT_SCHEMA_VERSION, + "ok": false, + "reason": "message-not-found", + "messageId": message_id, + })); + }; + let mut messages = archive + .messages + .iter() + .filter(|message| !message.deleted()) + .filter(|message| belongs_to_same_conversation(message, anchor)) + .cloned() + .collect::>(); + messages.sort_by(|left, right| left.timestamp.cmp(&right.timestamp)); + let anchor_index = messages + .iter() + .position(|message| message.id == message_id) + .context("anchor disappeared from context set")?; + let start = anchor_index.saturating_sub(before); + let end = (anchor_index + after + 1).min(messages.len()); + Ok(json!({ + "schemaVersion": CONTEXT_SCHEMA_VERSION, + "ok": true, + "messageId": message_id, + "archivePath": config.archive_path, + "messages": messages[start..end].iter().map(format_message).collect::>(), + })) +} + +fn postgres_status(config: &BridgeConfig) -> Value { + match postgres::Client::connect(&config.database_dsn(), NoTls) { + Ok(mut client) => { + let tables = [ + "jobs", + "audit_events", + "interaction_memory_events", + "interaction_identity_profiles", + "void_usage_rate_limit_state", + ]; + let counts = tables + .into_iter() + .map(|table| { + let count = client + .query_one(&format!("select count(*)::bigint from {table}"), &[]) + .map(|row| row.get::<_, i64>(0)); + (table, count) + }) + .map(|(table, count)| match count { + Ok(count) => json!({"table": table, "ok": true, "count": count}), + Err(error) => json!({"table": table, "ok": false, "error": error.to_string()}), + }) + .collect::>(); + json!({"ok": true, "dsn": redact_dsn(&config.database_dsn()), "tables": counts}) + } + Err(error) => json!({ + "ok": false, + "dsn": redact_dsn(&config.database_dsn()), + "error": error.to_string(), + }), + } +} + +fn qdrant_status(config: &BridgeConfig) -> Value { + json!({ + "url": config.qdrant_url, + "history": qdrant_collection_status(config, &config.qdrant_history_collection), + "source": qdrant_collection_status(config, &config.qdrant_source_collection), + }) +} + +fn qdrant_collection_status(config: &BridgeConfig, collection: &str) -> Value { + let client = qdrant_client(config); + match client + .get(format!("{}/collections/{collection}", config.qdrant_url)) + .send() + { + Ok(response) => match decode_json(response) { + Ok(payload) => json!({ + "ok": true, + "collection": collection, + "pointsCount": payload.pointer("/result/points_count"), + "vectorsCount": payload.pointer("/result/vectors_count"), + "status": payload.pointer("/result/status"), + }), + Err(error) => { + json!({"ok": false, "collection": collection, "error": error.to_string()}) + } + }, + Err(error) => json!({"ok": false, "collection": collection, "error": error.to_string()}), + } +} + +fn archive_status(path: &Path) -> Value { + match load_archive(path) { + Ok(archive) => json!({ + "ok": true, + "path": path, + "messageCount": archive.messages.len(), + "activeMessageCount": archive.messages.iter().filter(|message| !message.deleted()).count(), + }), + Err(error) => json!({"ok": false, "path": path, "error": error.to_string()}), + } +} + +fn embed_query(config: &BridgeConfig, instruction: &str, query: &str) -> Result> { + let client = ClientBuilder::new() + .timeout(Duration::from_millis(config.ollama_timeout_ms)) + .build() + .context("failed to build Ollama client")?; + let formatted = format!("Instruct: {instruction}\nQuery: {query}"); + let response = client + .post(format!("{}/api/embed", config.ollama_base_url)) + .json(&json!({"model": config.ollama_model, "input": [formatted]})) + .send() + .context("failed to contact Ollama embedding backend")?; + let payload = decode_json(response).context("failed to decode Ollama embedding response")?; + let embedding = payload["embeddings"] + .as_array() + .and_then(|items| items.first()) + .and_then(Value::as_array) + .ok_or_else(|| anyhow!("Ollama embedding response did not include embeddings[0]"))?; + embedding + .iter() + .map(|value| { + value + .as_f64() + .map(|value| value as f32) + .ok_or_else(|| anyhow!("Ollama embedding included a non-number")) + }) + .collect() +} + +fn query_qdrant( + config: &BridgeConfig, + collection: &str, + vector: &[f32], + limit: usize, + filter: Option, +) -> Result> { + let response = qdrant_client(config) + .post(format!( + "{}/collections/{collection}/points/query", + config.qdrant_url + )) + .json(&json!({ + "query": vector, + "limit": limit, + "with_payload": true, + "with_vector": false, + "filter": filter, + })) + .send() + .with_context(|| format!("failed to query Qdrant collection {collection}"))?; + let payload = decode_json(response)?; + let points = payload + .pointer("/result/points") + .and_then(Value::as_array) + .cloned() + .unwrap_or_default(); + Ok(points.into_iter().filter_map(format_qdrant_point).collect()) +} + +fn format_qdrant_point(point: Value) -> Option { + let payload = point.get("payload")?; + Some(json!({ + "score": point.get("score"), + "chunkId": payload.get("chunkId"), + "sourceId": payload.get("sourceId"), + "sourceKind": payload.get("sourceKind"), + "text": payload.get("text"), + "metadata": payload.get("metadata"), + })) +} + +fn qdrant_client(config: &BridgeConfig) -> Client { + let mut headers = HeaderMap::new(); + if let Some(api_key) = config.qdrant_api_key() { + if let Ok(value) = HeaderValue::from_str(&api_key) { + headers.insert("api-key", value); + } + } + ClientBuilder::new() + .timeout(Duration::from_millis(config.qdrant_timeout_ms)) + .default_headers(headers) + .build() + .expect("Qdrant client should build") +} + +fn qdrant_filter(fields: [(&str, Option); N]) -> Option { + let must = fields + .into_iter() + .filter_map(|(key, value)| { + let value = value?.trim().to_string(); + (!value.is_empty()).then(|| json!({"key": key, "match": {"value": value}})) + }) + .collect::>(); + (!must.is_empty()).then(|| json!({"must": must})) +} + +#[derive(Clone, Debug, Deserialize)] +struct ArchiveStore { + messages: Vec, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct ArchivedMessage { + id: String, + guild_id: Option, + channel_id: String, + author_id: String, + author_name: String, + content: String, + timestamp: String, + deleted_at: Option, + thread_id: Option, + metadata: Option, +} + +impl ArchivedMessage { + fn deleted(&self) -> bool { + self.deleted_at + .as_deref() + .is_some_and(|value| !value.is_empty()) + } +} + +fn load_archive(path: &Path) -> Result { + let raw = + fs::read_to_string(path).with_context(|| format!("failed to read {}", path.display()))?; + serde_json::from_str(&raw).with_context(|| format!("failed to decode {}", path.display())) +} + +fn belongs_to_same_conversation(message: &ArchivedMessage, anchor: &ArchivedMessage) -> bool { + message.channel_id == anchor.channel_id && message.thread_id == anchor.thread_id +} + +fn format_message(message: &ArchivedMessage) -> Value { + json!({ + "id": message.id, + "timestamp": message.timestamp, + "authorId": message.author_id, + "authorName": message.author_name, + "guildId": message.guild_id, + "channelId": message.channel_id, + "threadId": message.thread_id, + "content": message.content, + "jumpUrl": message.metadata.as_ref().and_then(|metadata| metadata.get("jumpUrl")), + }) +} + +fn run_smoke() -> Result { + let dir = env::temp_dir().join(format!( + "epiphany-void-memory-smoke-{}", + uuid::Uuid::new_v4() + )); + fs::create_dir_all(&dir)?; + let archive_path = dir.join("messages.json"); + fs::write( + &archive_path, + serde_json::to_string_pretty(&json!({ + "version": 1, + "messages": [ + {"id":"1","guildId":"g","channelId":"c","authorId":"a","authorName":"A","content":"before","timestamp":"2026-05-06T00:00:00Z","threadId":"t","metadata":{"jumpUrl":"https://discord.invalid/1"}}, + {"id":"2","guildId":"g","channelId":"c","authorId":"b","authorName":"B","content":"anchor","timestamp":"2026-05-06T00:01:00Z","threadId":"t","metadata":{"jumpUrl":"https://discord.invalid/2"}}, + {"id":"3","guildId":"g","channelId":"c","authorId":"a","authorName":"A","content":"after","timestamp":"2026-05-06T00:02:00Z","threadId":"t","metadata":{"jumpUrl":"https://discord.invalid/3"}} + ] + }))?, + )?; + let config = BridgeConfig { + database_dsn_env: None, + database_dsn: "postgres://voidbot:voidbot@localhost:5432/voidbot".to_string(), + qdrant_url: "http://127.0.0.1:1".to_string(), + qdrant_api_key_env: None, + qdrant_history_collection: "history".to_string(), + qdrant_source_collection: "source".to_string(), + qdrant_timeout_ms: 50, + ollama_base_url: "http://127.0.0.1:1".to_string(), + ollama_model: "qwen3-embedding:0.6b".to_string(), + ollama_timeout_ms: 50, + history_query_instruction: "history".to_string(), + source_query_instruction: "source".to_string(), + archive_path, + }; + let context = run_message_context(&config, "2".to_string(), 1, 1)?; + let status = run_status(&config)?; + let _ = fs::remove_dir_all(&dir); + Ok(json!({ + "ok": context["ok"] == true + && context["messages"].as_array().is_some_and(|messages| messages.len() == 3), + "context": context, + "status": status, + })) +} + +fn decode_json(response: reqwest::blocking::Response) -> Result { + let status = response.status(); + let body = response.text().context("failed to read response body")?; + if !status.is_success() { + return Err(anyhow!("HTTP {status}: {body}")); + } + serde_json::from_str(&body).context("response was not JSON") +} + +fn toml_string(raw: &str, key: &str) -> Option { + raw.lines() + .map(str::trim) + .filter(|line| !line.starts_with('#')) + .find_map(|line| { + let (left, right) = line.split_once('=')?; + (left.trim() == key).then(|| parse_toml_string(right.trim()))? + }) +} + +fn parse_toml_string(value: &str) -> Option { + value + .strip_prefix('"') + .and_then(|value| value.strip_suffix('"')) + .map(|value| value.replace("\\\\", "\\")) +} + +fn toml_number(raw: &str, key: &str) -> Option { + raw.lines() + .map(str::trim) + .filter(|line| !line.starts_with('#')) + .find_map(|line| { + let (left, right) = line.split_once('=')?; + (left.trim() == key).then(|| right.trim().parse().ok())? + }) +} + +fn normalize_base_url(value: &str) -> String { + value.trim_end_matches('/').to_string() +} + +fn normalize_path_prefix(value: String) -> String { + value.replace('\\', "/").trim_start_matches('/').to_string() +} + +fn redact_dsn(dsn: &str) -> String { + if let Some((prefix, rest)) = dsn.split_once("://") { + if let Some(at) = rest.find('@') { + return format!("{prefix}://***@{}", &rest[at + 1..]); + } + } + dsn.to_string() +} + +fn take(args: &mut impl Iterator, name: &str) -> Result { + args.next() + .ok_or_else(|| anyhow!("{name} requires a value")) +} + +fn usage() -> Result<()> { + Err(anyhow!( + "usage: epiphany-void-memory [--config ] [--query ] [--message-id ] [--limit ]" + )) +} diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 0ce36036..86a35779 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -49,7 +49,8 @@ remembers doctrine; the branch remembers the blade. - The first Ghostlight-derived timing slice is landed in Epiphany, but Ghostlight is reference lineage rather than a sibling runtime to preserve. `epiphany-heartbeat-store init --profile ghostlight-scene --scene-id --scene-participant ` creates a typed CultCache MessagePack scene heartbeat store whose participants are `arena=scene`, `participantKind=character`; `tick` emits `ghostlight.initiative_schedule.v0` receipts with `scene_turn` actions and local-affordance basis. The generic Epiphany maintenance lanes are not auto-patched into scene stores. - The first Void-derived routine slice is landed in Epiphany, but VoidBot is reference lineage rather than a runtime dependency. `epiphany-heartbeat-store routine --store .\state\agent-heartbeats.msgpack --artifact-dir .\.epiphany-heartbeats --agent-store .\state\agents.msgpack` reads typed role dossiers, computes bounded memory resonance, maintains incubation themes, runs analytic and associative cognition lanes, writes bridge syntheses/saturation/tension, projects the active thought cluster through each role's Ghostlight-shaped personality vectors, derives participant-local reactions, applies personality/mood timing, advances the sleep/dream cycle, updates the typed heartbeat store, and emits an auditable `epiphany.void_routine.v0` receipt. This mutates only heartbeat physiology fields: project truth and role memory mutation remain on their reviewed surfaces. - Manual Codex-run rumination still has an explicit aftercare rule until Epiphany owns the full sleep consolidator. In the intended Epiphany cycle, sub-agents ruminate when idle and distill when they sleep; in this supervising Codex thread, a heartbeat/routine vigil is only physiology until a separate closing pass reviews the receipts and decides whether map, handoff, evidence, or role self-memory should change. -- The Face public-surface pass is landed as a bounded lane. Face's role dossier lives in `state/agents.msgpack`; `epiphany_specialists.toml` gives it a VoidBot-heartbeat-derived prompt stripped of moderation authority; `state/face-discord.toml` and the native `epiphany-face-discord` binary enforce that Face may interact only through #aquarium. Missing channel id or token writes candidate chat artifacts instead of posting elsewhere. +- The Face public-surface pass is landed as a bounded lane. Face's role dossier lives in `state/agents.msgpack`; `epiphany_specialists.toml` gives it a VoidBot-heartbeat-derived prompt stripped of moderation authority; `state/face-discord.toml` and the native `epiphany-face-discord` binary enforce that Face may interact only through #aquarium. Missing channel id or token writes candidate chat artifacts instead of posting elsewhere. If a Face has a persona name/avatar, `post` uses the shared Discord webhook pipe so each Epiphany can speak with its own nickname and avatar without a separate bot identity. +- The Void memory bridge is now native enough to keep the useful organs attached. `state/void-memory.toml` and `epiphany-void-memory` can check Void's Docker Postgres state spine, query Qdrant Discord-history and source/lore collections with the configured Ollama embedding model, and fetch raw archive context windows from Void's file-backed Discord archive. Native `epiphany-mvp-status` includes a `voidMemory` block so Aquarium/backend clients can inspect whether the mouth and memory are actually wired. - The first Epiphany-native character-loop pass is landed. `epiphany-character-loop turn --role face --stimulus ` loads Face's typed dossier from `state/agents.msgpack` and emits an auditable `epiphany.character_turn_packet.v0` packet with projected local context, visible stimulus, allowed outputs, and guardrails. The same packet builder works for other role ids, because every organ already has a Ghostlight-shaped dossier. - The heartbeat/Face operator API pass is landed. Native `epiphany-heartbeat-store status` returns machine-readable initiative state plus CultCache store presence, thought appraisals, and derived reactions; native `epiphany-face-discord bubble` writes Discord-independent `epiphany.face_bubble.v0` artifacts, and native `epiphany-mvp-status` includes `heartbeat` and `face` blocks. Aquarium should call native/backend surfaces rather than resurrecting deleted Python action shims. - The native runtime-spine pass is landed as a first vertebra, not a full daemon. `state/runtime-spine.msgpack` is the default store, `.epiphany-dogfood/runtime-spine-job/runtime.msgpack` and `hello.cultnet` are the latest job/result smoke artifacts, and specialist launch/result flows now route through typed heartbeat/runtime-spine documents. Its CultNet hello advertises mutation contracts for runtime/session/job/memory/heartbeat/ledger documents, with coordinator-owned intent/receipt paths for writes. @@ -144,7 +145,7 @@ The current spine, blessed but not yet finished: - Ghostlight-derived heartbeat initiative scheduling through the native `epiphany-heartbeat-store` binary, with Self and Face included as first-class Epiphany maintenance participants, Ghostlight scene characters supported through the same timing law, role-personality cooldowns, appraisal mood/anxiety cooldowns, effective recovery timing, adaptive pressure-based pump tempo/concurrency, idle rumination feeding candidate self-memory pressure, sleep/dream passes serving as the distillation window, and heartbeat state persisted through typed CultCache MessagePack stores - Void-derived native routine physiology through `epiphany-heartbeat-store routine`, with sleep cycle, memory resonance, incubation, analytic/associative cognition lanes, bridge judgment, candidate interventions, Ghostlight-style personality appraisals, mood/anxiety timing, derived reactions, and dream maintenance stored in the typed heartbeat store - Epiphany-native character-loop packet projection through `epiphany-character-loop`, with Face as the first public-surface actor over its typed role dossier -- Face as the public #aquarium-only surface for translating agent thought-weather into short chats or candidate drafts, without moderator authority +- Face as the public #aquarium-only surface for translating agent thought-weather into short chats or candidate drafts, with persona webhook presentation and Void memory/search access, without moderator authority - Ghostlight-shaped role dossiers in `state/agents.msgpack`, plus `selfPatch` review projection through `roleResult`/`roleAccept` and accepted memory application through the native `epiphany-agent-memory-store` binary - first Unity runtime bridge through native `epiphany-unity-bridge`, native `epiphany-unity-bridge-smoke`, GUI Inspect Unity, runtime artifact listing, and implementation prompt guardrails - first Rider source-context bridge through native `epiphany-rider-bridge`, native `epiphany-rider-bridge-smoke`, GUI Inspect Rider, Rider artifact listing, implementation prompt guardrails, and a source scaffold under `integrations/rider` @@ -288,6 +289,14 @@ For the native Void-derived routine pass, run: cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-heartbeat-store -- routine --store .\state\agent-heartbeats.msgpack --artifact-dir .\.epiphany-heartbeats --agent-store .\state\agents.msgpack ``` +For Face's Discord mouth and Void memory bridge, run: + +```powershell +cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-face-discord -- smoke +cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-void-memory -- smoke +cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-void-memory -- status +``` + For GUI Objective Draft adoption behavior, run: ```powershell diff --git a/state/agents/README.md b/state/agents/README.md index 01aa24b2..b9bde65a 100644 --- a/state/agents/README.md +++ b/state/agents/README.md @@ -34,6 +34,19 @@ interact only through #aquarium. If the channel id is not configured, Face must write candidate chat artifacts through the native `epiphany-face-discord draft` instead of posting. The public mouth does not invent new pulpits. +When a Face has a configured `persona_name` and optional `persona_avatar_url`, +`epiphany-face-discord post` uses the shared guild-channel webhook pipe so each +Epiphany instance can speak with its own nickname and avatar without needing a +separate Discord bot identity. The same boundary still applies: wrong channel +means draft, not improvisation. + +Void memory access lives behind `state/void-memory.toml` and the native +`epiphany-void-memory` bridge. It checks Void's Docker Postgres state spine, +queries Qdrant history/source collections with the configured Ollama embedding +model, and fetches raw Discord archive context for exact message windows. Face +may use those surfaces to ground speech; raw archive rows are evidence, not the +speech itself. + Use: ```powershell @@ -43,5 +56,8 @@ cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-agent-memory cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-heartbeat-store -- tick --store .\state\agent-heartbeats.msgpack --artifact-dir .\.epiphany-heartbeats --coordinator-action continueImplementation --urgency 0.95 --agent-store .\state\agents.msgpack --apply-rumination cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-heartbeat-store -- smoke --agent-store .\state\agents.msgpack cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-face-discord -- draft --content 'Face notices the organs are arguing about evidence again.' +cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-face-discord -- post --content 'Face has entered the aquarium.' --persona-name 'Epiphany Face' cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-face-discord -- smoke +cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-void-memory -- status +cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-void-memory -- search-history --query 'Epiphany Aquarium Face Discord' --limit 3 ``` diff --git a/state/face-discord.toml b/state/face-discord.toml index e7fe392e..2ac503ee 100644 --- a/state/face-discord.toml +++ b/state/face-discord.toml @@ -2,10 +2,14 @@ schema_version = "epiphany.face_discord.v0" allowed_channel_name = "#aquarium" allowed_channel_id_env = "EPIPHANY_FACE_AQUARIUM_CHANNEL_ID" bot_token_env = "DISCORD_BOT_TOKEN" +webhook_cache_path = ".epiphany-face/discord-webhook-cache.json" +persona_name = "Epiphany Face" +# persona_avatar_url may be set per Face/backend when a specific swarm avatar exists. policy = [ "Face may post only in #aquarium.", "If the #aquarium channel id is missing, Face writes candidate chat artifacts instead of posting.", + "When a Face has a persona name/avatar, it speaks through the shared Discord webhook pipe so each Epiphany can present as itself without separate bot identities.", "Face must not DM, moderate, escalate, or substitute another channel.", "Face translates agent thought-weather; it does not leak raw transcripts, private notes, or sealed artifacts.", ] diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index bafa0f1c529449ef782ab0400075ec01081fd933..fef79cc580ab1ac2a0ac395773d6a1bf783a125a 100644 GIT binary patch delta 285 zcmZvXKT5<<5Qm9-0z1nQ3lTPM%;E}LtF;SaVK=^vd5>jh!o0VMskE@L6a)|81!U1i z5xjzxXz3k1fG-GEmhV**+ICsFXZ$z~F?T z!eIM=9Fwt86Hw(Ui`=GlOs6xNiMC)YndvVO4#bBtBKj~X6deb!&WE@)@G{q^Qj>{g poOe{k=Fbh)*zSZ84s;gaR1`Y-!Co6}OO-hnj?2x9$A6wZ{sDj7XI20J delta 45 zcmeyek@?|z<_U^S*H>;-p2o=7zIhj;;5D&^Ek*`LX1WHZx&~$;Mg~@ diff --git a/state/map.yaml b/state/map.yaml index 00885236..fd8c232e 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -145,7 +145,8 @@ accepted_design: - VoidBot's current routine is reference lineage only. Epiphany's native routine pass lives in Rust as `epiphany-heartbeat-store routine`: it reads typed role dossiers, projects memory resonance, maintains incubation themes, runs analytic and associative cognition lanes, writes bridge syntheses/saturation/tension, produces reviewed candidate interventions, advances the sleep/dream cycle, and writes an auditable routine receipt while leaving project truth and role memory mutation on their dedicated reviewed surfaces. Qdrant-backed memory vectors remain a future enhancement; the current native pass uses bounded local resonance over typed memories. - `epiphany-character-loop` now advertises `epiphany.cognition_lanes.v0` and `epiphany.cognition_bridge.v0` in every character-turn packet. Face and future role-local actors must run an analytic lane and an associative lane, then let the bridge choose bubble, draft, finding, silence, or bounded `selfPatch`; those lanes shape attention but do not mutate project truth. - The Rust CultCache-compatible contract now lives in dedicated upstream `https://github.com/GameCult/cultcache-rs` and is vendored as `vendor/cultcache-rs`. Epiphany should consume it as the canonical typed MessagePack persistence seam instead of growing an embedded local copy like an unsanctioned organ. - - `state/face-discord.toml` and the native `epiphany-face-discord` binary are the first Face Discord boundary. Face may interact only through #aquarium; missing or mismatched channel configuration produces candidate chat artifacts instead of posting elsewhere. + - `state/face-discord.toml` and the native `epiphany-face-discord` binary are the Face Discord boundary. Face may interact only through #aquarium; missing or mismatched channel configuration produces candidate chat artifacts instead of posting elsewhere. When a Face has a configured persona name/avatar, posting uses the shared Discord webhook pipe so each Epiphany can speak with its own nickname and avatar without needing a separate bot identity. + - `state/void-memory.toml` and the native `epiphany-void-memory` binary are the first Void memory bridge: Epiphany can check Void's Docker Postgres state spine, query Qdrant Discord-history and source/lore vector collections through the configured Ollama embedding model, and fetch raw archive context windows from Void's Discord archive. Raw archive rows remain evidence for Face and Eyes, not public speech. - The native `epiphany-heartbeat-store status`, the `heartbeat` block in native `epiphany-mvp-status`, and GUI actions `heartbeatStatus` / `runHeartbeat` are the first operator API surface for heartbeat initiative state and outputs. `runHeartbeat` advances one slot and emits a Discord-independent Face bubble artifact; native `epiphany-heartbeat-store pump` adaptively launches concurrent deferred turns when swarm pressure justifies it. Status reflects the backing CultCache store and latest adaptive pacing receipt so Aquarium can see whether the typed heartbeat memory is present and whether the swarm is sleeping, stirring, or alarmed. - The native `epiphany-face-discord bubble`, the `face` block in native `epiphany-mvp-status`, and GUI action `faceBubble` are the first Aquarium bubble surface. Face can open a local chat bubble artifact even when Discord channel id/token configuration is absent. - `thread/epiphany/roleResult` and `thread/epiphany/roleAccept` now project optional specialist `selfPatch` requests with coordinator review through `selfPersistence`: good mutations are role-matched, bounded, evidence-grounded lane memory/goal/value/private-note updates; project truth, authority, code edits, graphs, checkpoints, planning, scratch, jobs, and raw transcripts are refused with reasons. GUI/coordinator acceptance paths apply accepted `selfPatch` requests through the native `epiphany-agent-memory-store` binary. @@ -199,7 +200,7 @@ landed_baseline: - Phase 6 Imagination role lane: `thread/epiphany/roles` now exposes Imagination/planning, `roleLaunch` can launch the fixed `planning-synthesis-worker`, `roleResult` projects its finding, `roleAccept` applies planning-only patches with review-gated Objective Drafts, and the GUI/status tools can launch, read, and accept that lane. - Phase 6 Aquarium graph and Rider bridge slice: the Tauri/React/WebGL Aquarium embeds the adjacent EpiphanyGraph viewer over typed graph state, native `epiphany-rider-bridge` writes Rider/source-context artifacts, Aquarium Inspect Rider surfaces those artifacts, and `integrations/rider` scaffolds the first frontend-only Rider tool-window/context-action plugin. - Phase 6 role self-memory slice: Ghostlight-shaped role dossiers live in typed CultCache `state/agents.msgpack`, specialists may request bounded `selfPatch` lane-memory mutations, coordinator review projects acceptance/refusal reasons through `selfPersistence`, and GUI/coordinator accept paths apply accepted requests with the native `epiphany-agent-memory-store` binary. - - Phase 6 Face public-surface slice: Face's typed role dossier, Face prompt text, `state/face-discord.toml`, and the native `epiphany-face-discord` binary establish Face as the public #aquarium-only translator of Epiphany agent thought-weather, without VoidBot's moderation authority. + - Phase 6 Face public-surface slice: Face's typed role dossier, Face prompt text, `state/face-discord.toml`, the native `epiphany-face-discord` persona/webhook pipe, `state/void-memory.toml`, and the native `epiphany-void-memory` bridge establish Face as the public #aquarium-only translator of Epiphany agent thought-weather, with Void-derived Discord memory/search/presentation organs but without VoidBot's moderation authority. - Phase 6 character-loop slice: native `epiphany-character-loop` loads any role's Ghostlight-shaped typed dossier from `state/agents.msgpack`, combines it with a visible stimulus, and emits an auditable `epiphany.character_turn_packet.v0` local projection for response, bubble, finding, silence, or bounded `selfPatch`. Face is the first intended public-surface consumer; Ghostlight is reference material, not a runtime dependency. - Phase 6 heartbeat initiative slice: `state/agent-heartbeats.msgpack`, `epiphany-core::EpiphanyHeartbeatStateEntry`, the native `epiphany-heartbeat-store` binary, and heartbeat smoke coverage borrow Ghostlight initiative scheduling so Self, Face, Imagination, Eyes, Body, Hands, Soul, and Life compete for heartbeat slots; idle slots become bounded rumination instead of fake project work, and sleep/dream cycle passes are the intended distillation window for durable self-memory and doctrine. The live state surface now ticks/completes/pumps/applies heartbeat physiology through typed CultCache MessagePack instead of JSON or Python wrapper state. Role personality and current mood/anxiety both shape initiative recovery through personality, mood, and effective cooldown multipliers, so Hands-like work pressure and anxious high-need lanes can recover sooner without waking lanes whose previous turn is still running. Adaptive pump pressure controls tempo and concurrency: calm can launch zero and sleep slow; alarm can fill most active lanes. The same store can now initialize a `ghostlight-scene` profile for character scene turns. - Phase 6 cognition-lanes/Void routine slice: native `epiphany-heartbeat-store routine` rebuilds VoidBot-style sleep, resonance, incubation, parallel analytic/associative thought lanes, bridge judgment, candidate interventions, Ghostlight-style participant-local thought appraisal, derived reactions, dream maintenance, and mood/anxiety timing inside Epiphany's heartbeat store. It reads typed role dossiers from `state/agents.msgpack`, projects clustered thought state through each role's personality vectors, updates `state/agent-heartbeats.msgpack`, and emits an auditable `epiphany.void_routine.v0` receipt without importing VoidBot or granting speech/project authority. `epiphany-character-loop` also carries the same cognition lane/bridge/appraisal contract for role-local actor turns; reactions may pace, color, draft, or display behavior, but state mutation remains on reviewed `selfPatch` or project-state surfaces. @@ -227,6 +228,7 @@ landed_baseline: - Use `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-heartbeat-store -- smoke --agent-store .\state\agents.msgpack` before modifying heartbeat initiative timing, idle rumination, or role slot selection. - Use `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-repo-personality-smoke` before modifying repo personality terrain scoring, role projection, or startup-personality artifact shape. - Use `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-face-discord -- smoke` before modifying Face's #aquarium posting/draft guardrails. + - Use `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-void-memory -- smoke` and `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-void-memory -- status` before modifying Void memory bridge behavior. - Use `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-unity-bridge-smoke` before modifying the Unity editor/runtime bridge. - Use `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-rider-bridge-smoke` before modifying the Rider source-context bridge. - Do not claim live specialist execution works end to end until a native heartbeat/runtime-spine runner proves it with artifacts. diff --git a/state/void-memory.toml b/state/void-memory.toml new file mode 100644 index 00000000..c05b5bda --- /dev/null +++ b/state/void-memory.toml @@ -0,0 +1,25 @@ +schema_version = "epiphany.void_memory_bridge.v0" + +database_dsn_env = "VOID_DATABASE_DSN" +database_dsn = "postgres://voidbot:voidbot@localhost:5432/voidbot" + +qdrant_url = "http://127.0.0.1:6333" +qdrant_api_key_env = "QDRANT_API_KEY" +qdrant_history_collection = "voidbot_discord_history_chunks" +qdrant_source_collection = "voidbot_repository_source_chunks" +qdrant_timeout_ms = 30000 + +ollama_base_url = "http://127.0.0.1:11434" +ollama_model = "qwen3-embedding:0.6b" +ollama_timeout_ms = 30000 +history_query_instruction = "Given a Discord history question, retrieve relevant messages and discussion snippets that answer it." +source_query_instruction = "Given a source-tree, codebase, or lore question, retrieve relevant files, code snippets, and lore passages that answer it." + +archive_path = "E:\\Projects\\VoidBot\\.voidbot\\rag\\messages.json" + +policy = [ + "Face may search archived Discord memory for context before speaking.", + "Qdrant is the semantic memory backend for Discord history and source/lore vectors.", + "Postgres is checked as the live Void state spine for jobs, audit, interaction memory, and rate limits.", + "Raw archive rows remain evidence, not public speech; Face summarizes with restraint.", +]