Serve one mind over CultNet, and no rule beside it
`huginn-daemon` becomes a library and a binary. `Daemon` holds one mind and
dispatches a `HuginnMindRequest` to the `Mind` method that answers it, with no
socket and no clock: `now` is the caller's. Every read that names an instance
is put to `Mind::require_instance` before the method runs, so ruling 14 is
checked once, by its owner, whichever side of the wire the request came from.
`IndexSink` is where Cut 11 attaches; its error is logged and the outcome is
what the mind decided.
`envelope` carries the vocabulary in CultNet's `cultnet.operation_request.v0`
and `cultnet.operation_response.v0` as base64 of named MessagePack, which is
what the C# reference and Eve's plugin ABI speak. The envelope's operation
string is checked against the decoded payload rather than trusted. A message
that does not decode is answered with a typed failure naming its code, and
reaches no mind.
`serve` binds one non-blocking socket on CultNet's operation connection id and
answers each frame on the session it arrived on. A refusal is an answer with a
`rejected` status, never a transport error. The two wire schemas go out on a
schema catalog request. A hostile datagram and a departed peer are logged and
served past. `startup` is the one place the mind opens and the socket binds,
in that order, so a mind that will not open leaves the port free.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 22:59:33 +02:00
|
|
|
//! The process: open one instance's mind, bind one socket, serve until a stop
|
|
|
|
|
//! signal. A mind that will not open ends the process with the refusal on
|
|
|
|
|
//! stderr and no socket ever bound.
|
|
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use std::sync::atomic::AtomicBool;
|
|
|
|
|
|
|
|
|
|
use anyhow::{Context, Result};
|
2026-09-29 08:05:26 +02:00
|
|
|
use huginn_daemon::index::Backoff;
|
2026-10-31 07:54:57 +01:00
|
|
|
use huginn_daemon::index::ollama::pool;
|
2026-09-29 08:05:26 +02:00
|
|
|
use huginn_daemon::index::qdrant::QdrantIndex;
|
2026-11-10 20:56:51 +00:00
|
|
|
use huginn_daemon::serve::{ServeOptions, Started, parse_options, run, startup};
|
Serve one mind over CultNet, and no rule beside it
`huginn-daemon` becomes a library and a binary. `Daemon` holds one mind and
dispatches a `HuginnMindRequest` to the `Mind` method that answers it, with no
socket and no clock: `now` is the caller's. Every read that names an instance
is put to `Mind::require_instance` before the method runs, so ruling 14 is
checked once, by its owner, whichever side of the wire the request came from.
`IndexSink` is where Cut 11 attaches; its error is logged and the outcome is
what the mind decided.
`envelope` carries the vocabulary in CultNet's `cultnet.operation_request.v0`
and `cultnet.operation_response.v0` as base64 of named MessagePack, which is
what the C# reference and Eve's plugin ABI speak. The envelope's operation
string is checked against the decoded payload rather than trusted. A message
that does not decode is answered with a typed failure naming its code, and
reaches no mind.
`serve` binds one non-blocking socket on CultNet's operation connection id and
answers each frame on the session it arrived on. A refusal is an answer with a
`rejected` status, never a transport error. The two wire schemas go out on a
schema catalog request. A hostile datagram and a departed peer are logged and
served past. `startup` is the one place the mind opens and the socket binds,
in that order, so a mind that will not open leaves the port free.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 22:59:33 +02:00
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
|
let options = parse_options(std::env::args().skip(1))?;
|
2026-10-31 07:54:57 +01:00
|
|
|
let embedder = pool(&options.ollama_urls, &options.reserve_ollama_urls, &options.embedding_model);
|
2026-09-29 08:05:26 +02:00
|
|
|
let index = QdrantIndex::new(&options.qdrant_url);
|
2026-11-10 20:56:51 +00:00
|
|
|
let Started { mut daemon, mut hub, registry, mut desk } = match startup(&options, embedder, index, Backoff::default()) {
|
Serve one mind over CultNet, and no rule beside it
`huginn-daemon` becomes a library and a binary. `Daemon` holds one mind and
dispatches a `HuginnMindRequest` to the `Mind` method that answers it, with no
socket and no clock: `now` is the caller's. Every read that names an instance
is put to `Mind::require_instance` before the method runs, so ruling 14 is
checked once, by its owner, whichever side of the wire the request came from.
`IndexSink` is where Cut 11 attaches; its error is logged and the outcome is
what the mind decided.
`envelope` carries the vocabulary in CultNet's `cultnet.operation_request.v0`
and `cultnet.operation_response.v0` as base64 of named MessagePack, which is
what the C# reference and Eve's plugin ABI speak. The envelope's operation
string is checked against the decoded payload rather than trusted. A message
that does not decode is answered with a typed failure naming its code, and
reaches no mind.
`serve` binds one non-blocking socket on CultNet's operation connection id and
answers each frame on the session it arrived on. A refusal is an answer with a
`rejected` status, never a transport error. The two wire schemas go out on a
schema catalog request. A hostile datagram and a departed peer are logged and
served past. `startup` is the one place the mind opens and the socket binds,
in that order, so a mind that will not open leaves the port free.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 22:59:33 +02:00
|
|
|
Ok(started) => started,
|
|
|
|
|
Err(error) => {
|
|
|
|
|
eprintln!("huginn-daemon refuses to serve {}: {error:#}", options.instance.0);
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Idunn runs this process as PID 1 of its own PID namespace, and a
|
|
|
|
|
// namespace init ignores every signal it has not caught. Without this,
|
|
|
|
|
// a stop is a ninety-second wait for SIGKILL.
|
|
|
|
|
let stopping = Arc::new(AtomicBool::new(false));
|
|
|
|
|
for signal in [signal_hook::consts::SIGTERM, signal_hook::consts::SIGINT] {
|
|
|
|
|
signal_hook::flag::register(signal, Arc::clone(&stopping))
|
|
|
|
|
.context("registering Huginn's stop signal handler")?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eprintln!("huginn-daemon serving {} on {}", options.instance.0, hub.local_addr()?);
|
2026-11-10 20:56:51 +00:00
|
|
|
if let Some(door) = &desk {
|
|
|
|
|
eprintln!("huginn-daemon serving the desk door on {}", door.path().display());
|
|
|
|
|
}
|
|
|
|
|
run(&mut daemon, &mut hub, ®istry, desk.as_mut(), &stopping, &ServeOptions::default())
|
Serve one mind over CultNet, and no rule beside it
`huginn-daemon` becomes a library and a binary. `Daemon` holds one mind and
dispatches a `HuginnMindRequest` to the `Mind` method that answers it, with no
socket and no clock: `now` is the caller's. Every read that names an instance
is put to `Mind::require_instance` before the method runs, so ruling 14 is
checked once, by its owner, whichever side of the wire the request came from.
`IndexSink` is where Cut 11 attaches; its error is logged and the outcome is
what the mind decided.
`envelope` carries the vocabulary in CultNet's `cultnet.operation_request.v0`
and `cultnet.operation_response.v0` as base64 of named MessagePack, which is
what the C# reference and Eve's plugin ABI speak. The envelope's operation
string is checked against the decoded payload rather than trusted. A message
that does not decode is answered with a typed failure naming its code, and
reaches no mind.
`serve` binds one non-blocking socket on CultNet's operation connection id and
answers each frame on the session it arrived on. A refusal is an answer with a
`rejected` status, never a transport error. The two wire schemas go out on a
schema catalog request. A hostile datagram and a departed peer are logged and
served past. `startup` is the one place the mind opens and the socket binds,
in that order, so a mind that will not open leaves the port free.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 22:59:33 +02:00
|
|
|
}
|