about summary refs log tree commit diff stats
path: root/bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash')
-rwxr-xr-xbash/computer295
-rwxr-xr-xbash/exploration246
-rwxr-xr-xbash/logging.sh146
-rwxr-xr-xbash/metrics18
-rwxr-xr-xbash/synthesis240
5 files changed, 945 insertions, 0 deletions
diff --git a/bash/computer b/bash/computer
new file mode 100755
index 0000000..e5aa36d
--- /dev/null
+++ b/bash/computer
@@ -0,0 +1,295 @@
+#!/bin/bash
+
+# Get the directory where this script is located
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Computer Dispatch System
+# This script intelligently routes prompts to the most appropriate thinking mechanism
+# or directly to Ollama based on complexity, question type, and user intent.
+#
+# APPLICATION LOGIC:
+# The computer dispatch system implements an intelligent routing mechanism that
+# analyzes user prompts and determines the optimal response strategy. The system
+# operates through three distinct phases designed to maximize response quality:
+#
+# PHASE 1 - PROMPT ANALYSIS:
+#   - Analyzes prompt complexity, length, and question type
+#   - Identifies user intent and specific keywords
+#   - Determines if direct Ollama response is appropriate
+#   - Classifies prompts into response categories
+#
+# PHASE 2 - MECHANISM SELECTION:
+#   - Routes to appropriate thinking mechanism based on classification
+#   - Uses decision tree with keywords for clear cases
+#   - Considers prompt complexity and user intent
+#   - Falls back to direct Ollama for simple cases
+#
+# PHASE 3 - RESPONSE EXECUTION:
+#   - Executes the selected mechanism or direct Ollama call
+#   - Maintains transparency about the routing decision
+#   - Provides consistent output format regardless of mechanism
+#   - Logs the decision process for analysis
+#
+# DISPATCH MODELING:
+# The system applies intelligent routing principles to AI response generation:
+#   - Prompt classification helps match complexity to appropriate mechanism
+#   - Keyword analysis identifies specific user needs and intent
+#   - Decision tree provides consistent, predictable routing logic
+#   - Direct Ollama routing handles simple cases efficiently
+#   - Transparency shows users how their prompt was processed
+#   - The system may improve response quality by using specialized mechanisms
+#
+# The dispatch process emphasizes efficiency and appropriateness,
+# ensuring users get the best possible response for their specific needs.
+# The system balances speed with depth based on prompt characteristics.
+
+# --- Model Configuration ---
+DEFAULT_MODEL="gemma3n:e2b"
+
+# --- Defaults ---
+DEFAULT_ROUNDS=2
+
+# --- Argument Validation ---
+if [ "$#" -lt 1 ]; then
+    echo -e "\n\tComputer"
+    echo -e "\tThis script intelligently routes prompts to the most appropriate thinking mechanism"
+    echo -e "\tor directly to Ollama based on complexity, question type, and user intent."
+    echo -e "\n\tUsage: $0 [-f <file_path>] [-d] \"<your prompt>\" [number_of_rounds]"
+    echo -e "\n\tExample: $0 -f ./input.txt \"Please analyze this text\" 2"
+    echo -e "\n\tIf number_of_rounds is not provided, the program will default to $DEFAULT_ROUNDS rounds."
+    echo -e "\n\t-f <file_path> (optional): Append the contents of the file to the prompt."
+    echo -e "\n\t-d (optional): Force direct Ollama response (bypass thinking mechanisms)."
+    echo -e "\n"
+    exit 1
+fi
+
+# --- Argument Parsing ---
+FILE_PATH=""
+FORCE_DIRECT=false
+while getopts "f:d" opt; do
+  case $opt in
+    f)
+      FILE_PATH="$OPTARG"
+      ;;
+    d)
+      FORCE_DIRECT=true
+      ;;
+    *)
+      echo "Invalid option: -$OPTARG" >&2
+      exit 1
+      ;;
+  esac
+done
+shift $((OPTIND -1))
+
+PROMPT="$1"
+if [ -z "$2" ]; then
+    ROUNDS=$DEFAULT_ROUNDS
+else
+    ROUNDS=$2
+fi
+
+# If file path is provided, append its contents to the prompt
+if [ -n "$FILE_PATH" ]; then
+    if [ ! -f "$FILE_PATH" ]; then
+        echo "File not found: $FILE_PATH" >&2
+        exit 1
+    fi
+    FILE_CONTENTS=$(cat "$FILE_PATH")
+    PROMPT="$PROMPT\n[FILE CONTENTS]\n$FILE_CONTENTS\n[END FILE]"
+fi
+
+# Source the logging system using absolute path
+source "${SCRIPT_DIR}/logging.sh"
+
+# --- File Initialization ---
+# Create a temporary directory if it doesn't exist
+mkdir -p ~/tmp
+# Create a unique file for this session based on the timestamp
+SESSION_FILE=~/tmp/computer_$(date +%Y%m%d_%H%M%S).txt
+
+# Initialize timing
+SESSION_ID=$(generate_session_id)
+start_timer "$SESSION_ID" "computer"
+
+echo "Computer Dispatch Session Log: ${SESSION_FILE}"
+echo "---------------------------------"
+
+# Store the initial user prompt in the session file
+echo "USER PROMPT: ${PROMPT}" >> "${SESSION_FILE}"
+echo "FORCE DIRECT: ${FORCE_DIRECT}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Prompt Analysis Function ---
+analyze_prompt() {
+    local prompt="$1"
+    local analysis=""
+    
+    # Check for direct Ollama requests
+    if [[ "$prompt" =~ (direct|simple|quick|fast|straight) ]]; then
+        analysis="DIRECT"
+        return
+    fi
+    
+    # Check prompt length (simple heuristic for complexity)
+    local word_count=$(echo "$prompt" | wc -w)
+    
+    # Very short prompts (likely simple questions)
+    if [ "$word_count" -le 5 ]; then
+        analysis="DIRECT"
+        return
+    fi
+    
+    # Keyword-based classification
+    if [[ "$prompt" =~ (consensus|agree|disagree|vote|multiple|perspectives|opinions) ]]; then
+        analysis="CONSENSUS"
+    elif [[ "$prompt" =~ (synthesize|combine|integrate|unify|merge|consolidate) ]]; then
+        analysis="SYNTHESIS"
+    elif [[ "$prompt" =~ (explore|paths|alternatives|options|compare|strategies|approaches) ]]; then
+        analysis="EXPLORATION"
+    elif [[ "$prompt" =~ (analyze|examine|explore|investigate|deep|thorough|comprehensive) ]]; then
+        analysis="SOCRATIC"
+    elif [[ "$prompt" =~ (improve|refine|edit|revise|better|enhance|polish|fix) ]]; then
+        analysis="CRITIQUE"
+    elif [[ "$prompt" =~ (review|feedback|peer|collaborate|suggest|advice) ]]; then
+        analysis="PEER_REVIEW"
+    else
+        # Default to direct for unclear cases
+        analysis="DIRECT"
+    fi
+    
+    echo "$analysis"
+}
+
+# --- Mechanism Selection ---
+echo "Analyzing prompt and selecting mechanism..."
+echo "PROMPT ANALYSIS:" >> "${SESSION_FILE}"
+
+if [ "$FORCE_DIRECT" = true ]; then
+    MECHANISM="DIRECT"
+    REASON="User requested direct response with -d flag"
+else
+    MECHANISM=$(analyze_prompt "$PROMPT")
+    case "$MECHANISM" in
+        "DIRECT")
+            REASON="Simple prompt or direct request"
+            ;;
+        "CONSENSUS")
+            REASON="Multiple perspectives or consensus needed"
+            ;;
+        "SYNTHESIS")
+            REASON="Integration of multiple approaches needed"
+            ;;
+        "EXPLORATION")
+            REASON="Systematic exploration of alternatives needed"
+            ;;
+        "SOCRATIC")
+            REASON="Deep analysis or exploration required"
+            ;;
+        "CRITIQUE")
+            REASON="Improvement or refinement requested"
+            ;;
+        "PEER_REVIEW")
+            REASON="Collaborative review or feedback needed"
+            ;;
+        *)
+            REASON="Default fallback"
+            MECHANISM="DIRECT"
+            ;;
+    esac
+fi
+
+echo "Selected mechanism: ${MECHANISM}" >> "${SESSION_FILE}"
+echo "Reason: ${REASON}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+echo "Selected mechanism: ${MECHANISM}"
+echo "Reason: ${REASON}"
+echo "---------------------------------"
+
+# --- Response Execution ---
+echo "Executing selected mechanism..."
+echo "RESPONSE EXECUTION:" >> "${SESSION_FILE}"
+
+case "$MECHANISM" in
+    "DIRECT")
+        echo "Using direct Ollama response..."
+        echo "DIRECT OLLAMA RESPONSE:" >> "${SESSION_FILE}"
+        
+        DIRECT_PROMPT="You are an expert assistant. You always flag if you don't know something. Please provide a clear, helpful response to the following prompt: ${PROMPT}"
+        
+        RESPONSE=$(ollama run "${DEFAULT_MODEL}" "${DIRECT_PROMPT}")
+        
+        echo "${RESPONSE}" >> "${SESSION_FILE}"
+        echo "" >> "${SESSION_FILE}"
+        
+        echo "---------------------------------"
+        echo "Direct response:"
+        echo "---------------------------------"
+        echo "${RESPONSE}"
+        ;;
+        
+    "CONSENSUS")
+        echo "Delegating to consensus mechanism..."
+        echo "DELEGATING TO CONSENSUS:" >> "${SESSION_FILE}"
+        
+        # Execute consensus script and display output directly
+        "${SCRIPT_DIR}/consensus" "${PROMPT}" "${ROUNDS}" 2>&1 | tee -a "${SESSION_FILE}"
+        ;;
+        
+    "SOCRATIC")
+        echo "Delegating to Socratic mechanism..."
+        echo "DELEGATING TO SOCRATIC:" >> "${SESSION_FILE}"
+        
+        # Execute Socratic script and display output directly
+        "${SCRIPT_DIR}/socratic" "${PROMPT}" "${ROUNDS}" 2>&1 | tee -a "${SESSION_FILE}"
+        ;;
+        
+    "CRITIQUE")
+        echo "Delegating to critique mechanism..."
+        echo "DELEGATING TO CRITIQUE:" >> "${SESSION_FILE}"
+        
+        # Execute critique script and display output directly
+        "${SCRIPT_DIR}/critique" "${PROMPT}" "${ROUNDS}" 2>&1 | tee -a "${SESSION_FILE}"
+        ;;
+        
+        "PEER_REVIEW")
+        echo "Delegating to peer-review mechanism..."
+        echo "DELEGATING TO PEER_REVIEW:" >> "${SESSION_FILE}"
+        
+        # Execute peer-review script and display output directly
+        "${SCRIPT_DIR}/peer-review" "${PROMPT}" "${ROUNDS}" 2>&1 | tee -a "${SESSION_FILE}"
+        ;;
+        
+        "SYNTHESIS")
+        echo "Delegating to synthesis mechanism..."
+        echo "DELEGATING TO SYNTHESIS:" >> "${SESSION_FILE}"
+        
+        # Execute synthesis script and display output directly
+        "${SCRIPT_DIR}/synthesis" "${PROMPT}" "${ROUNDS}" 2>&1 | tee -a "${SESSION_FILE}"
+        ;;
+        
+        "EXPLORATION")
+        echo "Delegating to exploration mechanism..."
+        echo "DELEGATING TO EXPLORATION:" >> "${SESSION_FILE}"
+        
+        # Execute exploration script and display output directly
+        "${SCRIPT_DIR}/exploration" "${PROMPT}" "${ROUNDS}" 2>&1 | tee -a "${SESSION_FILE}"
+        ;;
+esac
+
+# --- Final Summary ---
+echo "" >> "${SESSION_FILE}"
+echo "DISPATCH SUMMARY:" >> "${SESSION_FILE}"
+echo "================" >> "${SESSION_FILE}"
+echo "Original Prompt: ${PROMPT}" >> "${SESSION_FILE}"
+echo "Selected Mechanism: ${MECHANISM}" >> "${SESSION_FILE}"
+echo "Reason: ${REASON}" >> "${SESSION_FILE}"
+echo "Rounds: ${ROUNDS}" >> "${SESSION_FILE}"
+
+# End timing
+duration=$(end_timer "$SESSION_ID" "computer")
+
+echo ""
+echo "Execution time: ${duration} seconds"
+echo "Full dispatch log: ${SESSION_FILE}" 
\ No newline at end of file
diff --git a/bash/exploration b/bash/exploration
new file mode 100755
index 0000000..8dc09b7
--- /dev/null
+++ b/bash/exploration
@@ -0,0 +1,246 @@
+#!/bin/bash
+
+# Get the directory where this script is located
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Exploration System
+# This script systematically explores multiple solution paths and compares alternatives.
+#
+# APPLICATION LOGIC:
+# The exploration process implements a branching analysis system that systematically
+# explores multiple approaches to a problem and compares their merits. The system
+# operates through three distinct phases designed to maximize discovery and comparison:
+#
+# PHASE 1 - PATH GENERATION:
+#   - Identifies multiple possible approaches to the problem
+#   - Generates alternative solution paths
+#   - Ensures comprehensive coverage of the solution space
+#   - Creates a foundation for systematic comparison
+#
+# PHASE 2 - PATH EXPLORATION:
+#   - Explores each identified path in detail
+#   - Develops the implications and consequences of each approach
+#   - Identifies strengths, weaknesses, and trade-offs
+#   - Provides detailed analysis of each alternative
+#
+# PHASE 3 - COMPARATIVE ANALYSIS:
+#   - Systematically compares all explored paths
+#   - Evaluates relative merits and trade-offs
+#   - Identifies optimal approaches or combinations
+#   - Provides recommendations based on different criteria
+#
+# EXPLORATION MODELING:
+# The system applies systematic exploration principles to AI response generation:
+#   - Multiple paths ensure comprehensive problem coverage
+#   - Systematic comparison reveals optimal approaches
+#   - Trade-off analysis helps users make informed decisions
+#   - The process may reveal unexpected insights or approaches
+#   - Transparency shows how different paths were evaluated
+#   - The method may identify novel solutions that single-path approaches miss
+#
+# The exploration process emphasizes systematic analysis and comparison,
+# ensuring users understand the full range of possible approaches and their implications.
+
+# Source the logging system using absolute path
+source "${SCRIPT_DIR}/logging.sh"
+
+# --- Model Configuration ---
+EXPLORATION_MODEL="llama3:8b-instruct-q4_K_M"
+ANALYSIS_MODEL="phi3:3.8b-mini-4k-instruct-q4_K_M"
+
+# --- Defaults ---
+DEFAULT_PATHS=3
+
+# --- Argument Validation ---
+if [ "$#" -lt 1 ]; then
+    echo -e "\n\tExploration"
+    echo -e "\tThis script systematically explores multiple solution paths and compares alternatives."
+    echo -e "\n\tUsage: $0 [-f <file_path>] [-p <number_of_paths>] \"<your prompt>\" [number_of_rounds]"
+    echo -e "\n\tExample: $0 -f ./input.txt -p 4 \"How can we solve this problem?\" 2"
+    echo -e "\n\tIf number_of_rounds is not provided, the program will default to 2 rounds."
+    echo -e "\n\t-f <file_path> (optional): Append the contents of the file to the prompt."
+    echo -e "\n\t-p <paths> (optional): Number of solution paths to explore (default: 3)."
+    echo -e "\n"
+    exit 1
+fi
+
+# --- Argument Parsing ---
+FILE_PATH=""
+NUM_PATHS=$DEFAULT_PATHS
+while getopts "f:p:" opt; do
+  case $opt in
+    f)
+      FILE_PATH="$OPTARG"
+      ;;
+    p)
+      NUM_PATHS="$OPTARG"
+      ;;
+    *)
+      echo "Invalid option: -$OPTARG" >&2
+      exit 1
+      ;;
+  esac
+done
+shift $((OPTIND -1))
+
+PROMPT="$1"
+if [ -z "$2" ]; then
+    ROUNDS=2
+else
+    ROUNDS=$2
+fi
+
+# If file path is provided, append its contents to the prompt
+if [ -n "$FILE_PATH" ]; then
+    if [ ! -f "$FILE_PATH" ]; then
+        echo "File not found: $FILE_PATH" >&2
+        exit 1
+    fi
+    FILE_CONTENTS=$(cat "$FILE_PATH")
+    PROMPT="$PROMPT\n[FILE CONTENTS]\n$FILE_CONTENTS\n[END FILE]"
+fi
+
+# --- File Initialization ---
+mkdir -p ~/tmp
+SESSION_FILE=~/tmp/exploration_$(date +%Y%m%d_%H%M%S).txt
+
+# Initialize timing
+SESSION_ID=$(generate_session_id)
+start_timer "$SESSION_ID" "exploration"
+
+echo "Exploration Session Log: ${SESSION_FILE}"
+echo "---------------------------------"
+
+# Store the initial user prompt in the session file
+echo "USER PROMPT: ${PROMPT}" >> "${SESSION_FILE}"
+echo "NUMBER OF PATHS: ${NUM_PATHS}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Phase 1: Path Generation ---
+echo "Phase 1: Generating solution paths..."
+echo "PHASE 1 - PATH GENERATION:" >> "${SESSION_FILE}"
+
+PATH_GENERATION_PROMPT="You are a strategic thinker. Your task is to identify ${NUM_PATHS} distinct, viable approaches to the following problem. Each path should represent a different strategy or methodology.
+
+PROBLEM: ${PROMPT}
+
+Please identify ${NUM_PATHS} different solution paths. For each path, provide:
+1. A clear name/title for the approach
+2. A brief description of the strategy
+3. The key principles or methodology it follows
+
+Format your response as:
+PATH 1: [Name]
+[Description]
+
+PATH 2: [Name]
+[Description]
+
+etc.
+
+Ensure the paths are genuinely different approaches, not just variations of the same idea."
+
+paths_output=$(ollama run "${EXPLORATION_MODEL}" "${PATH_GENERATION_PROMPT}")
+
+echo "GENERATED PATHS:" >> "${SESSION_FILE}"
+echo "${paths_output}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Phase 2: Path Exploration ---
+echo "Phase 2: Exploring each path in detail..."
+echo "PHASE 2 - PATH EXPLORATION:" >> "${SESSION_FILE}"
+
+declare -a path_analyses
+declare -a path_names
+
+# Extract path names and explore each one
+for i in $(seq 1 "${NUM_PATHS}"); do
+    echo "  Exploring path ${i}..."
+    
+    # Extract the path description (simplified approach)
+    path_section=$(echo "${paths_output}" | sed -n "/PATH ${i}:/,/PATH $((i+1)):/p" | sed '$d')
+    if [ -z "$path_section" ]; then
+        path_section=$(echo "${paths_output}" | sed -n "/PATH ${i}:/,\$p")
+    fi
+    
+    # Generate path name from the section
+    path_name=$(echo "${path_section}" | head -n1 | sed 's/^PATH [0-9]*: //')
+    
+    EXPLORATION_PROMPT="You are a detailed analyst. Explore the following solution path in depth, considering its implications, requirements, and potential outcomes.
+
+ORIGINAL PROBLEM: ${PROMPT}
+
+PATH TO EXPLORE: ${path_section}
+
+Please provide a comprehensive analysis of this path including:
+1. Detailed implementation approach
+2. Potential benefits and advantages
+3. Potential challenges and risks
+4. Resource requirements and constraints
+5. Expected outcomes and timeline
+6. Success factors and critical elements
+7. Potential variations or adaptations
+
+Provide a thorough, well-structured analysis."
+
+    path_analysis=$(ollama run "${EXPLORATION_MODEL}" "${EXPLORATION_PROMPT}")
+    
+    path_analyses[$((i-1))]="${path_analysis}"
+    path_names[$((i-1))]="${path_name}"
+    
+    echo "PATH ${i} ANALYSIS (${path_name}):" >> "${SESSION_FILE}"
+    echo "${path_analysis}" >> "${SESSION_FILE}"
+    echo "" >> "${SESSION_FILE}"
+done
+
+# --- Phase 3: Comparative Analysis ---
+echo "Phase 3: Comparing and evaluating paths..."
+echo "PHASE 3 - COMPARATIVE ANALYSIS:" >> "${SESSION_FILE}"
+
+# Create comparison prompt
+COMPARISON_PROMPT="You are a strategic analyst. Compare and evaluate the following solution paths for the given problem.
+
+ORIGINAL PROBLEM: ${PROMPT}
+
+PATH ANALYSES:"
+
+for i in $(seq 0 $((NUM_PATHS-1))); do
+    COMPARISON_PROMPT="${COMPARISON_PROMPT}
+
+PATH ${i+1}: ${path_names[$i]}
+${path_analyses[$i]}"
+done
+
+COMPARISON_PROMPT="${COMPARISON_PROMPT}
+
+Please provide a comprehensive comparative analysis including:
+1. Direct comparison of approaches across key criteria
+2. Relative strengths and weaknesses of each path
+3. Trade-offs and opportunity costs
+4. Risk assessment for each approach
+5. Recommendations based on different scenarios
+6. Potential for combining elements from multiple paths
+7. Final recommendation with justification
+
+Provide a clear, structured comparison that helps decision-making."
+
+comparative_analysis=$(ollama run "${ANALYSIS_MODEL}" "${COMPARISON_PROMPT}")
+
+echo "COMPARATIVE ANALYSIS:" >> "${SESSION_FILE}"
+echo "${comparative_analysis}" >> "${SESSION_FILE}"
+
+# End timing
+duration=$(end_timer "$SESSION_ID" "exploration")
+
+# --- Final Output ---
+echo "---------------------------------"
+echo "Exploration process complete."
+echo "Comparative analysis:"
+echo "---------------------------------"
+
+echo "${comparative_analysis}"
+echo ""
+echo "Paths explored: ${NUM_PATHS}"
+echo "Execution time: ${duration} seconds"
+echo ""
+echo "Full exploration log: ${SESSION_FILE}" 
\ No newline at end of file
diff --git a/bash/logging.sh b/bash/logging.sh
new file mode 100755
index 0000000..c37aaf4
--- /dev/null
+++ b/bash/logging.sh
@@ -0,0 +1,146 @@
+#!/bin/bash
+
+# Unified Logging System
+# This script provides consistent logging and performance metrics across all thinking mechanisms.
+
+# --- Logging Configuration ---
+LOG_DIR=~/tmp/ai_thinking
+METRICS_FILE="${LOG_DIR}/performance_metrics.json"
+SESSION_LOG="${LOG_DIR}/session_$(date +%Y%m%d_%H%M%S).json"
+
+# Create logging directory
+mkdir -p "${LOG_DIR}"
+
+# --- Timing Functions ---
+start_timer() {
+    local session_id="$1"
+    local mechanism="$2"
+    local start_time=$(date +%s.%N)
+    
+    # Store start time
+    echo "$start_time" > "/tmp/${session_id}_start"
+    
+    # Log session start
+    log_session_start "$session_id" "$mechanism" "$start_time"
+}
+
+end_timer() {
+    local session_id="$1"
+    local mechanism="$2"
+    local end_time=$(date +%s.%N)
+    local start_time=$(cat "/tmp/${session_id}_start" 2>/dev/null || echo "$end_time")
+    
+    # Calculate duration
+    local duration=$(echo "$end_time - $start_time" | bc -l 2>/dev/null || echo "0")
+    
+    # Log session end
+    log_session_end "$session_id" "$mechanism" "$end_time" "$duration"
+    
+    # Clean up
+    rm -f "/tmp/${session_id}_start"
+    
+    echo "$duration"
+}
+
+# --- Session Logging ---
+log_session_start() {
+    local session_id="$1"
+    local mechanism="$2"
+    local start_time="$3"
+    
+    cat > "${SESSION_LOG}" << EOF
+{
+  "session_id": "${session_id}",
+  "mechanism": "${mechanism}",
+  "start_time": "${start_time}",
+  "prompt": "${PROMPT:-""}",
+  "status": "started"
+}
+EOF
+}
+
+log_session_end() {
+    local session_id="$1"
+    local mechanism="$2"
+    local end_time="$3"
+    local duration="$4"
+    
+    # Update session log
+    cat > "${SESSION_LOG}" << EOF
+{
+  "session_id": "${session_id}",
+  "mechanism": "${mechanism}",
+  "start_time": "$(cat "${SESSION_LOG}" | jq -r '.start_time' 2>/dev/null || echo "")",
+  "end_time": "${end_time}",
+  "duration": "${duration}",
+  "prompt": "${PROMPT:-""}",
+  "status": "completed"
+}
+EOF
+    
+    # Update metrics file
+    update_metrics "$mechanism" "$duration"
+}
+
+# --- Metrics Management ---
+update_metrics() {
+    local mechanism="$1"
+    local duration="$2"
+    
+    # Create metrics file if it doesn't exist
+    if [ ! -f "${METRICS_FILE}" ]; then
+        cat > "${METRICS_FILE}" << EOF
+{
+  "total_sessions": 0,
+  "mechanisms": {},
+  "average_durations": {}
+}
+EOF
+    fi
+    
+    # Update metrics using jq (if available) or simple text processing
+    if command -v jq >/dev/null 2>&1; then
+        # Use jq for proper JSON handling
+        local temp_file=$(mktemp)
+        jq --arg mechanism "$mechanism" --arg duration "$duration" '
+            .total_sessions += 1 |
+            .mechanisms[$mechanism] = (.mechanisms[$mechanism] // 0) + 1 |
+            .average_durations[$mechanism] = (
+                (.average_durations[$mechanism] // 0) * (.mechanisms[$mechanism] - 1) + ($duration | tonumber)
+            ) / .mechanisms[$mechanism]
+        ' "${METRICS_FILE}" > "$temp_file"
+        mv "$temp_file" "${METRICS_FILE}"
+    else
+        # Fallback: simple text-based metrics
+        echo "$(date +%Y%m%d_%H%M%S),${mechanism},${duration}" >> "${LOG_DIR}/simple_metrics.csv"
+    fi
+}
+
+# --- Utility Functions ---
+generate_session_id() {
+    echo "session_$(date +%Y%m%d_%H%M%S)_$$"
+}
+
+get_metrics_summary() {
+    if [ -f "${METRICS_FILE}" ]; then
+        echo "=== Performance Metrics ==="
+        if command -v jq >/dev/null 2>&1; then
+            jq -r '.mechanisms | to_entries[] | "\(.key): \(.value) sessions"' "${METRICS_FILE}"
+            echo ""
+            jq -r '.average_durations | to_entries[] | "\(.key): \(.value | tonumber | floor)s average"' "${METRICS_FILE}"
+        else
+            echo "Metrics available in: ${METRICS_FILE}"
+        fi
+    else
+        echo "No metrics available yet."
+    fi
+}
+
+# --- Export Functions for Other Scripts ---
+export -f start_timer
+export -f end_timer
+export -f log_session_start
+export -f log_session_end
+export -f update_metrics
+export -f generate_session_id
+export -f get_metrics_summary 
\ No newline at end of file
diff --git a/bash/metrics b/bash/metrics
new file mode 100755
index 0000000..ad430b5
--- /dev/null
+++ b/bash/metrics
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# Metrics Viewer
+# This script displays performance metrics from the unified logging system.
+
+# Source the logging system
+source ./logging.sh
+
+echo "AI Thinking System - Performance Metrics"
+echo "========================================"
+echo ""
+
+# Display metrics summary
+get_metrics_summary
+
+echo ""
+echo "Detailed metrics file: ${METRICS_FILE}"
+echo "Session logs directory: ${LOG_DIR}" 
\ No newline at end of file
diff --git a/bash/synthesis b/bash/synthesis
new file mode 100755
index 0000000..417279e
--- /dev/null
+++ b/bash/synthesis
@@ -0,0 +1,240 @@
+#!/bin/bash
+
+# Get the directory where this script is located
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Synthesis System
+# This script combines outputs from multiple thinking mechanisms into a coherent final response.
+#
+# APPLICATION LOGIC:
+# The synthesis process implements a multi-mechanism integration system that combines
+# outputs from different thinking strategies into a unified, coherent response. The system
+# operates through three distinct phases designed to maximize comprehensiveness and clarity:
+#
+# PHASE 1 - MECHANISM EXECUTION:
+#   - Executes multiple thinking mechanisms on the same prompt
+#   - Collects diverse perspectives and approaches
+#   - Ensures comprehensive coverage of the problem space
+#   - Creates a foundation for synthesis
+#
+# PHASE 2 - CONFLICT RESOLUTION:
+#   - Identifies contradictions and conflicts between mechanism outputs
+#   - Resolves disagreements through logical analysis
+#   - Prioritizes information based on confidence and relevance
+#   - Maintains intellectual honesty about uncertainties
+#
+# PHASE 3 - SYNTHESIS GENERATION:
+#   - Combines the best elements from each mechanism
+#   - Creates a coherent narrative that addresses all aspects
+#   - Provides a unified response that leverages multiple perspectives
+#   - Ensures the final output is greater than the sum of its parts
+#
+# SYNTHESIS MODELING:
+# The system applies integrative thinking principles to AI response generation:
+#   - Multiple mechanisms provide diverse perspectives on the same problem
+#   - Conflict resolution ensures logical consistency in the final output
+#   - Synthesis leverages the strengths of each individual mechanism
+#   - The process may reveal insights that individual mechanisms miss
+#   - Transparency shows how different perspectives were integrated
+#   - The method may provide more comprehensive and balanced responses
+#
+# The synthesis process emphasizes comprehensiveness and coherence,
+# ensuring users get the benefits of multiple thinking approaches in a unified response.
+
+# Source the logging system using absolute path
+source "${SCRIPT_DIR}/logging.sh"
+
+# --- Model Configuration ---
+SYNTHESIS_MODEL="llama3:8b-instruct-q4_K_M"
+
+# --- Defaults ---
+DEFAULT_MECHANISMS=("consensus" "critique" "socratic")
+
+# --- Argument Validation ---
+if [ "$#" -lt 1 ]; then
+    echo -e "\n\tSynthesis"
+    echo -e "\tThis script combines outputs from multiple thinking mechanisms into a coherent final response."
+    echo -e "\n\tUsage: $0 [-f <file_path>] [-m <mechanism1,mechanism2,...>] \"<your prompt>\" [number_of_rounds]"
+    echo -e "\n\tExample: $0 -f ./input.txt -m consensus,critique \"Please analyze this text\" 2"
+    echo -e "\n\tIf number_of_rounds is not provided, the program will default to 2 rounds."
+    echo -e "\n\t-f <file_path> (optional): Append the contents of the file to the prompt."
+    echo -e "\n\t-m <mechanisms> (optional): Comma-separated list of mechanisms to use (default: consensus,critique,socratic)."
+    echo -e "\n"
+    exit 1
+fi
+
+# --- Argument Parsing ---
+FILE_PATH=""
+MECHANISMS_STR=""
+while getopts "f:m:" opt; do
+  case $opt in
+    f)
+      FILE_PATH="$OPTARG"
+      ;;
+    m)
+      MECHANISMS_STR="$OPTARG"
+      ;;
+    *)
+      echo "Invalid option: -$OPTARG" >&2
+      exit 1
+      ;;
+  esac
+done
+shift $((OPTIND -1))
+
+PROMPT="$1"
+if [ -z "$2" ]; then
+    ROUNDS=2
+else
+    ROUNDS=$2
+fi
+
+# Parse mechanisms
+if [ -n "$MECHANISMS_STR" ]; then
+    IFS=',' read -ra MECHANISMS <<< "$MECHANISMS_STR"
+else
+    MECHANISMS=("${DEFAULT_MECHANISMS[@]}")
+fi
+
+# If file path is provided, append its contents to the prompt
+if [ -n "$FILE_PATH" ]; then
+    if [ ! -f "$FILE_PATH" ]; then
+        echo "File not found: $FILE_PATH" >&2
+        exit 1
+    fi
+    FILE_CONTENTS=$(cat "$FILE_PATH")
+    PROMPT="$PROMPT\n[FILE CONTENTS]\n$FILE_CONTENTS\n[END FILE]"
+fi
+
+# --- File Initialization ---
+mkdir -p ~/tmp
+SESSION_FILE=~/tmp/synthesis_$(date +%Y%m%d_%H%M%S).txt
+
+# Initialize timing
+SESSION_ID=$(generate_session_id)
+start_timer "$SESSION_ID" "synthesis"
+
+echo "Synthesis Session Log: ${SESSION_FILE}"
+echo "---------------------------------"
+
+# Store the initial user prompt in the session file
+echo "USER PROMPT: ${PROMPT}" >> "${SESSION_FILE}"
+echo "MECHANISMS: ${MECHANISMS[*]}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Phase 1: Mechanism Execution ---
+echo "Phase 1: Executing thinking mechanisms..."
+echo "PHASE 1 - MECHANISM EXECUTION:" >> "${SESSION_FILE}"
+
+declare -a mechanism_outputs
+declare -a mechanism_names
+
+for i in "${!MECHANISMS[@]}"; do
+    mechanism="${MECHANISMS[$i]}"
+    echo "  Executing ${mechanism} mechanism..."
+    
+    # Execute the mechanism using absolute path
+    if [ -f "${SCRIPT_DIR}/${mechanism}" ]; then
+        output=$("${SCRIPT_DIR}/${mechanism}" "${PROMPT}" "${ROUNDS}" 2>&1)
+        mechanism_outputs[$i]="${output}"
+        mechanism_names[$i]="${mechanism}"
+        
+        echo "MECHANISM ${i+1} (${mechanism}):" >> "${SESSION_FILE}"
+        echo "${output}" >> "${SESSION_FILE}"
+        echo "" >> "${SESSION_FILE}"
+    else
+        echo "  WARNING: Mechanism ${mechanism} not found, skipping..." >&2
+    fi
+done
+
+# --- Phase 2: Conflict Resolution ---
+echo "Phase 2: Analyzing and resolving conflicts..."
+echo "PHASE 2 - CONFLICT RESOLUTION:" >> "${SESSION_FILE}"
+
+# Create conflict analysis prompt
+CONFLICT_PROMPT="You are a conflict resolution specialist. Analyze the following outputs from different thinking mechanisms and identify any contradictions, conflicts, or areas of disagreement.
+
+ORIGINAL PROMPT: ${PROMPT}
+
+MECHANISM OUTPUTS:"
+
+for i in "${!MECHANISMS[@]}"; do
+    if [ -n "${mechanism_outputs[$i]}" ]; then
+        CONFLICT_PROMPT="${CONFLICT_PROMPT}
+
+${mechanism_names[$i]} OUTPUT:
+${mechanism_outputs[$i]}"
+    fi
+done
+
+CONFLICT_PROMPT="${CONFLICT_PROMPT}
+
+Please identify:
+1. Any direct contradictions between the outputs
+2. Areas where the mechanisms disagree
+3. Information that appears to be conflicting
+4. How these conflicts might be resolved
+
+Provide a clear analysis of conflicts and potential resolutions."
+
+conflict_analysis=$(ollama run "${SYNTHESIS_MODEL}" "${CONFLICT_PROMPT}")
+
+echo "CONFLICT ANALYSIS:" >> "${SESSION_FILE}"
+echo "${conflict_analysis}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Phase 3: Synthesis Generation ---
+echo "Phase 3: Generating unified synthesis..."
+echo "PHASE 3 - SYNTHESIS GENERATION:" >> "${SESSION_FILE}"
+
+# Create synthesis prompt
+SYNTHESIS_PROMPT="You are a synthesis specialist. Your task is to combine the outputs from multiple thinking mechanisms into a coherent, unified response that leverages the strengths of each approach.
+
+ORIGINAL PROMPT: ${PROMPT}
+
+MECHANISM OUTPUTS:"
+
+for i in "${!MECHANISMS[@]}"; do
+    if [ -n "${mechanism_outputs[$i]}" ]; then
+        SYNTHESIS_PROMPT="${SYNTHESIS_PROMPT}
+
+${mechanism_names[$i]} OUTPUT:
+${mechanism_outputs[$i]}"
+    fi
+done
+
+SYNTHESIS_PROMPT="${SYNTHESIS_PROMPT}
+
+CONFLICT ANALYSIS:
+${conflict_analysis}
+
+Please create a unified synthesis that:
+1. Combines the best insights from each mechanism
+2. Resolves any identified conflicts logically
+3. Provides a comprehensive response that addresses all aspects
+4. Maintains intellectual honesty about uncertainties
+5. Creates a coherent narrative that flows naturally
+6. Leverages the unique strengths of each thinking approach
+
+Your synthesis should be greater than the sum of its parts - it should provide insights that individual mechanisms might miss."
+
+final_synthesis=$(ollama run "${SYNTHESIS_MODEL}" "${SYNTHESIS_PROMPT}")
+
+echo "FINAL SYNTHESIS:" >> "${SESSION_FILE}"
+echo "${final_synthesis}" >> "${SESSION_FILE}"
+
+# End timing
+duration=$(end_timer "$SESSION_ID" "synthesis")
+
+# --- Final Output ---
+echo "---------------------------------"
+echo "Synthesis process complete."
+echo "Final unified response:"
+echo "---------------------------------"
+
+echo "${final_synthesis}"
+echo ""
+echo "Mechanisms used: ${MECHANISMS[*]}"
+echo "Execution time: ${duration} seconds"
+echo ""
+echo "Full synthesis log: ${SESSION_FILE}" 
\ No newline at end of file