1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! The nervous system: the layer between sensors, small fast models, the
//! large slow model (the brain, an LLM) and actuators.
//!
//! 
//!
//! Not a server that loads models and answers requests, but what moves signals between
//! them: overwhelmingly light, so that the models are the only cost. Most signals must
//! never reach the brain. The mechanisms are a neuron's:
//!
//! - **Receptors** ([`receptor`]) extract a small [`Feature`] from the world and stamp an
//! [`Urgency`]; the raw input stays a lazily shared [`Payload`].
//! - **Habituation**, **thresholds** and **refractory periods** ([`Mechanisms`]) live in
//! every neuron's gate: a repeated feature attenuates before it propagates and recovers
//! with time; weak signals cost nothing; a neuron that just fired ignores the next burst.
//! - **Reflex pathways** are direct calls on the firing thread, with no queue and no
//! scheduler: microseconds from stimulus to effector.
//! - **Deliberative pathways** queue to a worker that sums a window of signals into one
//! firing of a brain ([`NeuronKind::Brain`]) (temporal summation).
//! - **Timing selects the pathway**: a pathway whose measured p99 does not fit in the
//! signal's remaining deadline is not eligible; among the eligible, the heaviest weight
//! wins. No classifier decides "is this urgent".
//! - **Effectors** ([`effector`]) act on the world (a webhook, a command, a file, a
//! response) with their own local loops: retry, circuit breaker, rate limit, refractory
//! period. The brain is never in a retry loop.
//! - **Motor neurons** ([`motor`]) stand between the brain and the effectors: the brain names
//! an action ("get dressed"), and a motor neuron's program breaks it down into commands for
//! the motor neurons and effectors below it, waits for what a receptor senses, asks a small
//! question, retries locally and reports back up. The brain is told the actions declared
//! with [`FabricBuilder::action`], not the joints, and reaches nothing else.
//! - **The skeleton**: [`FabricBuilder::spine`] is the brain's only way to the body (senses
//! up, actions down, outcomes and questions up), and [`FabricBuilder::nerve`] the trunk to
//! one part, which carries its own load, the urgent first, and closes the part's own loops.
//!
//! ```no_run
//! use std::time::Duration;
//! use furnace::nerve::prelude::*;
//! use serde_json::json;
//!
//! let mut b = Fabric::builder();
//! // POST /events: a 64-bit sketch of the body is the feature; repeats habituate here,
//! // attenuated below the threshold
//! let events = b.receptor(Http::new("events", "/events").text());
//! let habituation = Habituation::new(Duration::from_secs(30));
//! b.gate(events, Mechanisms::NONE.threshold(0.5).habituation(habituation));
//! // A reflex: in process, no blocking. Alerts become a command to `alert` at once; the rest
//! // go on to the brain
//! let triage = b.neuron(FnNeuron::reflex("triage", |signal, _| {
//! match signal.payload.as_text() {
//! Some(t) if t.contains("ALERT") => signal.command("alert", json!({"text": t})),
//! _ => signal,
//! }
//! }));
//! // The brain: slow, so it sits behind a deliberative pathway, a queue whose worker sums a
//! // window of signals into one firing (a closure here; `Llm` or `ModelNeuron` in practice)
//! let brain = b.neuron(
//! FnNeuron::reflex("brain", |signal, _| signal.command("alert", json!({"text": "look"})))
//! .with_kind(NeuronKind::Brain),
//! );
//! b.effector(Webhook::new("alert", "http://127.0.0.1:9000/hook")?);
//! b.reflex(events, triage);
//! b.deliberative(triage, brain);
//! let fabric = b.build()?;
//! # let _ = fabric;
//! # Ok::<(), furnace::nerve::BuildError>(())
//! ```
//!
//! See [docs/NERVE.md](https://github.com/Gilfeather/furnace/blob/main/docs/NERVE.md) for
//! the concepts, the demo and the measurements.
pub
pub
pub
/// The nervous system's own HTTP/1.1 client, for the nerve bench's raw baseline. Not part of
/// the API: it may change in any release.
/// What building a fabric usually takes, in one import: `use furnace::nerve::prelude::*;`
pub use Announced;
pub use ;
pub use ;
pub use LatencySnapshot;
pub use ;
pub use ;
pub use ;
pub use ;
/// Nanoseconds from `epoch` to `now`: 0 if `now` is earlier, `u64::MAX` past 584 years
pub