File size: 4,419 Bytes
33b4056
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
pub mod core;
pub mod sandbox;
pub mod sim;
pub mod spatial;
pub mod render;
pub mod physics;
pub mod layers;
pub mod engine;
pub mod autofix;
pub mod reporters;
pub mod multi;
pub mod multi_engine;
pub mod weaver;
pub mod ai;
pub mod anomaly;

pub mod quality_filter;
pub mod text_quality;
pub mod fisig_formatter;
pub mod omni;
pub mod speech;
pub mod microwave;
pub mod gpu;
pub mod vsa;
pub mod safety;
pub mod patcher;
pub mod gguf;

pub use core::hypervector::Hypervector;
pub use core::information_triangle::InformationTriangle;
pub use core::pentagon_storage::PentagonStorage;
pub use core::wave_cube::WaveCube;
pub use core::fuga_synthesizer::{FugaResult, FugaSynthesizer, BugLocation};

pub use layers::syntax_layer::{
    SyntaxInvariantLayer, SyntaxAnalysisResult, SyntaxViolation,
    ViolationKind, Severity, CodeStats,
};
pub use layers::semantic_layer::{
    SemanticLayer, SemanticAnalysis, SemanticAnomaly, AnomalyKind,
};
pub use layers::chaos_layer::{
    ChaosMutationLayer, ChaosAnalysis, ChaosAttack,
    AttackKind, AttackMetadata, ChaosStats,
};

pub use engine::{
    FugaEngine, FugaEngineResult, AnalysisResult, ViolationInfo, AttackInfo,
    LayerResults, FugaError, SourceStats,
};

pub use autofix::{
    FixGenerator, FixValidator, PatchGenerator,
    FixStrategy, FixProposal, UnifiedDiff,
};

pub use reporters::{
    Reporter, OutputFormat, FileAnalysisResult, WorkspaceStats,
    JsonReporter, HtmlReporter, MarkdownReporter,
    WorkspaceScanner, ScanMode,
};

pub use multi_engine::{MultiEngine, MultiEngineResult};

pub use multi::{
    LanguageId, MultiSyntaxLayer, MultiSyntaxResult, MultiSyntaxViolation,
    MultiSemanticLayer, MultiSemanticResult, MultiSemanticAnomaly,
    MultiChaosLayer, MultiChaosResult, MultiChaosAttack,
    ViolationPattern, MultiFixGenerator, CodeTranslator,
};

pub use weaver::{
    WeaverEngine, WeaverResult, UnweaveResult,
    super_token::{SuperToken, TokenRole},
    token_builder::TokenBuilder,
    pattern_matcher::TokenInfo,
    vocabulary::TokenVocabulary,
    explorer::TokenExplorer,
};

pub use sim::{
    CubicController, Pipe, Valve, Heater, Boiler, Phase,
};

pub use ai::{
    FugaAI, AIOutput, ResonanceAttention, AttentionCell,
    DynamicRouter, TargetExpert, ExpertConfig,
    MemoryStore, MemoryEntry, MoEStore,
    AnswerEngine, AnswerResult, AnswerHit,
    CodegenResult, JepaPredictor, HierarchicalJEPA, PromptVectors,
    SdrVector, SdrIndex, SdrStore, sparsify, encode_text, domain_sdr,
    SDR_DIM, SDR_DENSITY, SDR_WORDS,
    TemporalMemory, TemporalCell, DendriteSegment, Synapse,
    AnomalyDetector, AnomalyEvent, AnomalyReflector, CorrectionSignal, StyloProfile,
    temporal_predictor::{TemporalPredictor, sdr_to_hypervector},
    self_mirror::{SelfMirror, PhaseNode, AutoCorrectEngine, AutoCorrectSuggestion, InspectReport, RawChunk},
};

pub use quality_filter::{
    CodeQualityFilter, QualityScore, summarize_quality,
};
pub use text_quality::{
    TextQualityFilter, TextQualityScore, TextSourceType,
    extract_dialogue_pairs, summarize_text_quality,
};

use serde::Deserialize;

#[derive(Deserialize, Clone)]
pub struct CorpusDoc {
    pub title: Option<String>,
    pub author: Option<String>,
    pub language: Option<String>,
    pub chapters: Vec<CorpusChapter>,
}

#[derive(Deserialize, Clone)]
pub struct CorpusChapter {
    pub heading: Option<String>,
    pub paragraphs: Vec<String>,
    pub number: Option<u64>,
}

pub fn tokenize_corpus_text(text: &str, vocab: &[(u32, String)]) -> Vec<crate::weaver::pattern_matcher::TokenInfo> {
    use std::collections::HashMap;
    use crate::weaver::pattern_matcher::TokenInfo;

    let word_id_map: HashMap<&str, u32> = vocab.iter()
        .map(|(id, t)| (t.as_str(), *id))
        .collect();

    text.split_whitespace().enumerate().map(|(_, word)| {
        let id = word_id_map.get(word).copied().unwrap_or_else(|| {
            let h = word.bytes().fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32));
            100000 + (h % 90000)
        });
        TokenInfo { id, text: word.to_string() }
    }).collect()
}

pub fn load_corpus(path: &str) -> Result<Vec<CorpusDoc>, String> {
    let content = std::fs::read_to_string(path)
        .map_err(|e| format!("Failed to read corpus: {}", e))?;
    Ok(content.lines()
        .filter(|l| !l.trim().is_empty())
        .filter_map(|l| serde_json::from_str(l).ok())
        .collect())
}