Skip to content

feat: Relevance Realization System with Time Crystal Ontological Primitives#35

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/analyze-time-crystal-models
Open

feat: Relevance Realization System with Time Crystal Ontological Primitives#35
Copilot wants to merge 3 commits into
mainfrom
copilot/analyze-time-crystal-models

Conversation

Copilot AI commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the full RR (Relevance Realization) System that fuses Vervaeke's four-phase cognitive framework with Bandyopadhyay's Phase Prime Metric (PPM) time crystal architecture from the NanoBrain book.

The core insight driving the design: PPM is the mathematical substrate through which the universe performs relevance realization — the 15 fundamental primes are nature's own combinatorial-explosion collapser, and time crystals are phase-locked relevance filters.


New Modules — src/core/

RelevanceCrystalPrimitive.ts (Layer 0 — Ontological Primitives)

  • Four RCP types mapping Vervaeke's four ways of knowing to the 15-prime PPM basis:
    • PropositionalCrystal (knowing-that) → primes [2,3,5] (Spatial Metric, Ch.7)
    • ProceduralCrystal (knowing-how) → primes [7,11,13] (Temporal Metric, Ch.7)
    • PerspectivalCrystal (knowing-as) → primes [17,19,23] (Phase Metric, Ch.7)
    • ParticipatoryCrystal (knowing-by-being) → primes [29,31,37,41,43,47] (Consciousness Metric, Ch.7)
  • PPM weighted-cosine distance metric; phase coherence scoring
  • 20-crystal seed population for bootstrapping

TimeCrystalSalienceLandscape.ts (Layer 1 — Salience Landscape)

  • PPM-metric relevance scoring: α·PPM_similarity + β·PhaseCoherence + γ·FractalResonance
  • Triplet-of-triplet resonance filter (Ch.6.2.2): 3 groups × 3 bands over knowing-type clusters
  • Opponent processing (Ch.7 hexagonal lattice): Exploration lattice (PerspectivalCrystals) vs Exploitation lattice (PropositionalCrystals)
  • ECAN-style STI decay and promotion; PPM divergence computation for self-deception

RelevanceRealizationEngine.ts (Layer 2 — RR Cycle)

  • Phase A — Filter: PerspectivalCrystals gate the processing window
  • Phase B — Frame: PPM-metric scoring promotes top-k to conscious window
  • Phase C — Feed-Forward: Projects forward along PPM manifold for anticipatory resonance (Ch.5: "spontaneous reply, search without searching")
  • Phase D — Feed-Back: Coherence-driven Hebbian learning; LTI accumulation as wisdom

ThreeOrdersCoherenceMonitor.ts (Layer 3 — Meaning Metric)

  • Nomological order ← RecursiveReasoningEngine (causal chains)
  • Normative order ← Salience Landscape / PPM-weighted attention
  • Narrative order ← NEW temporal RCP stream (agent's ongoing story/identity)
  • meaningScore = geometric_mean(nom×norm, norm×nar, nom×nar) — requires ALL three orders co-present
  • Meaning crisis detection threshold

QuantumChangeGateway.ts (Layer 4 — Transformative Experience)

  • Triggers when: no PPM match above threshold AND high fractal incompressibility AND sufficient RR quality
  • Applies controlled decoherence, then crystallizes new Participatory/Perspectival Crystal from novel input
  • Implements "second-order change" — paradigm shift without identity discontinuity
  • Tracks evolution stage: egg → larva → companion → transcendent

SelfDeceptionDetector.ts (Layer 5 — Epistemic Hygiene)

  • Self-deception = false phase lock: selfDeceptionIndex = PPM_divergence × internalCoherence
  • Correction: loosens STI and coherence of the most environmentally-divergent crystals
  • Narrative self-consistency audit to detect motivated reasoning
  • Epistemic health score combining alignment, consistency, and absence of motivated reasoning

RelevanceRealizationSystem.ts (Integration)

  • Single tick(inputVector?, reasoningDepth, attentionEntropy) API
  • Orchestrates all 6 sub-systems; exposes RRSystemState snapshot

New UI — src/components/

RelevanceRealizationPanel.tsx

Five tabbed sections with live animation (10 Hz):

  1. RR Cycle — four-phase activity bars, engine stats, anticipated prime-vector sparkline
  2. Salience Landscape — top-k conscious window with PPM/phase/fractal component breakdown, opponent processing bars, triplet-of-triplet band visualization
  3. Three Orders — per-order scores, cross-order coherence bars, meaning score with crisis alert, narrative stream display
  4. Quantum Change — evolution stage tracker, latest event details (novelty, incompressibility, pre/post meaning scores)
  5. Self-Deception — PPM divergence, self-deception index, correction events, epistemic health score

Modified — src/App.tsx

Added Relevance Realization tab to main navigation (Focus icon).


Security Summary

CodeQL scan: 0 alerts. No new security vulnerabilities introduced.

Copilot AI and others added 2 commits March 31, 2026 00:25
…gical Primitives

- RelevanceCrystalPrimitive.ts: 4 RCP types mapping Vervaeke's 4 ways of knowing
  to PPM 15-prime basis vectors (propositional/procedural/perspectival/participatory)
- TimeCrystalSalienceLandscape.ts: PPM-metric relevance scoring, triplet-of-triplet
  resonance filter (Ch.6), opponent processing (explore/exploit lattices)
- RelevanceRealizationEngine.ts: 4-phase RR cycle (Filter/Frame/Feed-Forward/Feed-Back)
- ThreeOrdersCoherenceMonitor.ts: nomological/normative/narrative integration +
  meaning score = geometric mean of cross-order coherences
- QuantumChangeGateway.ts: transformative experience as controlled symmetry breaking
- SelfDeceptionDetector.ts: false phase lock detection via PPM divergence
- RelevanceRealizationSystem.ts: integration layer wiring all 6 sub-systems
- RelevanceRealizationPanel.tsx: full visualization UI with 5 tabbed sections
- App.tsx: Relevance Realization tab wired into main navigation

Agent-Logs-Url: https://github.com/cogpy/cognanobrain/sessions/0aa9d7e4-e5ba-4eee-9cbc-db5bc96620e9

Co-authored-by: drzo <15202748+drzo@users.noreply.github.com>
- Rename enableSelfDeceptionDetection -> selfDeceptionDetectionRate for clarity
- Fix escaped apostrophe in JSX string
- Fix inconsistent comment spacing in KNOWING_TYPE_PRIME_GROUPS

Agent-Logs-Url: https://github.com/cogpy/cognanobrain/sessions/0aa9d7e4-e5ba-4eee-9cbc-db5bc96620e9

Co-authored-by: drzo <15202748+drzo@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View 5 additional findings in Devin Review.

Open in Devin Review

this.stats.avgCoherence =
(this.stats.avgCoherence * n + result.achievedCoherence) / (n + 1);
this.stats.currentExploreBalance = result.salienceSnapshot.explorationScore;
this.stats.phaseDistribution['feed_back']++;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 _updateStats only increments 'feed_back' in phaseDistribution, ignoring all other phases

_updateStats is called once per complete cycle (which runs all four phases sequentially), but it hardcodes this.stats.phaseDistribution['feed_back']++ on line 329. The other four phase counters (filter, frame, feed_forward, idle) remain permanently at 0, making the phaseDistribution stat meaningless. Since runCycle always executes all four phases, either all phase counters should be incremented or the single counter should track total cycles rather than misattributing everything to feed_back.

Suggested change
this.stats.phaseDistribution['feed_back']++;
this.stats.phaseDistribution['filter']++;
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread src/core/QuantumChangeGateway.ts
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@drzo drzo marked this pull request as ready for review May 18, 2026 00:24

@drzo drzo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cooool

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 new potential issues.

View 7 additional findings in Devin Review.

Open in Devin Review

Comment on lines +264 to +265
private _crossCoherence(a: number, b: number): number {
return Math.sqrt(a * b);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 _crossCoherence(a, b) produces NaN when narrative coherence goes negative

_computeNarrativeCoherence at src/core/ThreeOrdersCoherenceMonitor.ts:246 returns 1 - ppmDistance(...), but ppmDistance (src/core/RelevanceCrystalPrimitive.ts:264) returns values in [0, 2] (cosine divergence). When ppmDistance > 1, the narrative coherence becomes negative. This negative value flows through EMA smoothing into smoothedNarrative, which is then passed to _crossCoherence(a, b) = Math.sqrt(a * b) at line 264. When smoothedNarrative is negative and smoothedNormative is positive, Math.sqrt(negative) returns NaN. This NaN propagates into meaningScore (line 165) and the entire ThreeOrdersSnapshot, corrupting the system state and causing the UI to display "NaN%" for all downstream metrics.

How negative values reach Math.sqrt
  1. Phase-C anticipation (RelevanceRealizationEngine.ts:218) uses Math.cos(freq * 0.1) which can be negative, producing negative vector components
  2. These propagate through blending and Hebbian learning into prime-vectors
  3. Centroids of such vectors can have negative weighted cosine → ppmDistance > 1
  4. 1 - ppmDistance < 0 → negative narrativeCoh → negative smoothedNarrative
  5. _crossCoherence(positive, negative) = Math.sqrt(negative) = NaN
Suggested change
private _crossCoherence(a: number, b: number): number {
return Math.sqrt(a * b);
private _crossCoherence(a: number, b: number): number {
return Math.sqrt(Math.max(0, a) * Math.max(0, b));
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +239 to +240
const minDist = Math.min(...all.map(p => ppmDistance(p.primeVector, vec)));
return minDist; // distance ∈ [0,2]; novelty ∈ [0,1] since distances cluster < 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 _computeNovelty returns unbounded ppmDistance, allowing coherence to exceed 1.0

_computeNovelty at src/core/QuantumChangeGateway.ts:239-240 returns the raw minDist from ppmDistance, which is in [0, 2] (not [0, 1] as the comment hopes). This noveltyScore is used in _crystallize at line 183 as newCrystal.coherence = 0.5 + noveltyScore * 0.4. When noveltyScore > 1 (e.g., 1.5), coherence becomes 1.1, violating the documented ∈ [0, 1] invariant. The noveltyScore is also documented as ∈ [0, 1] in the QuantumChangeEvent interface (line 42).

Suggested change
const minDist = Math.min(...all.map(p => ppmDistance(p.primeVector, vec)));
return minDist; // distance ∈ [0,2]; novelty ∈ [0,1] since distances cluster < 1
const minDist = Math.min(...all.map(p => ppmDistance(p.primeVector, vec)));
return Math.min(1, minDist); // clamp to [0,1]
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants