#!/usr/bin/env python3
import sys
import subprocess
import argparse
import json

# Mandated model for Deep Think tasks
DEEP_THINK_MODEL = "gemini-3-flash-preview"

def invoke_deep_think(prompt, output_file=None):
    """
    Invokes the reasoning capability using the mandated Gemini 3 model.
    Since the --thinking flag is a CLI-level abstraction, we ensure
    the model used is the most advanced for the task.
    """
    print(f"[*] Invoking Genesis Deep Think Skill (Model: {DEEP_THINK_MODEL})")
    print(f"[*] Prompt: {prompt[:100]}...")
    
    # We wrap the prompt in a 'thinking' directive to activate internal reasoning
    reasoning_prompt = f"Please perform deep thinking and complex reasoning on the following task. Think through step-by-step before providing the final answer.\n\nTASK: {prompt}"
    
    cmd = ["gemini", "--model", DEEP_THINK_MODEL, "--prompt", reasoning_prompt]
    
    try:
        result = subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
        
        if output_file:
            with open(output_file, 'w') as f:
                f.write(result)
            print(f"[+] Result saved to {output_file}")
            
        return result
    except subprocess.CalledProcessError as e:
        print(f"[!] Error invoking Deep Think: {e.output}")
        return None

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Genesis Deep Think Skill")
    parser.add_argument("--prompt", required=True, help="The prompt to analyze with deep thinking")
    parser.add_argument("--output", help="Optional output file for the result")
    
    args = parser.parse_args()
    
    res = invoke_deep_think(args.prompt, args.output)
    if res:
        print("\n=== DEEP THINK RESULT ===\n")
        print(res)
