Skip to content

Commit 35900f8

Browse files
committed
feat: wire 10-layer cognitive stack with resonance-gated processing
Replace the 7-layer consciousness stack with a unified 10-layer cognitive architecture that eliminates explicit dispatch in favor of implicit resonance-based routing via fingerprint similarity. New modules: - layer_stack.rs: 10-layer cognitive stack (L1:Recognition → L10:Crystallization) with 7-wave parallel processing and LayerNode/LayerResult types - satisfaction_gate.rs: Maslow-style continuous modulation where unsatisfied lower layers raise higher layers' effective thresholds proportionally - two_stroke.rs: 2-stroke engine (all layers fire every cycle against previous-cycle metadata), ThinkingStyle self-selection via resonance, NARS rule fingerprints (deduction/induction/abduction/analogy/revision), crystallize/recover_modulation via XOR bind/unbind - cognitive_kernel.rs: BindSpace bridge mapping layer outputs to kernel operations (resonate, write, bundle, crystallize) with popcount stacking early-exit at 1-2σ from centroid - cortex.rs: resonance-gated NARS rule selection replacing hardcoded apply_rule("deduction", ...) with gestalt fingerprint similarity Updated modules: - sieve.rs: L9 validation pipeline (NARS + Brier + XOR residual + Dunning-Kruger detection for high-confidence/high-divergence) - fabric.rs: 10-layer satisfaction gate, rule/style fingerprints, Crystallization triangle driven by L8/L9/L10 - grammar_engine.rs: updated from SevenLayerNode to LayerNode - seven_layer.rs: thin re-export wrapper for backward compat - contract/layers.rs: 10-layer constants with deprecation aliases - contract/legacy.rs: V1EnvelopeMetadata gains dominant_layer, layer_activations, nars_frequency, calibration_error for cross-agent awareness through shared metadata https://claude.ai/code/session_01HPnDXh9S876c15QLgkDpcN
1 parent 0670c86 commit 35900f8

16 files changed

Lines changed: 3991 additions & 627 deletions

File tree

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,69 @@
1-
//! 7-Layer consciousness markers.
1+
//! 10-Layer cognitive stack markers.
22
//!
3-
//! Each layer has a 5-byte marker stored in Container 0 metadata at W12-W15:
4-
//! (activation: u8, stability: u8, flags: u16, tag: u8)
3+
//! Each layer has a 3-byte marker stored in Container 0 metadata at W12-W15:
4+
//! (activation: u8, stability: u8, flags: u8)
55
//!
66
//! Read/write via [`MetaView::layer_marker(layer_index)`].
7+
//!
8+
//! ## 10-Layer Cognitive Stack
9+
//!
10+
//! ```text
11+
//! L1 Recognition — pattern matching, fingerprint encoding
12+
//! L2 Resonance — field binding, similarity search
13+
//! L3 Appraisal — gestalt, hypothesis, evaluation
14+
//! L4 Routing — branch selection, template dispatch
15+
//! L5 Execution — active manipulation, synthesis
16+
//! ─── single agent boundary ───
17+
//! L6 Delegation — cognitive fan-out, multi-agent
18+
//! L7 Contingency — cross-branch, could-be-otherwise
19+
//! L8 Integration — evidence merge, meta-awareness
20+
//! L9 Validation — NARS, Brier, Socratic sieve
21+
//! L10 Crystallization — what survives becomes system
22+
//! ```
723
8-
/// Type ID constants for the 7 consciousness layers.
9-
pub const LAYER_SUBSTRATE: u16 = 0x0200;
10-
pub const LAYER_FELT_CORE: u16 = 0x0201;
11-
pub const LAYER_BODY: u16 = 0x0202;
12-
pub const LAYER_QUALIA: u16 = 0x0203;
13-
pub const LAYER_VOLITION: u16 = 0x0204;
14-
pub const LAYER_GESTALT: u16 = 0x0205;
15-
pub const LAYER_META: u16 = 0x0206;
24+
/// Type ID constants for the 10 cognitive layers.
25+
pub const LAYER_RECOGNITION: u16 = 0x0200; // L1
26+
pub const LAYER_RESONANCE: u16 = 0x0201; // L2
27+
pub const LAYER_APPRAISAL: u16 = 0x0202; // L3
28+
pub const LAYER_ROUTING: u16 = 0x0203; // L4
29+
pub const LAYER_EXECUTION: u16 = 0x0204; // L5
30+
pub const LAYER_DELEGATION: u16 = 0x0205; // L6
31+
pub const LAYER_CONTINGENCY: u16 = 0x0206; // L7
32+
pub const LAYER_INTEGRATION: u16 = 0x0207; // L8
33+
pub const LAYER_VALIDATION: u16 = 0x0208; // L9
34+
pub const LAYER_CRYSTALLIZATION: u16 = 0x0209; // L10
1635

17-
/// Number of consciousness layers.
18-
pub const NUM_LAYERS: usize = 7;
36+
/// Number of cognitive layers.
37+
pub const NUM_LAYERS: usize = 10;
1938

20-
/// Layer names, indexed 0-6.
39+
/// Layer names, indexed 0-9.
2140
pub const LAYER_NAMES: [&str; NUM_LAYERS] = [
22-
"Substrate",
23-
"Felt Core",
24-
"Body",
25-
"Qualia",
26-
"Volition",
27-
"Gestalt",
28-
"Meta",
41+
"Recognition",
42+
"Resonance",
43+
"Appraisal",
44+
"Routing",
45+
"Execution",
46+
"Delegation",
47+
"Contingency",
48+
"Integration",
49+
"Validation",
50+
"Crystallization",
2951
];
52+
53+
// Deprecation aliases for old 7-layer names.
54+
// These keep the same type ID values (0x0200-0x0206) so existing
55+
// on-disk records remain readable.
56+
#[deprecated(note = "use LAYER_RECOGNITION")]
57+
pub const LAYER_SUBSTRATE: u16 = LAYER_RECOGNITION;
58+
#[deprecated(note = "use LAYER_RESONANCE")]
59+
pub const LAYER_FELT_CORE: u16 = LAYER_RESONANCE;
60+
#[deprecated(note = "use LAYER_APPRAISAL")]
61+
pub const LAYER_BODY: u16 = LAYER_APPRAISAL;
62+
#[deprecated(note = "use LAYER_ROUTING")]
63+
pub const LAYER_QUALIA: u16 = LAYER_ROUTING;
64+
#[deprecated(note = "use LAYER_EXECUTION")]
65+
pub const LAYER_VOLITION: u16 = LAYER_EXECUTION;
66+
#[deprecated(note = "use LAYER_DELEGATION")]
67+
pub const LAYER_GESTALT: u16 = LAYER_DELEGATION;
68+
#[deprecated(note = "use LAYER_CONTINGENCY")]
69+
pub const LAYER_META: u16 = LAYER_CONTINGENCY;

crates/ladybug-contract/src/legacy.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ pub struct V1EnvelopeMetadata {
105105
pub epoch: i64,
106106
#[serde(skip_serializing_if = "Option::is_none")]
107107
pub version: Option<String>,
108+
109+
// --- 10-Layer Cognitive Awareness (backward-compatible, all optional) ---
110+
111+
/// Dominant cognitive layer that produced this output (0-9 → L1-L10).
112+
/// Used for cross-agent routing: savant agents operate at L1-L5,
113+
/// orchestrator agents at L6-L10.
114+
#[serde(skip_serializing_if = "Option::is_none", default)]
115+
pub dominant_layer: Option<u8>,
116+
117+
/// 10-layer activation snapshot: [f32; 10] serialized as JSON array.
118+
/// Encodes the satisfaction state at the time of output, enabling
119+
/// cross-agent awareness through shared metadata.
120+
#[serde(skip_serializing_if = "Option::is_none", default)]
121+
pub layer_activations: Option<Vec<f32>>,
122+
123+
/// NARS frequency component (0.0-1.0) from L9 validation.
124+
#[serde(skip_serializing_if = "Option::is_none", default)]
125+
pub nars_frequency: Option<f64>,
126+
127+
/// Calibration error (Brier score) from MetaCognition.
128+
/// Lower = better calibrated. Consumers can use this to weight
129+
/// evidence from this source during L8 Integration.
130+
#[serde(skip_serializing_if = "Option::is_none", default)]
131+
pub calibration_error: Option<f64>,
108132
}
109133

110134
// ============================================================================
@@ -130,6 +154,24 @@ pub struct V1LadybugMetadata {
130154
pub epoch: Option<i64>,
131155
#[serde(skip_serializing_if = "Option::is_none")]
132156
pub version: Option<String>,
157+
158+
// --- 10-Layer Cognitive Awareness ---
159+
160+
/// Dominant cognitive layer (0-9 → L1-L10).
161+
#[serde(skip_serializing_if = "Option::is_none", default)]
162+
pub dominant_layer: Option<u8>,
163+
164+
/// 10-layer activation snapshot.
165+
#[serde(skip_serializing_if = "Option::is_none", default)]
166+
pub layer_activations: Option<Vec<f32>>,
167+
168+
/// NARS frequency from L9 validation.
169+
#[serde(skip_serializing_if = "Option::is_none", default)]
170+
pub nars_frequency: Option<f64>,
171+
172+
/// Calibration error (Brier score).
173+
#[serde(skip_serializing_if = "Option::is_none", default)]
174+
pub calibration_error: Option<f64>,
133175
}
134176

135177
// ============================================================================
@@ -235,6 +277,13 @@ impl From<&V1DataEnvelope> for CogRecord {
235277
let mut m = record.meta_view_mut();
236278
m.set_dn_addr(hash_step_id(&envelope.metadata.source_step));
237279
m.set_nars_confidence(envelope.metadata.confidence as f32);
280+
if let Some(freq) = envelope.metadata.nars_frequency {
281+
m.set_nars_frequency(freq as f32);
282+
}
283+
// Layer activations are carried in the JSON metadata, not
284+
// packed into container words (container layer markers are
285+
// 5-byte 7-layer format; the 10-layer data travels in the
286+
// serde envelope until container format is upgraded).
238287
}
239288
let bytes = serde_json::to_vec(&envelope.data).unwrap_or_default();
240289
record.content[0] = content_from_bytes(&bytes);
@@ -245,13 +294,36 @@ impl From<&V1DataEnvelope> for CogRecord {
245294
impl From<&CogRecord> for V1DataEnvelope {
246295
fn from(record: &CogRecord) -> V1DataEnvelope {
247296
let m = record.meta_view();
297+
298+
// Extract layer markers from container (7-layer format in W12-W15).
299+
// We extract the available 7 layers and pad with zeros for L8-L10.
300+
// Full 10-layer data travels in the JSON envelope when available.
301+
let mut layer_activations = Vec::with_capacity(10);
302+
let mut dominant: Option<(u8, f32)> = None;
303+
for i in 0..7 {
304+
let marker = m.layer_marker(i);
305+
let activation = marker.0 as f32 / 255.0;
306+
layer_activations.push(activation);
307+
if dominant.is_none() || activation > dominant.unwrap().1 {
308+
dominant = Some((i as u8, activation));
309+
}
310+
}
311+
// Pad L8-L10 with zero (not yet stored in container metadata)
312+
for _ in 7..10 {
313+
layer_activations.push(0.0);
314+
}
315+
248316
V1DataEnvelope {
249317
data: Value::Null,
250318
metadata: V1EnvelopeMetadata {
251319
source_step: format!("{:016X}", m.dn_addr()),
252320
confidence: m.nars_confidence() as f64,
253321
epoch: 0,
254322
version: None,
323+
dominant_layer: dominant.map(|(i, _)| i),
324+
layer_activations: Some(layer_activations),
325+
nars_frequency: Some(m.nars_frequency() as f64),
326+
calibration_error: None, // Not stored in container metadata
255327
},
256328
}
257329
}
@@ -297,6 +369,17 @@ impl From<&CogRecord> for V1LadybugEnvelope {
297369
},
298370
epoch: None,
299371
version: None,
372+
dominant_layer: None,
373+
layer_activations: None,
374+
nars_frequency: {
375+
let f = m.nars_frequency();
376+
if f > 0.0 {
377+
Some(f as f64)
378+
} else {
379+
None
380+
}
381+
},
382+
calibration_error: None,
300383
},
301384
}
302385
}

0 commit comments

Comments
 (0)