aboutsummaryrefslogtreecommitdiffstats
path: root/bash
diff options
context:
space:
mode:
authorelioat <{ID}+{username}@users.noreply.github.com>2025-08-20 12:24:56 -0400
committerelioat <{ID}+{username}@users.noreply.github.com>2025-08-20 12:24:56 -0400
commit93e85ad4bbf23cc8754302b5194a4ae04d911a82 (patch)
tree51ae684e8d764a997364423170ea13484a4d2a08 /bash
parent0929844d28e7d8e72e0138813b1ba9b05bfaf867 (diff)
downloadtour-93e85ad4bbf23cc8754302b5194a4ae04d911a82.tar.gz
*
Diffstat (limited to 'bash')
-rw-r--r--bash/talk-to-computer/README.md36
-rwxr-xr-xbash/talk-to-computer/classifier.sh16
-rwxr-xr-xbash/talk-to-computer/computer11
-rwxr-xr-xbash/talk-to-computer/puzzle336
4 files changed, 397 insertions, 2 deletions
diff --git a/bash/talk-to-computer/README.md b/bash/talk-to-computer/README.md
index e0b4cb3..0d2603a 100644
--- a/bash/talk-to-computer/README.md
+++ b/bash/talk-to-computer/README.md
@@ -36,7 +36,7 @@ User Prompt → Computer (Dispatcher) → Advanced Classifier → Specialized Me
1. Clone or download the scripts to your desired directory
2. Ensure all scripts have execute permissions:
```bash
- chmod +x computer exploration consensus socratic critique peer-review synthesis
+ chmod +x computer exploration consensus socratic critique peer-review synthesis puzzle
chmod +x logging.sh classifier.sh
```
3. Verify Ollama is running and accessible:
@@ -69,6 +69,7 @@ The system now uses a sophisticated **three-layer classification approach**:
#### **Layer 1: Intent Pattern Analysis**
- **Question type detection**: what/when/where → DIRECT, why/how → SOCRATIC
- **Action-oriented patterns**: improve → CRITIQUE, compare → EXPLORATION
+- **Puzzle & coding patterns**: algorithm/implement → PUZZLE, challenge/problem → PUZZLE
- **Context-aware scoring**: strategy/planning → EXPLORATION, analysis → SOCRATIC
- **Weighted scoring system** with priority handling
@@ -113,6 +114,10 @@ Output: SOCRATIC:0.85 (correctly identifies deep questioning need)
# Simple Question (Complexity Override)
Input: "What is 2+2?"
Output: DIRECT:0.8 (low complexity override)
+
+# Algorithm Challenge (High Confidence)
+Input: "How can I implement a binary search algorithm?"
+Output: PUZZLE:1.00 (correctly identifies coding challenge need)
```
## Thinking Mechanisms
@@ -192,6 +197,27 @@ Output: DIRECT:0.8 (low complexity override)
- **Phase 2**: Integration analysis
- **Phase 3**: Unified solution creation
+### 7. **Puzzle** - Problem Solving & Coding
+**Best for**: Algorithm challenges, coding problems, puzzle solving, programming education
+
+```bash
+./puzzle "How can I implement a sorting algorithm?"
+./puzzle -l python "What's the best way to solve this data structure problem?"
+```
+
+**Process**:
+- **Phase 1**: Problem analysis and classification
+- **Phase 2**: Solution strategy development
+- **Phase 3**: Implementation guidance with code examples
+- **Phase 4**: Solution validation and testing
+
+**Special Features**:
+- **Built-in Lil language expertise** for RAG-like context
+- **Algorithmic complexity analysis** and optimization tips
+- **Multiple solution approaches** with trade-off analysis
+- **Language-specific code examples** and best practices
+- **Testing and debugging guidance** for robust solutions
+
## Configuration
### Model Selection
@@ -447,6 +473,14 @@ The modular architecture makes it easy to:
./socratic "What are the root causes of our deployment failures?"
```
+### Algorithm & Coding Challenges
+
+```bash
+# The system automatically routes to puzzle mechanism
+./computer "How can I implement a binary search algorithm?"
+./puzzle "What's the most efficient way to sort this data structure?"
+```
+
### Complex Classification
```bash
diff --git a/bash/talk-to-computer/classifier.sh b/bash/talk-to-computer/classifier.sh
index 3dfb69d..157673e 100755
--- a/bash/talk-to-computer/classifier.sh
+++ b/bash/talk-to-computer/classifier.sh
@@ -49,6 +49,7 @@ analyze_intent_patterns() {
local socratic_score=0
local critique_score=0
local peer_review_score=0
+ local puzzle_score=0
# Question type patterns
if [[ "$prompt" =~ ^(what|when|where|who|which|how\ much|how\ many) ]]; then
@@ -89,6 +90,15 @@ analyze_intent_patterns() {
socratic_score=$((socratic_score + 2))
fi
+ # Puzzle and coding patterns
+ if [[ "$prompt" =~ (puzzle|solve|algorithm|code|programming|implement|sort|search|optimize|data.*structure) ]]; then
+ puzzle_score=$((puzzle_score + 3))
+ fi
+
+ if [[ "$prompt" =~ (challenge|problem|question|task|assignment|exercise) ]]; then
+ puzzle_score=$((puzzle_score + 2))
+ fi
+
# Find highest scoring mechanism
local max_score=0
local best_mechanism="DIRECT"
@@ -121,9 +131,13 @@ analyze_intent_patterns() {
max_score="$peer_review_score"
best_mechanism="PEER_REVIEW"
fi
+ if [ "$puzzle_score" -gt "$max_score" ]; then
+ max_score="$puzzle_score"
+ best_mechanism="PUZZLE"
+ fi
# Calculate confidence based on score distribution
- local total_score=$((direct_score + consensus_score + synthesis_score + exploration_score + socratic_score + critique_score + peer_review_score))
+ local total_score=$((direct_score + consensus_score + synthesis_score + exploration_score + socratic_score + critique_score + peer_review_score + puzzle_score))
local confidence="0.0"
if [ "$total_score" -gt 0 ]; then
diff --git a/bash/talk-to-computer/computer b/bash/talk-to-computer/computer
index 1999d7d..b1e5aa5 100755
--- a/bash/talk-to-computer/computer
+++ b/bash/talk-to-computer/computer
@@ -251,6 +251,9 @@ else
"PEER_REVIEW")
REASON="Collaborative review or feedback needed (confidence: $CONFIDENCE)"
;;
+ "PUZZLE")
+ REASON="Puzzle solving or coding challenge (confidence: $CONFIDENCE)"
+ ;;
*)
REASON="Default fallback (confidence: $CONFIDENCE)"
MECHANISM="DIRECT"
@@ -341,6 +344,14 @@ case "$MECHANISM" in
# Execute exploration script and display output directly
"${SCRIPT_DIR}/exploration" "${PROMPT}" "${ROUNDS}" 2>&1 | tee -a "${SESSION_FILE}"
;;
+
+ "PUZZLE")
+ echo "Delegating to puzzle mechanism..."
+ echo "DELEGATING TO PUZZLE:" >> "${SESSION_FILE}"
+
+ # Execute puzzle script and display output directly
+ "${SCRIPT_DIR}/puzzle" "${PROMPT}" "${ROUNDS}" 2>&1 | tee -a "${SESSION_FILE}"
+ ;;
esac
# --- Final Summary ---
diff --git a/bash/talk-to-computer/puzzle b/bash/talk-to-computer/puzzle
new file mode 100755
index 0000000..9f0ec9c
--- /dev/null
+++ b/bash/talk-to-computer/puzzle
@@ -0,0 +1,336 @@
+#!/bin/bash
+
+# Get the directory where this script is located
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Puzzle System
+# This script specializes in puzzle solving and coding challenges with Lil programming language expertise.
+#
+# APPLICATION LOGIC:
+# The puzzle process implements a systematic problem-solving approach that combines
+# algorithmic thinking, code analysis, and domain-specific knowledge. The system operates
+# through four distinct phases designed to maximize puzzle-solving effectiveness:
+#
+# PHASE 1 - PROBLEM ANALYSIS:
+# - Analyzes the puzzle or coding challenge
+# - Identifies problem type and complexity
+# - Determines appropriate solution strategies
+# - Provides Lil language context when relevant
+#
+# PHASE 2 - SOLUTION STRATEGY:
+# - Develops multiple solution approaches
+# - Considers algorithmic complexity and trade-offs
+# - Provides Lil-specific implementation guidance
+# - Suggests testing and validation strategies
+#
+# PHASE 3 - IMPLEMENTATION GUIDANCE:
+# - Provides detailed code examples in Lil
+# - Explains key concepts and patterns
+# - Suggests optimizations and improvements
+# - Offers debugging and troubleshooting tips
+#
+# PHASE 4 - SOLUTION VALIDATION:
+# - Reviews the proposed solution
+# - Identifies potential edge cases
+# - Suggests testing scenarios
+# - Provides alternative approaches if applicable
+#
+# PUZZLE MODELING:
+# The system applies systematic problem-solving principles to coding challenges:
+# - Algorithmic thinking ensures optimal solutions
+# - Lil language expertise provides domain-specific guidance
+# - Multiple solution approaches reveal different perspectives
+# - Systematic validation reduces errors and improves code quality
+#
+# The puzzle process emphasizes systematic analysis and practical implementation,
+# ensuring users understand both the problem-solving approach and the Lil language specifics.
+
+# Source the logging system using absolute path
+source "${SCRIPT_DIR}/logging.sh"
+
+# --- Model Configuration ---
+PUZZLE_MODEL="llama3:8b-instruct-q4_K_M"
+ANALYSIS_MODEL="phi3:3.8b-mini-4k-instruct-q4_K_M"
+
+# Validate and set models with fallbacks
+PUZZLE_MODEL=$(validate_model "$PUZZLE_MODEL" "gemma3n:e2b")
+if [ $? -ne 0 ]; then
+ log_error "No valid puzzle model available"
+ exit 1
+fi
+
+ANALYSIS_MODEL=$(validate_model "$ANALYSIS_MODEL" "gemma3n:e2b")
+if [ $? -ne 0 ]; then
+ log_error "No valid analysis model available"
+ exit 1
+fi
+
+# --- Defaults ---
+DEFAULT_ROUNDS=2
+
+# --- Argument Validation ---
+if [ "$#" -lt 1 ]; then
+ echo -e "\n\tPuzzle"
+ echo -e "\tThis script specializes in puzzle solving and coding challenges with Lil programming language expertise."
+ echo -e "\n\tUsage: $0 [-f <file_path>] [-l <language>] \"<your puzzle/challenge>\" [number_of_rounds]"
+ echo -e "\n\tExample: $0 -f ./challenge.txt -l lil \"How can I implement a sorting algorithm?\" 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-l <language> (optional): Specify programming language focus (default: lil)."
+ echo -e "\n"
+ exit 1
+fi
+
+# --- Argument Parsing ---
+FILE_PATH=""
+LANGUAGE="lil"
+while getopts "f:l:" opt; do
+ case $opt in
+ f)
+ FILE_PATH="$OPTARG"
+ ;;
+ l)
+ LANGUAGE="$OPTARG"
+ ;;
+ *)
+ log_error "Invalid option: -$OPTARG"
+ exit 1
+ ;;
+ esac
+done
+shift $((OPTIND -1))
+
+PROMPT="$1"
+if [ -z "$2" ]; then
+ ROUNDS=2
+else
+ ROUNDS=$2
+fi
+
+# Validate prompt
+PROMPT=$(validate_prompt "$PROMPT")
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+# Validate file path if provided
+if [ -n "$FILE_PATH" ]; then
+ if ! validate_file_path "$FILE_PATH"; then
+ exit 1
+ fi
+ FILE_CONTENTS=$(cat "$FILE_PATH")
+ PROMPT="$PROMPT\n[FILE CONTENTS]\n$FILE_CONTENTS\n[END FILE]"
+fi
+
+# Validate rounds
+if ! [[ "$ROUNDS" =~ ^[1-9][0-9]*$ ]] || [ "$ROUNDS" -gt 5 ]; then
+ log_error "Invalid number of rounds: $ROUNDS (must be 1-5)"
+ exit 1
+fi
+
+# --- File Initialization ---
+mkdir -p ~/tmp
+SESSION_FILE=~/tmp/puzzle_$(date +%Y%m%d_%H%M%S).txt
+
+# Initialize timing
+SESSION_ID=$(generate_session_id)
+start_timer "$SESSION_ID" "puzzle"
+
+echo "Puzzle Session Log: ${SESSION_FILE}"
+echo "---------------------------------"
+
+# Store the initial user prompt in the session file
+echo "USER PROMPT: ${PROMPT}" >> "${SESSION_FILE}"
+echo "LANGUAGE FOCUS: ${LANGUAGE}" >> "${SESSION_FILE}"
+echo "NUMBER OF ROUNDS: ${ROUNDS}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Lil Language Knowledge Base ---
+LIL_KNOWLEDGE="LIL PROGRAMMING LANGUAGE KNOWLEDGE BASE:
+
+Lil is a scripting language designed for Decker, a multimedia creative tool. Key features:
+
+DATA TYPES:
+- Numbers: 42, 37.5, -29999 (floating-point)
+- Strings: \"apple\", \"foo\\nbar\" (with escape sequences)
+- Lists: (), (1,2,3), list 42
+- Dictionaries: dict, key-value pairs
+- Tables: rectangular arrays with string keys
+- Functions: declared with 'on'
+- nil: represents absence of value
+
+CORE SYNTAX:
+- Assignment: x:42
+- Function calls: function[arg1 arg2]
+- Comments: # line comment
+- Function definition: on name do ... end
+- Conditionals: if condition ... else ... end
+- Loops: each x in list do ... end, while condition do ... end
+
+OPERATORS:
+- Arithmetic: +, -, *, /, %, ^
+- Comparison: =, <, > (no !=, <=, >=)
+- Logical: & (AND), | (OR), ! (NOT)
+- List operations: , (join), take, drop
+- String operations: fuse (concatenate), split
+- Table operations: join, cross
+
+QUERY SYNTAX:
+- select/extract/update with where/by/orderby clauses
+- Example: first extract key orderby value desc from dict
+
+COMMON PATTERNS:
+- Dictionary iteration: each k in keys dict do ... end
+- List processing: each x in list do ... end
+- Table manipulation: rows table, cols table
+- Error handling: x unless y (nil-coalescing)
+- Set operations using dictionaries
+
+UNIQUE FEATURES:
+- Right-to-left operator precedence
+- Soft type system with automatic conversions
+- Query language for data manipulation
+- Vector-oriented operations
+- Built-in table operations"
+
+# --- Phase 1: Problem Analysis ---
+echo "Phase 1: Analyzing the puzzle or coding challenge..."
+echo "PHASE 1 - PROBLEM ANALYSIS:" >> "${SESSION_FILE}"
+
+PROBLEM_ANALYSIS_PROMPT="You are an expert puzzle solver and programming mentor specializing in the ${LANGUAGE} programming language. Analyze the following puzzle or coding challenge.
+
+${LIL_KNOWLEDGE}
+
+CHALLENGE: ${PROMPT}
+
+Please provide a comprehensive analysis including:
+1. Problem type classification (algorithm, data structure, logic, etc.)
+2. Complexity assessment (time/space requirements)
+3. Key concepts and patterns involved
+4. Relevant ${LANGUAGE} language features that could help
+5. Potential solution approaches
+6. Common pitfalls or edge cases to consider
+
+Provide a clear, structured analysis that helps understand the problem."
+
+problem_analysis=$(ollama run "${PUZZLE_MODEL}" "${PROBLEM_ANALYSIS_PROMPT}")
+
+echo "PROBLEM ANALYSIS:" >> "${SESSION_FILE}"
+echo "${problem_analysis}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Phase 2: Solution Strategy ---
+echo "Phase 2: Developing solution strategies..."
+echo "PHASE 2 - SOLUTION STRATEGY:" >> "${SESSION_FILE}"
+
+SOLUTION_STRATEGY_PROMPT="Based on the problem analysis, develop multiple solution strategies for this puzzle or coding challenge.
+
+${LIL_KNOWLEDGE}
+
+ORIGINAL CHALLENGE: ${PROMPT}
+
+PROBLEM ANALYSIS: ${problem_analysis}
+
+Please provide:
+1. At least 2-3 different solution approaches
+2. Algorithmic complexity analysis for each approach
+3. Trade-offs between different solutions
+4. Specific ${LANGUAGE} language constructs that would be useful
+5. Implementation considerations and challenges
+6. Testing and validation strategies
+
+Focus on practical, implementable solutions with clear reasoning."
+
+solution_strategy=$(ollama run "${PUZZLE_MODEL}" "${SOLUTION_STRATEGY_PROMPT}")
+
+echo "SOLUTION STRATEGY:" >> "${SESSION_FILE}"
+echo "${solution_strategy}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Phase 3: Implementation Guidance ---
+echo "Phase 3: Providing implementation guidance..."
+echo "PHASE 3 - IMPLEMENTATION GUIDANCE:" >> "${SESSION_FILE}"
+
+IMPLEMENTATION_PROMPT="Provide detailed implementation guidance for the best solution approach to this puzzle or coding challenge.
+
+${LIL_KNOWLEDGE}
+
+ORIGINAL CHALLENGE: ${PROMPT}
+PROBLEM ANALYSIS: ${problem_analysis}
+SOLUTION STRATEGY: ${solution_strategy}
+
+Please provide:
+1. Step-by-step implementation plan
+2. Complete code example in ${LANGUAGE} (if applicable)
+3. Explanation of key code sections and patterns
+4. Variable naming and structure recommendations
+5. Error handling and edge case considerations
+6. Performance optimization tips
+7. Testing and debugging guidance
+
+Make the implementation clear and educational, explaining the reasoning behind each decision."
+
+implementation_guidance=$(ollama run "${PUZZLE_MODEL}" "${IMPLEMENTATION_PROMPT}")
+
+echo "IMPLEMENTATION GUIDANCE:" >> "${SESSION_FILE}"
+echo "${implementation_guidance}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Phase 4: Solution Validation ---
+echo "Phase 4: Validating and reviewing the solution..."
+echo "PHASE 4 - SOLUTION VALIDATION:" >> "${SESSION_FILE}"
+
+VALIDATION_PROMPT="Review and validate the proposed solution to ensure it's correct, efficient, and well-implemented.
+
+${LIL_KNOWLEDGE}
+
+ORIGINAL CHALLENGE: ${PROMPT}
+PROBLEM ANALYSIS: ${problem_analysis}
+SOLUTION STRATEGY: ${solution_strategy}
+IMPLEMENTATION: ${implementation_guidance}
+
+Please provide:
+1. Code review and correctness verification
+2. Edge case analysis and testing scenarios
+3. Performance analysis and optimization opportunities
+4. Alternative approaches or improvements
+5. Common mistakes to avoid
+6. Learning resources and next steps
+7. Final recommendations and best practices
+
+Ensure the solution is robust, maintainable, and follows ${LANGUAGE} best practices."
+
+solution_validation=$(ollama run "${ANALYSIS_MODEL}" "${VALIDATION_PROMPT}")
+
+echo "SOLUTION VALIDATION:" >> "${SESSION_FILE}"
+echo "${solution_validation}" >> "${SESSION_FILE}"
+
+# End timing
+duration=$(end_timer "$SESSION_ID" "puzzle")
+
+# --- Final Output ---
+echo "---------------------------------"
+echo "Puzzle-solving process complete."
+echo "---------------------------------"
+echo ""
+echo "PROBLEM ANALYSIS:"
+echo "================="
+echo "${problem_analysis}"
+echo ""
+echo "SOLUTION STRATEGY:"
+echo "=================="
+echo "${solution_strategy}"
+echo ""
+echo "IMPLEMENTATION GUIDANCE:"
+echo "========================"
+echo "${implementation_guidance}"
+echo ""
+echo "SOLUTION VALIDATION:"
+echo "===================="
+echo "${solution_validation}"
+echo ""
+echo "Language focus: ${LANGUAGE}"
+echo "Rounds completed: ${ROUNDS}"
+echo "Execution time: ${duration} seconds"
+echo ""
+echo "Full puzzle-solving log: ${SESSION_FILE}"