Add Yggdrasil runtime and signed health support
This commit is contained in:
parent
88d81a0ec8
commit
f12de09d00
19 changed files with 1322 additions and 28 deletions
|
|
@ -23,6 +23,7 @@ rmp-serde.workspace = true
|
|||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde_bytes = "0.11"
|
||||
sha2.workspace = true
|
||||
thiserror.workspace = true
|
||||
tokio.workspace = true
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
let campaign = action_campaign();
|
||||
let store = CampaignStore::open(root.join("campaign.cc"))?;
|
||||
store.create_campaign(&campaign, &[], &[])?;
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_machine_dpapi(secret)?);
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_runtime_secret(secret)?);
|
||||
let assessor = ActionAssessor::new(model.clone(), "deepseek-v4-pro");
|
||||
let kernel = WorldKernel::start(store.clone());
|
||||
let started = Instant::now();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
let secret = std::env::var_os("GHOSTLIGHT_DEEPSEEK_BLOB")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from(r"F:\GameCult\GhostlightDungeon\secrets\deepseek.dpapi"));
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_machine_dpapi(secret)?);
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_runtime_secret(secret)?);
|
||||
let compiler = WorldCompiler::new(
|
||||
Arc::new(VoidBotMcpVault::starfire_loopback()),
|
||||
model,
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
let kernel = WorldKernel::start(store.clone());
|
||||
let model_calls = Arc::new(std::sync::Mutex::new(Vec::new()));
|
||||
let model: Arc<dyn ModelPort> = Arc::new(LiveFireModelRecorder {
|
||||
inner: DeepSeekPort::from_machine_dpapi(secret)?,
|
||||
inner: DeepSeekPort::from_runtime_secret(secret)?,
|
||||
calls: model_calls.clone(),
|
||||
});
|
||||
let started = Instant::now();
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
.clone();
|
||||
let store = CampaignStore::open(root.join("campaign.cc"))?;
|
||||
store.create_campaign(&campaign, &[], &[])?;
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_machine_dpapi(secret)?);
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_runtime_secret(secret)?);
|
||||
let started = Instant::now();
|
||||
let output = propose_resolution_wave(
|
||||
model,
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
let campaign = four_actor_campaign();
|
||||
let store = CampaignStore::open(root.join("campaign.cc"))?;
|
||||
store.create_campaign(&campaign, &[], &[])?;
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_machine_dpapi(secret)?);
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_runtime_secret(secret)?);
|
||||
let engine = PersonaProjectionEngine {
|
||||
model,
|
||||
permit: Arc::new(SnapshotPermit::new(store.clone(), campaign.id, 0)),
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
.load::<Campaign>("campaign.v1", &campaign_id)?
|
||||
.map(|(_, value)| value)
|
||||
.ok_or_else(|| anyhow::anyhow!("campaign disappeared"))?;
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_machine_dpapi(secret)?);
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_runtime_secret(secret)?);
|
||||
let narrator = Narrator {
|
||||
model,
|
||||
model_name: "deepseek-v4-pro".into(),
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from(r"F:\GameCult\GhostlightDungeon\secrets\deepseek.dpapi"));
|
||||
let model: Arc<dyn ModelPort> = Arc::new(ObservedModel {
|
||||
inner: DeepSeekPort::from_machine_dpapi(secret)?,
|
||||
inner: DeepSeekPort::from_runtime_secret(secret)?,
|
||||
calls: calls.clone(),
|
||||
});
|
||||
let started = Instant::now();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
use anyhow::{Result, bail};
|
||||
use cultnet_rs::{
|
||||
GameCultProviderHealthIdentity, enroll_service_identity_at, open_service_identity_at,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
let action = args.next().unwrap_or_default();
|
||||
let path = args.next().map(PathBuf::from);
|
||||
if args.next().is_some()
|
||||
|| path.is_none()
|
||||
|| !matches!(action.as_str(), "enroll" | "public-key-hex")
|
||||
{
|
||||
bail!("Usage: ghostlight-provider-health-identity enroll|public-key-hex <private-store>");
|
||||
}
|
||||
let path = path.expect("validated above");
|
||||
let signer = if action == "enroll" {
|
||||
enroll_service_identity_at::<GameCultProviderHealthIdentity>(&path)?
|
||||
} else {
|
||||
open_service_identity_at::<GameCultProviderHealthIdentity>(&path)?
|
||||
};
|
||||
println!("{}", hex(&signer.entry().public_key));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn hex(bytes: &[u8]) -> String {
|
||||
const DIGITS: &[u8; 16] = b"0123456789abcdef";
|
||||
let mut output = String::with_capacity(bytes.len() * 2);
|
||||
for byte in bytes {
|
||||
output.push(DIGITS[(byte >> 4) as usize] as char);
|
||||
output.push(DIGITS[(byte & 0x0f) as usize] as char);
|
||||
}
|
||||
output
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
.clone();
|
||||
let store = CampaignStore::open(root.join("campaign.cc"))?;
|
||||
store.create_campaign(&campaign, &[], &[])?;
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_machine_dpapi(secret)?);
|
||||
let model: Arc<dyn ModelPort> = Arc::new(DeepSeekPort::from_runtime_secret(secret)?);
|
||||
let started = Instant::now();
|
||||
let output = propose_resolution_wave(
|
||||
model,
|
||||
|
|
|
|||
300
crates/ghostlight-dungeon/src/idunn_health.rs
Normal file
300
crates/ghostlight-dungeon/src/idunn_health.rs
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use cultnet_rs::{
|
||||
CultNetMessage, CultNetRawDocumentRecord, CultNetRawPayloadEncoding,
|
||||
CultNetRudpSocketTransportConnection, CultNetRudpSocketTransportOptions, CultNetWireContract,
|
||||
GameCultProviderHealthIdentity, IdunnSignedDaemonHealthPurpose, ServiceIdentitySigner,
|
||||
encode_cultnet_message_to_vec, open_service_identity_at,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
net::{SocketAddr, UdpSocket},
|
||||
path::Path,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
pub const GHOSTLIGHT_IDUNN_HEALTH_CONTRACT: &str = "ghostlight.cultnet-rudp-service-health";
|
||||
const CULTNET_RUDP_PROTOCOL_ID: &str = "cultnet.transport.rudp.v0";
|
||||
const IDUNN_HEALTH_RUDP_CONNECTION_ID: u32 = 0x1d0d_0001;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
struct IdunnSignedDaemonHealthRecord {
|
||||
schema_version: String,
|
||||
daemon_id: String,
|
||||
health_contract: String,
|
||||
source_runtime_id: String,
|
||||
state: String,
|
||||
detail: String,
|
||||
signer_identity_id: String,
|
||||
publisher_incarnation_id: String,
|
||||
publisher_sequence: u64,
|
||||
observed_at_unix_millis: u64,
|
||||
release_id: Option<String>,
|
||||
release_witness_sha256: Option<String>,
|
||||
source_commit: Option<String>,
|
||||
deployment_id: Option<String>,
|
||||
signature_algorithm: String,
|
||||
#[serde(with = "serde_bytes")]
|
||||
signature: Vec<u8>,
|
||||
private_state_exposed: bool,
|
||||
}
|
||||
|
||||
impl IdunnSignedDaemonHealthRecord {
|
||||
const SCHEMA: &'static str = "idunn.signed_daemon_health.v1";
|
||||
|
||||
fn validate(&self) -> Result<()> {
|
||||
for (value, label) in [
|
||||
(&self.daemon_id, "daemon id"),
|
||||
(&self.health_contract, "health contract"),
|
||||
(&self.source_runtime_id, "source runtime id"),
|
||||
(&self.signer_identity_id, "signer identity id"),
|
||||
(&self.publisher_incarnation_id, "publisher incarnation id"),
|
||||
] {
|
||||
require_id(value, label)?;
|
||||
}
|
||||
if self.schema_version != Self::SCHEMA
|
||||
|| !matches!(
|
||||
self.state.as_str(),
|
||||
"active" | "warming" | "degraded" | "failed"
|
||||
)
|
||||
|| self.detail.len() > 512
|
||||
|| self.detail.chars().any(char::is_control)
|
||||
|| self.publisher_sequence == 0
|
||||
|| self.observed_at_unix_millis == 0
|
||||
|| self.release_id.is_some()
|
||||
|| self.release_witness_sha256.is_some()
|
||||
|| self.source_commit.is_some()
|
||||
|| self.deployment_id.is_some()
|
||||
|| self.signature_algorithm != "ed25519"
|
||||
|| self.signature.len() != 64
|
||||
|| self.private_state_exposed
|
||||
{
|
||||
bail!("signed daemon health shape is invalid");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct IdunnHealthPublisher {
|
||||
endpoint: SocketAddr,
|
||||
daemon_id: String,
|
||||
source_runtime_id: String,
|
||||
health_contract: String,
|
||||
signer: ServiceIdentitySigner<GameCultProviderHealthIdentity>,
|
||||
publisher_incarnation_id: String,
|
||||
publisher_sequence: u64,
|
||||
}
|
||||
|
||||
impl IdunnHealthPublisher {
|
||||
pub fn open(
|
||||
endpoint: SocketAddr,
|
||||
daemon_id: impl Into<String>,
|
||||
source_runtime_id: impl Into<String>,
|
||||
health_contract: impl Into<String>,
|
||||
identity_store: impl AsRef<Path>,
|
||||
) -> Result<Self> {
|
||||
let daemon_id = daemon_id.into();
|
||||
let source_runtime_id = source_runtime_id.into();
|
||||
let health_contract = health_contract.into();
|
||||
require_id(&daemon_id, "Idunn daemon id")?;
|
||||
require_id(&source_runtime_id, "health source runtime id")?;
|
||||
require_id(&health_contract, "Idunn health contract")?;
|
||||
Ok(Self {
|
||||
endpoint,
|
||||
daemon_id,
|
||||
source_runtime_id,
|
||||
health_contract,
|
||||
signer: open_service_identity_at::<GameCultProviderHealthIdentity>(
|
||||
identity_store.as_ref(),
|
||||
)?,
|
||||
publisher_incarnation_id: uuid::Uuid::new_v4().to_string(),
|
||||
publisher_sequence: 0,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn publish(&mut self, state: &str, detail: &str) -> Result<()> {
|
||||
if !matches!(state, "active" | "warming" | "degraded" | "failed") {
|
||||
bail!("unsupported Idunn daemon health state");
|
||||
}
|
||||
if detail.len() > 512 || detail.chars().any(char::is_control) {
|
||||
bail!("Idunn daemon health detail is oversized or contains control characters");
|
||||
}
|
||||
self.publisher_sequence = self
|
||||
.publisher_sequence
|
||||
.checked_add(1)
|
||||
.ok_or_else(|| anyhow!("Idunn health publisher sequence overflow"))?;
|
||||
let mut record = IdunnSignedDaemonHealthRecord {
|
||||
schema_version: IdunnSignedDaemonHealthRecord::SCHEMA.into(),
|
||||
daemon_id: self.daemon_id.clone(),
|
||||
health_contract: self.health_contract.clone(),
|
||||
source_runtime_id: self.source_runtime_id.clone(),
|
||||
state: state.into(),
|
||||
detail: detail.into(),
|
||||
signer_identity_id: self.signer.entry().identity_id.clone(),
|
||||
publisher_incarnation_id: self.publisher_incarnation_id.clone(),
|
||||
publisher_sequence: self.publisher_sequence,
|
||||
observed_at_unix_millis: chrono::Utc::now().timestamp_millis().try_into()?,
|
||||
release_id: None,
|
||||
release_witness_sha256: None,
|
||||
source_commit: None,
|
||||
deployment_id: None,
|
||||
signature_algorithm: "ed25519".into(),
|
||||
signature: Vec::new(),
|
||||
private_state_exposed: false,
|
||||
};
|
||||
let unsigned = canonical_unsigned_record(&record)?;
|
||||
let proof = self
|
||||
.signer
|
||||
.sign::<IdunnSignedDaemonHealthPurpose>(&unsigned);
|
||||
if proof.identity_id != record.signer_identity_id {
|
||||
bail!("provider-health signer identity disagrees with record");
|
||||
}
|
||||
record.signature = proof.signature;
|
||||
record.validate()?;
|
||||
publish_signed_health(self.endpoint, &self.source_runtime_id, &record)
|
||||
}
|
||||
|
||||
pub fn public_key(&self) -> &[u8] {
|
||||
&self.signer.entry().public_key
|
||||
}
|
||||
}
|
||||
|
||||
fn publish_signed_health(
|
||||
endpoint: SocketAddr,
|
||||
source_runtime_id: &str,
|
||||
signed: &IdunnSignedDaemonHealthRecord,
|
||||
) -> Result<()> {
|
||||
signed.validate()?;
|
||||
let payload = rmp_serde::to_vec(signed).context("encoding canonical signed Idunn health")?;
|
||||
let decoded: IdunnSignedDaemonHealthRecord = rmp_serde::from_slice(&payload)?;
|
||||
if decoded != *signed || rmp_serde::to_vec(&decoded)? != payload {
|
||||
bail!("signed Idunn health encoding is noncanonical");
|
||||
}
|
||||
let message = CultNetMessage::DocumentPutRaw {
|
||||
message_id: format!(
|
||||
"ghostlight-signed-health:{}:{}:{}",
|
||||
signed.daemon_id, signed.publisher_incarnation_id, signed.publisher_sequence
|
||||
),
|
||||
document: CultNetRawDocumentRecord {
|
||||
schema_id: IdunnSignedDaemonHealthRecord::SCHEMA.into(),
|
||||
record_key: signed.daemon_id.clone(),
|
||||
stored_at: chrono::DateTime::from_timestamp_millis(
|
||||
signed.observed_at_unix_millis.try_into()?,
|
||||
)
|
||||
.context("signed health observation time is invalid")?
|
||||
.to_rfc3339(),
|
||||
payload_encoding: CultNetRawPayloadEncoding::Messagepack,
|
||||
payload,
|
||||
source_runtime_id: Some(source_runtime_id.into()),
|
||||
source_agent_id: Some(signed.signer_identity_id.clone()),
|
||||
source_role: Some("daemon-health-publisher".into()),
|
||||
tags: Some(vec![CULTNET_RUDP_PROTOCOL_ID.into()]),
|
||||
},
|
||||
};
|
||||
let bind = if endpoint.is_ipv4() {
|
||||
"0.0.0.0:0"
|
||||
} else {
|
||||
"[::]:0"
|
||||
};
|
||||
let socket = UdpSocket::bind(bind)
|
||||
.with_context(|| format!("binding Ghostlight Idunn RUDP sender at {bind}"))?;
|
||||
socket.set_read_timeout(Some(Duration::from_millis(100)))?;
|
||||
let mut transport =
|
||||
CultNetRudpSocketTransportConnection::new(CultNetRudpSocketTransportOptions::client(
|
||||
source_runtime_id,
|
||||
socket,
|
||||
endpoint,
|
||||
IDUNN_HEALTH_RUDP_CONNECTION_ID,
|
||||
))?;
|
||||
transport.connect(Vec::new())?;
|
||||
let deadline = Instant::now() + Duration::from_millis(500);
|
||||
while !transport.connected() {
|
||||
let _ = transport.receive_once()?;
|
||||
transport.poll_resends()?;
|
||||
if Instant::now() >= deadline {
|
||||
return Err(anyhow!(
|
||||
"timed out connecting Ghostlight health publisher to {endpoint}"
|
||||
));
|
||||
}
|
||||
}
|
||||
transport.send(
|
||||
"schema",
|
||||
encode_cultnet_message_to_vec(&message, CultNetWireContract::CultNetSchemaV0)?,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn canonical_unsigned_record(record: &IdunnSignedDaemonHealthRecord) -> Result<Vec<u8>> {
|
||||
let mut unsigned = record.clone();
|
||||
unsigned.signature.clear();
|
||||
let mut signed_shape = unsigned.clone();
|
||||
signed_shape.signature = vec![0; 64];
|
||||
signed_shape.validate()?;
|
||||
uuid::Uuid::parse_str(&unsigned.publisher_incarnation_id)
|
||||
.context("publisher incarnation id must be UUID")?;
|
||||
rmp_serde::to_vec(&unsigned).context("encoding canonical unsigned Idunn health")
|
||||
}
|
||||
|
||||
fn require_id(value: &str, label: &str) -> Result<()> {
|
||||
if value.trim().is_empty() || value.len() > 256 || value.chars().any(char::is_control) {
|
||||
bail!("{label} is empty, oversized, or contains control characters");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use cultnet_rs::{
|
||||
GameCultProviderHealthIdentity, IdunnSignedDaemonHealthPurpose, enroll_service_identity_at,
|
||||
verify_service_identity_signature,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn ghostlight_health_is_canonical_private_free_and_release_unbound() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let path = root.path().join("provider.cc");
|
||||
let signer = enroll_service_identity_at::<GameCultProviderHealthIdentity>(&path).unwrap();
|
||||
let mut publisher = IdunnHealthPublisher::open(
|
||||
"127.0.0.1:17870".parse().unwrap(),
|
||||
"yggdrasil-ghostlight",
|
||||
"ghostlight-dungeon-yggdrasil",
|
||||
GHOSTLIGHT_IDUNN_HEALTH_CONTRACT,
|
||||
&path,
|
||||
)
|
||||
.unwrap();
|
||||
publisher.publisher_sequence = 7;
|
||||
let mut record = IdunnSignedDaemonHealthRecord {
|
||||
schema_version: IdunnSignedDaemonHealthRecord::SCHEMA.into(),
|
||||
daemon_id: publisher.daemon_id.clone(),
|
||||
health_contract: publisher.health_contract.clone(),
|
||||
source_runtime_id: publisher.source_runtime_id.clone(),
|
||||
state: "active".into(),
|
||||
detail: "world-kernel-serving".into(),
|
||||
signer_identity_id: publisher.signer.entry().identity_id.clone(),
|
||||
publisher_incarnation_id: publisher.publisher_incarnation_id.clone(),
|
||||
publisher_sequence: publisher.publisher_sequence,
|
||||
observed_at_unix_millis: 1_787_315_696_789,
|
||||
release_id: None,
|
||||
release_witness_sha256: None,
|
||||
source_commit: None,
|
||||
deployment_id: None,
|
||||
signature_algorithm: "ed25519".into(),
|
||||
signature: Vec::new(),
|
||||
private_state_exposed: false,
|
||||
};
|
||||
let unsigned = canonical_unsigned_record(&record).unwrap();
|
||||
let proof = publisher
|
||||
.signer
|
||||
.sign::<IdunnSignedDaemonHealthPurpose>(&unsigned);
|
||||
record.signature = proof.signature.clone();
|
||||
record.validate().unwrap();
|
||||
verify_service_identity_signature::<
|
||||
GameCultProviderHealthIdentity,
|
||||
IdunnSignedDaemonHealthPurpose,
|
||||
>(&signer.trust_anchor().unwrap(), &unsigned, &proof)
|
||||
.unwrap();
|
||||
assert!(record.release_id.is_none());
|
||||
assert!(!record.private_state_exposed);
|
||||
assert_eq!(rmp_serde::to_vec(&record).unwrap()[..3], [0xdc, 0, 17]);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ pub mod compiler;
|
|||
pub mod d20;
|
||||
pub mod domain;
|
||||
pub mod gestalt;
|
||||
pub mod idunn_health;
|
||||
pub mod initiative;
|
||||
pub mod kernel;
|
||||
pub mod mesh;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ use ghostlight_dungeon::{
|
|||
RejectedProposalReceipt, WorldCommand,
|
||||
},
|
||||
gestalt::GestaltPresencePlanner,
|
||||
idunn_health::{GHOSTLIGHT_IDUNN_HEALTH_CONTRACT, IdunnHealthPublisher},
|
||||
kernel::{CommandResult, KernelError},
|
||||
mesh::{CampaignMeshSnapshot, MeshPublisher, SessionZeroMeshSnapshot},
|
||||
mesh::{CampaignMeshSnapshot, MeshPublisher, MeshRuntimeIdentity, SessionZeroMeshSnapshot},
|
||||
model::{DeepSeekPort, ModelPort, ModelStageRequest, run_validated_stage},
|
||||
narrator::Narrator,
|
||||
persistence::CampaignStore,
|
||||
|
|
@ -253,7 +254,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
.init();
|
||||
let runtime_root = std::env::var_os("GHOSTLIGHT_DUNGEON_ROOT")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from(r"F:\GameCult\GhostlightDungeon"));
|
||||
.unwrap_or_else(default_runtime_root);
|
||||
migrate_default_campaign(&runtime_root)?;
|
||||
let registry = CampaignRegistry::new(runtime_root.join("campaigns"))?;
|
||||
registry.load_existing().await?;
|
||||
|
|
@ -282,10 +283,12 @@ async fn main() -> anyhow::Result<()> {
|
|||
}
|
||||
};
|
||||
migrate_legacy_campaign_memberships(®istry, &auth_state).await?;
|
||||
let secret_path = runtime_root.join("secrets/deepseek.dpapi");
|
||||
let secret_path = std::env::var_os("GHOSTLIGHT_DEEPSEEK_CREDENTIAL")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| runtime_root.join("secrets/deepseek.dpapi"));
|
||||
let (deepseek_status, compiler, assessor, shared_model) = if secret_path.is_file() {
|
||||
let provider: Arc<dyn ModelPort> =
|
||||
Arc::new(DeepSeekPort::from_machine_dpapi(&secret_path)?);
|
||||
Arc::new(DeepSeekPort::from_runtime_secret(&secret_path)?);
|
||||
let probe = run_validated_stage(
|
||||
provider.as_ref(),
|
||||
&ModelStageRequest {
|
||||
|
|
@ -299,11 +302,20 @@ async fn main() -> anyhow::Result<()> {
|
|||
max_output_tokens: Some(16),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
.await;
|
||||
let deepseek_status = match probe {
|
||||
Ok(probe) => format!("ready:{}", probe.receipt.output_hash),
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "DeepSeek startup probe failed; runtime remains available");
|
||||
"degraded:startup-probe-failed".into()
|
||||
}
|
||||
};
|
||||
let vault_endpoint = std::env::var("GHOSTLIGHT_VAULT_MCP_URL")
|
||||
.unwrap_or_else(|_| "http://127.0.0.1:17875/mcp".into());
|
||||
(
|
||||
format!("ready:{}", probe.receipt.output_hash),
|
||||
deepseek_status,
|
||||
Some(Arc::new(WorldCompiler::new(
|
||||
Arc::new(VoidBotMcpVault::starfire_loopback()),
|
||||
Arc::new(VoidBotMcpVault::new(vault_endpoint)),
|
||||
provider.clone(),
|
||||
"deepseek-v4-flash",
|
||||
"deepseek-v4-pro",
|
||||
|
|
@ -321,7 +333,39 @@ async fn main() -> anyhow::Result<()> {
|
|||
.ok()
|
||||
.map(|value| value.parse())
|
||||
.transpose()?;
|
||||
let mesh = MeshPublisher::open(runtime_root.join("service/mesh.cc"), mesh_target)?;
|
||||
let mesh_identity = MeshRuntimeIdentity {
|
||||
runtime_id: std::env::var("GHOSTLIGHT_RUNTIME_ID")
|
||||
.unwrap_or_else(|_| "ghostlight-dungeon-starfire".into()),
|
||||
service_id: std::env::var("GHOSTLIGHT_SERVICE_ID")
|
||||
.unwrap_or_else(|_| "ghostlight-dungeon-starfire".into()),
|
||||
located_service: std::env::var("GHOSTLIGHT_LOCATED_SERVICE")
|
||||
.unwrap_or_else(|_| "starfire".into()),
|
||||
};
|
||||
let mesh = MeshPublisher::open_with_identity(
|
||||
runtime_root.join("service/mesh.cc"),
|
||||
mesh_target,
|
||||
mesh_identity.clone(),
|
||||
)?;
|
||||
let idunn_health =
|
||||
std::env::var("GHOSTLIGHT_IDUNN_RUDP")
|
||||
.ok()
|
||||
.map(|endpoint| -> anyhow::Result<IdunnHealthPublisher> {
|
||||
let identity_store = std::env::var_os("GHOSTLIGHT_IDUNN_HEALTH_IDENTITY")
|
||||
.map(PathBuf::from)
|
||||
.ok_or_else(|| anyhow::anyhow!(
|
||||
"GHOSTLIGHT_IDUNN_HEALTH_IDENTITY is required with GHOSTLIGHT_IDUNN_RUDP"
|
||||
))?;
|
||||
Ok(IdunnHealthPublisher::open(
|
||||
endpoint.parse()?,
|
||||
std::env::var("GHOSTLIGHT_IDUNN_DAEMON")
|
||||
.unwrap_or_else(|_| "yggdrasil-ghostlight".into()),
|
||||
mesh_identity.runtime_id.clone(),
|
||||
std::env::var("GHOSTLIGHT_IDUNN_HEALTH_CONTRACT")
|
||||
.unwrap_or_else(|_| GHOSTLIGHT_IDUNN_HEALTH_CONTRACT.into()),
|
||||
identity_store,
|
||||
)?)
|
||||
})
|
||||
.transpose()?;
|
||||
let session_zero_director = shared_model.as_ref().map(|model| {
|
||||
Arc::new(SessionZeroDirector::new(
|
||||
model.clone(),
|
||||
|
|
@ -367,6 +411,16 @@ async fn main() -> anyhow::Result<()> {
|
|||
.parse()?;
|
||||
let listener = tokio::net::TcpListener::bind(address).await?;
|
||||
tracing::info!(%address, "GhostlightDungeon listening");
|
||||
if let Some(mut publisher) = idunn_health {
|
||||
tokio::task::spawn_blocking(move || {
|
||||
loop {
|
||||
if let Err(error) = publisher.publish("active", "world-kernel-serving") {
|
||||
tracing::warn!(%error, "signed Idunn health publication failed");
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_secs(10));
|
||||
}
|
||||
});
|
||||
}
|
||||
axum::serve(
|
||||
listener,
|
||||
app.into_make_service_with_connect_info::<SocketAddr>(),
|
||||
|
|
@ -375,6 +429,17 @@ async fn main() -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn default_runtime_root() -> PathBuf {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
PathBuf::from(r"F:\GameCult\GhostlightDungeon")
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
PathBuf::from("/var/lib/gamecult/ghostlight-dungeon")
|
||||
}
|
||||
}
|
||||
|
||||
fn app_router(state: AppState, web_root: PathBuf) -> Router {
|
||||
let protected_api = Router::new()
|
||||
.route("/api/surface", get(surface))
|
||||
|
|
|
|||
|
|
@ -40,6 +40,23 @@ pub const PROVIDER_ID: &str = "gamecult.ghostlight.dungeon";
|
|||
pub const HEALTH_KEY: &str = "ghostlight:dungeon:health";
|
||||
pub const ADVERTISEMENT_KEY: &str = "eve:provider:gamecult.ghostlight.dungeon";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct MeshRuntimeIdentity {
|
||||
pub runtime_id: String,
|
||||
pub service_id: String,
|
||||
pub located_service: String,
|
||||
}
|
||||
|
||||
impl Default for MeshRuntimeIdentity {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
runtime_id: "ghostlight-dungeon-starfire".into(),
|
||||
service_id: "ghostlight-dungeon-starfire".into(),
|
||||
located_service: "starfire".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CampaignMeshSnapshot {
|
||||
pub campaign: Campaign,
|
||||
|
|
@ -131,16 +148,26 @@ cultmesh_rs::cultmesh_documents!(GhostlightDocuments {
|
|||
pub struct MeshPublisher {
|
||||
node: Arc<Mutex<CultMeshNode>>,
|
||||
remote: Option<RemoteReplication>,
|
||||
identity: MeshRuntimeIdentity,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct RemoteReplication {
|
||||
target: SocketAddr,
|
||||
runtime_id: String,
|
||||
pending: Arc<(Mutex<Option<Vec<cultnet_rs::CultNetMessage>>>, Condvar)>,
|
||||
}
|
||||
|
||||
impl MeshPublisher {
|
||||
pub fn open(store_path: impl AsRef<Path>, rudp_target: Option<SocketAddr>) -> Result<Self> {
|
||||
Self::open_with_identity(store_path, rudp_target, MeshRuntimeIdentity::default())
|
||||
}
|
||||
|
||||
pub fn open_with_identity(
|
||||
store_path: impl AsRef<Path>,
|
||||
rudp_target: Option<SocketAddr>,
|
||||
identity: MeshRuntimeIdentity,
|
||||
) -> Result<Self> {
|
||||
if let Some(parent) = store_path.as_ref().parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
|
|
@ -148,14 +175,16 @@ impl MeshPublisher {
|
|||
store_path,
|
||||
GhostlightDocuments,
|
||||
CultMeshNodeOptions {
|
||||
runtime_id: "ghostlight-dungeon-starfire".into(),
|
||||
runtime_id: identity.runtime_id.clone(),
|
||||
pull_on_start: true,
|
||||
},
|
||||
)?;
|
||||
let remote = rudp_target.map(RemoteReplication::start);
|
||||
let remote =
|
||||
rudp_target.map(|target| RemoteReplication::start(target, identity.runtime_id.clone()));
|
||||
Ok(Self {
|
||||
node: Arc::new(Mutex::new(node)),
|
||||
remote,
|
||||
identity,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +204,7 @@ impl MeshPublisher {
|
|||
"deepseek":deepseek_status,
|
||||
"scheduler":{"live_turn_pressure":live_turn_pressure},
|
||||
"updatedAtUtc":updated_at,
|
||||
"runtime":"ghostlight-dungeon-starfire",
|
||||
"runtime":self.identity.runtime_id.as_str(),
|
||||
"commit":option_env!("GHOSTLIGHT_BUILD_COMMIT").unwrap_or("development")
|
||||
});
|
||||
let schema_ids = vec![
|
||||
|
|
@ -269,11 +298,11 @@ impl MeshPublisher {
|
|||
let advertisement = json!({
|
||||
"schema":"gamecult.eve.provider_advertisement.v1",
|
||||
"providerId":PROVIDER_ID,
|
||||
"serviceId":"ghostlight-dungeon-starfire",
|
||||
"serviceId":self.identity.service_id.as_str(),
|
||||
"verseId":"gamecult.private",
|
||||
"rootVerse":"gamecult",
|
||||
"canonicalService":"ghostlight-dungeon",
|
||||
"locatedService":"starfire",
|
||||
"locatedService":self.identity.located_service.as_str(),
|
||||
"cultMeshAddress":"cultmesh://gamecult.private/ghostlight/providers/dungeon",
|
||||
"title":"GhostlightDungeon",
|
||||
"kind":"narrative.simulation",
|
||||
|
|
@ -497,12 +526,13 @@ impl MeshPublisher {
|
|||
}
|
||||
|
||||
impl RemoteReplication {
|
||||
fn start(target: SocketAddr) -> Self {
|
||||
fn start(target: SocketAddr, runtime_id: String) -> Self {
|
||||
let pending = Arc::new((
|
||||
Mutex::new(None::<Vec<cultnet_rs::CultNetMessage>>),
|
||||
Condvar::new(),
|
||||
));
|
||||
let worker_pending = pending.clone();
|
||||
let worker_runtime_id = runtime_id.clone();
|
||||
thread::Builder::new()
|
||||
.name("ghostlight-odin-rudp".into())
|
||||
.spawn(move || loop {
|
||||
|
|
@ -519,7 +549,7 @@ impl RemoteReplication {
|
|||
if messages.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let options = remote_options(target);
|
||||
let options = remote_options(target, &worker_runtime_id);
|
||||
if let Err(error) = publish_cultnet_messages_to_rudp_catalog(&messages, options) {
|
||||
tracing::warn!(
|
||||
document_count = messages.len(),
|
||||
|
|
@ -530,11 +560,15 @@ impl RemoteReplication {
|
|||
}
|
||||
})
|
||||
.expect("Ghostlight RUDP replication worker must start");
|
||||
Self { target, pending }
|
||||
Self {
|
||||
target,
|
||||
runtime_id,
|
||||
pending,
|
||||
}
|
||||
}
|
||||
|
||||
fn options(&self) -> CultMeshRudpDocumentPublishOptions {
|
||||
remote_options(self.target)
|
||||
remote_options(self.target, &self.runtime_id)
|
||||
}
|
||||
|
||||
fn enqueue(&self, messages: Vec<cultnet_rs::CultNetMessage>) {
|
||||
|
|
@ -545,9 +579,8 @@ impl RemoteReplication {
|
|||
}
|
||||
}
|
||||
|
||||
fn remote_options(target: SocketAddr) -> CultMeshRudpDocumentPublishOptions {
|
||||
let mut options =
|
||||
CultMeshRudpDocumentPublishOptions::odin(target, "ghostlight-dungeon-starfire");
|
||||
fn remote_options(target: SocketAddr, runtime_id: &str) -> CultMeshRudpDocumentPublishOptions {
|
||||
let mut options = CultMeshRudpDocumentPublishOptions::odin(target, runtime_id);
|
||||
options.source_agent_id = Some(PROVIDER_ID.into());
|
||||
options.source_role = Some("narrative-simulation".into());
|
||||
options.tags = vec!["ghostlight".into(), "eve".into(), "private".into()];
|
||||
|
|
|
|||
|
|
@ -511,6 +511,27 @@ impl DeepSeekPort {
|
|||
)?))
|
||||
}
|
||||
|
||||
pub fn from_utf8_secret_file(path: impl AsRef<std::path::Path>) -> Result<Self> {
|
||||
let bytes = Zeroizing::new(std::fs::read(path.as_ref())?);
|
||||
let secret = std::str::from_utf8(bytes.as_slice())?.trim().to_owned();
|
||||
if secret.is_empty() {
|
||||
anyhow::bail!("DeepSeek credential file is empty");
|
||||
}
|
||||
Ok(Self::new(secret))
|
||||
}
|
||||
|
||||
pub fn from_runtime_secret(path: impl AsRef<std::path::Path>) -> Result<Self> {
|
||||
#[cfg(windows)]
|
||||
if path
|
||||
.as_ref()
|
||||
.extension()
|
||||
.is_some_and(|value| value == "dpapi")
|
||||
{
|
||||
return Self::from_machine_dpapi(path);
|
||||
}
|
||||
Self::from_utf8_secret_file(path)
|
||||
}
|
||||
|
||||
async fn run_with_observation(
|
||||
&self,
|
||||
request: &ModelStageRequest,
|
||||
|
|
|
|||
Loading…
Reference in a new issue