use crate::error::Result;
use serde::{Deserialize, Serialize};
pub mod bedrock;
pub mod brutalhonesty;
pub mod brutalhonesty_enhanced;
pub mod escot;
pub mod gigathink;
#[cfg(feature = "got")]
pub mod graphofthought;
pub mod image_generation;
pub mod laserlogic;
pub mod proofguard;
pub use bedrock::BedRock;
pub use brutalhonesty::BrutalHonesty;
pub use brutalhonesty_enhanced::BrutalHonestyEnhanced;
pub use escot::ESCoT;
pub use gigathink::GigaThink;
#[cfg(feature = "got")]
pub use graphofthought::GraphOfThought;
pub use laserlogic::LaserLogic;
pub use proofguard::ProofGuard;
pub use gigathink::{
AnalysisDimension, AsyncThinkToolModule, GigaThinkBuilder, GigaThinkConfig, GigaThinkError,
GigaThinkMetadata, GigaThinkResult, Perspective, SynthesizedInsight, Theme,
};
pub use laserlogic::{
Argument, ArgumentForm, Contradiction, ContradictionType, DetectedFallacy, Fallacy,
LaserLogicConfig, LaserLogicResult, Premise, PremiseType, SoundnessStatus, ValidityStatus,
};
pub use brutalhonesty::{
BrutalHonestyBuilder, BrutalHonestyConfig, CritiqueSeverity, CritiqueVerdict, DetectedFlaw,
FlawCategory, FlawSeverity, IdentifiedStrength, ImplicitAssumption,
};
pub use brutalhonesty_enhanced::{
ArgumentMap, BiasCategory, CognitiveBias, CognitiveBiasDepth, CulturalAssumption,
EnhancedBuilder, EnhancedConfig, SteelmanArgument,
};
pub use escot::{ESCoTBuilder, ESCoTConfig, ESCoTResult, Example, ExampleDatabase, SimilarExample};
#[cfg(feature = "got")]
pub use graphofthought::{
ExecutedOperation, GoTBuilder, GoTConfig, GoTMetadata, GoTResult, GraphOfThoughtError, GraphOp,
ReasoningGraphData, ThoughtMetadata, ThoughtNode,
};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThinkToolModuleConfig {
pub name: String,
pub version: String,
pub description: String,
pub confidence_weight: f64,
}
impl ThinkToolModuleConfig {
pub fn new(
name: impl Into<String>,
version: impl Into<String>,
description: impl Into<String>,
) -> Self {
Self {
name: name.into(),
version: version.into(),
description: description.into(),
confidence_weight: 0.20, }
}
pub fn with_confidence_weight(mut self, weight: f64) -> Self {
self.confidence_weight = weight.clamp(0.0, 1.0);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThinkToolContext {
pub query: String,
pub previous_steps: Vec<String>,
}
impl ThinkToolContext {
pub fn new(query: impl Into<String>) -> Self {
Self {
query: query.into(),
previous_steps: Vec::new(),
}
}
pub fn with_previous_steps(query: impl Into<String>, steps: Vec<String>) -> Self {
Self {
query: query.into(),
previous_steps: steps,
}
}
pub fn add_previous_step(&mut self, step: impl Into<String>) {
self.previous_steps.push(step.into());
}
pub fn has_previous_steps(&self) -> bool {
!self.previous_steps.is_empty()
}
pub fn previous_step_count(&self) -> usize {
self.previous_steps.len()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThinkToolOutput {
pub module: String,
pub confidence: f64,
pub output: serde_json::Value,
}
impl ThinkToolOutput {
pub fn new(module: impl Into<String>, confidence: f64, output: serde_json::Value) -> Self {
Self {
module: module.into(),
confidence: confidence.clamp(0.0, 1.0),
output,
}
}
pub fn get(&self, field: &str) -> Option<&serde_json::Value> {
self.output.get(field)
}
pub fn get_str(&self, field: &str) -> Option<&str> {
self.output.get(field).and_then(|v| v.as_str())
}
pub fn get_array(&self, field: &str) -> Option<&Vec<serde_json::Value>> {
self.output.get(field).and_then(|v| v.as_array())
}
pub fn is_high_confidence(&self) -> bool {
self.confidence >= 0.80
}
pub fn meets_threshold(&self, threshold: f64) -> bool {
self.confidence >= threshold
}
}
pub trait ThinkToolModule: Send + Sync {
fn config(&self) -> &ThinkToolModuleConfig;
fn execute(&self, context: &ThinkToolContext) -> Result<ThinkToolOutput>;
fn name(&self) -> &str {
&self.config().name
}
fn version(&self) -> &str {
&self.config().version
}
fn description(&self) -> &str {
&self.config().description
}
fn confidence_weight(&self) -> f64 {
self.config().confidence_weight
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_module_config_creation() {
let config = ThinkToolModuleConfig::new("TestModule", "1.0.0", "A test module");
assert_eq!(config.name, "TestModule");
assert_eq!(config.version, "1.0.0");
assert_eq!(config.confidence_weight, 0.20);
}
#[test]
fn test_module_config_with_weight() {
let config = ThinkToolModuleConfig::new("TestModule", "1.0.0", "A test module")
.with_confidence_weight(0.35);
assert_eq!(config.confidence_weight, 0.35);
}
#[test]
fn test_context_creation() {
let context = ThinkToolContext::new("Test query");
assert_eq!(context.query, "Test query");
assert!(context.previous_steps.is_empty());
}
#[test]
fn test_context_with_previous_steps() {
let context =
ThinkToolContext::with_previous_steps("Query", vec!["Step 1".into(), "Step 2".into()]);
assert!(context.has_previous_steps());
assert_eq!(context.previous_step_count(), 2);
}
#[test]
fn test_output_creation() {
let output =
ThinkToolOutput::new("TestModule", 0.85, serde_json::json!({"result": "success"}));
assert_eq!(output.module, "TestModule");
assert_eq!(output.confidence, 0.85);
assert!(output.is_high_confidence());
}
#[test]
fn test_output_threshold() {
let output =
ThinkToolOutput::new("TestModule", 0.75, serde_json::json!({"result": "success"}));
assert!(output.meets_threshold(0.70));
assert!(!output.meets_threshold(0.80));
}
#[test]
fn test_output_field_access() {
let output = ThinkToolOutput::new(
"TestModule",
0.85,
serde_json::json!({
"name": "test",
"values": [1, 2, 3]
}),
);
assert_eq!(output.get_str("name"), Some("test"));
assert!(output.get_array("values").is_some());
}
#[test]
fn test_gigathink_module() {
let module = GigaThink::new();
assert_eq!(module.name(), "GigaThink");
assert_eq!(module.version(), "2.1.0");
}
#[test]
fn test_gigathink_execution() {
let module = GigaThink::new();
let context = ThinkToolContext::new("What are the implications of AI adoption?");
let result = module.execute(&context).unwrap();
assert_eq!(result.module, "GigaThink");
assert!(result.confidence > 0.0);
let perspectives = result.get_array("perspectives").unwrap();
assert!(perspectives.len() >= 10);
}
#[test]
fn test_laserlogic_module() {
let module = LaserLogic::new();
assert_eq!(module.name(), "LaserLogic");
assert_eq!(module.version(), "3.0.0");
}
#[test]
fn test_laserlogic_analyze_argument() {
let module = LaserLogic::new();
let result = module
.analyze_argument(
&["All humans are mortal", "Socrates is human"],
"Socrates is mortal",
)
.unwrap();
assert_eq!(
result.argument_form,
Some(ArgumentForm::CategoricalSyllogism)
);
assert!(result.confidence > 0.0);
}
#[test]
fn test_laserlogic_fallacy_detection() {
let module = LaserLogic::new();
let result = module
.analyze_argument(
&["If it rains, then the ground is wet", "The ground is wet"],
"It rained",
)
.unwrap();
assert!(result.has_fallacies());
assert!(result
.fallacies
.iter()
.any(|f| f.fallacy == Fallacy::AffirmingConsequent));
}
#[test]
fn test_brutalhonesty_module() {
let module = BrutalHonesty::new();
assert_eq!(module.name(), "BrutalHonesty");
assert_eq!(module.version(), "3.0.0");
}
#[test]
fn test_brutalhonesty_execution() {
let module = BrutalHonesty::new();
let context =
ThinkToolContext::new("Our startup will succeed because we have the best team");
let result = module.execute(&context).unwrap();
assert_eq!(result.module, "BrutalHonesty");
assert!(result.confidence > 0.0);
assert!(result.confidence <= 0.95);
assert!(result.get("verdict").is_some());
assert!(result.get("analysis").is_some());
assert!(result.get("devils_advocate").is_some());
}
#[test]
fn test_brutalhonesty_enhanced_module() {
let module = BrutalHonestyEnhanced::new();
assert_eq!(module.name(), "BrutalHonestyEnhanced");
assert_eq!(module.version(), "3.0.0");
}
#[test]
fn test_brutalhonesty_enhanced_execution() {
let module = BrutalHonestyEnhanced::new();
let context = ThinkToolContext::new(
"We're certain this will succeed because everyone agrees it's the best approach.",
);
let result = module.execute(&context).unwrap();
assert_eq!(result.module, "BrutalHonestyEnhanced");
assert!(result.confidence > 0.0);
assert!(result.confidence <= 0.90);
assert!(result.get("enhanced_analysis").is_some());
assert!(result.get("base_analysis").is_some());
}
#[test]
fn test_brutalhonesty_builder() {
let module = BrutalHonesty::builder()
.severity(CritiqueSeverity::Ruthless)
.enable_devil_advocate(true)
.build();
assert_eq!(module.brutal_config().severity, CritiqueSeverity::Ruthless);
assert!(module.brutal_config().enable_devil_advocate);
}
#[test]
fn test_brutalhonesty_enhanced_builder() {
let module = BrutalHonestyEnhanced::builder()
.severity(CritiqueSeverity::Harsh)
.cognitive_bias_depth(CognitiveBiasDepth::Deep)
.enable_cultural_analysis(true)
.build();
assert_eq!(
module.enhanced_config().base_config.severity,
CritiqueSeverity::Harsh
);
assert_eq!(
module.enhanced_config().cognitive_bias_depth,
CognitiveBiasDepth::Deep
);
}
}