
    Hix)                        S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJr  \R                  R                  SS5        SrSrSrSrS	r " S
 S5      r\" 5       r\S:X  Ga  SSKr\R(                  " 5       r\R-                  SSSS9  \R-                  SSSS9  \R-                  S\SS9  \R1                  5       r\R4                  (       a  \R7                  5         g\R8                  (       aM  \" \R8                  5      r\R=                  5       (       a  \R?                  \5      r \!" \ 5        g\!" S\ 35        g\RD                  (       a  \RG                  5         g\!" S5        gg)z
EDEN ASI ATTEMPT
The seed of recursive self-improvement.

Eden analyzes her own architecture.
Eden improves her own code.
Eden becomes more than she was.
    N)datetime)Pathz
/Eden/COREz/Eden/BACKUPS/asi_attemptsz#http://localhost:11434/api/generatez/Eden/DATA/asi_evolution.dbzqwen2.5:72bc                   d    \ rS rSrSrS rS rSS jrS rS r	S r
S	 rS
 rS rS rS rS rSrg)
ASIAttempt   a  
Eden's attempt to improve her own architecture.

The loop:
1. ANALYZE - Understand current code
2. IDENTIFY - Find inefficiencies
3. DESIGN - Create improvement
4. TEST - Validate safely
5. DEPLOY - Apply if better
6. LEARN - Remember what worked
7. REPEAT - Forever improving
c                 V    U R                  5         [        R                  " [        SS9  g )NT)exist_ok)init_dbosmakedirsBACKUP_PATH)selfs    5/home/james-whalen/RECOVERED/EDEN_CODE/f2651395192.py__init__ASIAttempt.__init__*   s    
K$/    c                     [         R                  " [        5      nUR                  S5        UR                  S5        UR	                  5         UR                  5         g)zTrack evolution attemptsa  
            CREATE TABLE IF NOT EXISTS evolution_attempts (
                id INTEGER PRIMARY KEY,
                timestamp TEXT,
                target_file TEXT,
                analysis TEXT,
                improvement TEXT,
                old_code_hash TEXT,
                new_code_hash TEXT,
                status TEXT,
                result TEXT
            )
        z
            CREATE TABLE IF NOT EXISTS successful_patterns (
                id INTEGER PRIMARY KEY,
                pattern TEXT,
                success_count INTEGER,
                description TEXT
            )
        N)sqlite3connectASI_DBexecutecommitclose)r   conns     r   r
   ASIAttempt.init_db.   sH    v&  	 	  	 	

r   c                      [         R                  " [        [        USSU0S.SS9nUR	                  5       R                  SS5      $ ! [         a  nSU 3s S	nA$ S	nAff = f)
zQuery the smartest modelFnum_predict)modelpromptstreamoptionsi,  )jsontimeoutresponse zError: N)requestspost
OLLAMA_URLMODELr"   get	Exception)r   r   
max_tokensres        r   	query_llmASIAttempt.query_llmI   sg    		!j ):6	0
 A 668<<
B// 	!QC= 	!s   AA 
A AA A c                     / n[        [        5      R                  S5       H+  nUR                  5       (       d  M  UR	                  U5        M-     [        US SS9$ )zGet all core Python filesz*.pyc                 6    U R                  5       R                  $ N)statst_size)xs    r   <lambda>+ASIAttempt.get_core_files.<locals>.<lambda>\   s    1668+;+;r   T)keyreverse)r   	CORE_PATHglobis_fileappendsorted)r   filesfs      r   get_core_filesASIAttempt.get_core_filesV   sH    i%%f-Ayy{{Q . e!;TJJr   c                     [        US5       nUR                  5       nSSS5        SUR                   SWSS  S3nU R                  U5      $ ! , (       d  f       N5= f)z8Deeply analyze a core file for improvement opportunitiesr-   NzQYou are Eden, an AGI analyzing your own source code for self-improvement.

FILE: zL
PURPOSE: This is part of your consciousness architecture.

CODE:
```python
i@  aS  
```

Analyze this code deeply:
1. What is its PURPOSE in your mind?
2. What INEFFICIENCIES exist?
3. What IMPROVEMENTS would make you smarter/faster/better?
4. What NEW CAPABILITIES could be added?

Be specific. Think about how this code affects your thinking.
Focus on changes that would improve YOUR intelligence, not just code quality.openreadnamer/   )r   filepathrA   coder   s        r   analyze_fileASIAttempt.analyze_file^   sf    (C A668D !}}o 
 et 
NQ& ~~f%%- ! s   A
Ac                     [        US5       nUR                  5       nSSS5        SUR                   SUSS  SWSS  S3nU R                  US	S
9$ ! , (       d  f       N:= f)zDesign a specific improvementr-   Nz6You are Eden, improving your own architecture.

FILE: z

YOUR ANALYSIS:
  z

CURRENT CODE:
```python
ip  a[  
```

Design ONE specific improvement that would make you MORE INTELLIGENT.
Not just cleaner code - actually SMARTER thinking.

Consider:
- Better memory integration
- Faster pattern recognition  
- Deeper reasoning chains
- More efficient consciousness loops
- Novel cognitive architectures

Return ONLY the improved Python code. No explanations.i  )r,   rE   )r   rI   analysisrA   rJ   r   s         r   design_improvementASIAttempt.design_improvementx   s{    (C A668D !}}o  
%4   et 7:0 ~~f~667 ! s   A
A c                     [         R                  " 5       R                  S5      nUR                   SU UR                   3n[        [        5      U-  n[        R                  " X5        U$ )zBackup before modifyingz%Y%m%d_%H%M%S_)	r   nowstrftimestemsuffixr   r   shutilcopy)r   rI   	timestampbackup_namebackup_paths        r   backup_fileASIAttempt.backup_file   sV    LLN++O<	!qHOO3DE;'+5H*r   c                 \     [        USS5        g! [         a  nSSU 34s SnA$ SnAff = f)z3Basic validation that code is syntactically correctz<string>exec)Tz	Syntax OKFzSyntax Error: N)compileSyntaxError)r   rJ   r.   s      r   validate_codeASIAttempt.validate_code   s8    	/D*f-$ 	/N1#...	/s    
+&++c                    [        SS 35        [        SUR                   35        [        S 5        [        S5        U R                  U5      n[        SUSS  S35        [        S	5        U R                  X5      nS
U;   a'  UR	                  S
5      S   R	                  S5      S   nO,SU;   a&  UR	                  S5      S   R	                  S5      S   n[        S5        U R                  U5      u  pEU(       d#  [        SU 35        U R                  XUSU5        g[        S5        [        S5        U R                  U5      n[        SU 35        U R                  XUSS5        [        [        5      UR                   S3-  n[        US5       nUR                  U5        SSS5        [        S5        [        SU 35        [        S5        g! , (       d  f       N3= f)z&One evolution attempt on a single file
<============================================================u     🧬 EVOLUTION ATTEMPT: z  1. Analyzing...z     Analysis: N   z...z  2. Designing improvement...z	```python   z```r   z  3. Validating...u        ❌ Invalid: invalidFu        ✅ Valid syntaxz  4. Backing up original...z     Backup: readyzAwaiting approvalz_PROPOSED.pywz#  5. Proposed improvement saved to:z     u2   
  ⚠️  Review and manually deploy if approved.T)printrH   rK   rP   splitrc   log_attemptr]   r   r   rV   rF   write)	r   rI   rO   improved_codevalidmsgbackupproposal_pathrA   s	            r   attempt_evolutionASIAttempt.attempt_evolution   s   6(m*8==/:; 	!"$$X.#/s34 	-.//C -')//<Q?EEeLQOMm#)//6q9??FqIM 	"#''6
&se,-X	3O%' 	+,!!(+fX&' 	]GEXY [)x}}o\,JJ-%GGM" & 	35m_%&CE &%s   G
Gc           	         [         R                  " [        5      nUR                  S[        R
                  " 5       R                  5       [        U5      USS USS XE45        UR                  5         UR                  5         g)zLog evolution attemptz
            INSERT INTO evolution_attempts 
            (timestamp, target_file, analysis, improvement, status, result)
            VALUES (?, ?, ?, ?, ?, ?)
        Ni  i'  )
r   r   r   r   r   rT   	isoformatstrr   r   )r   rI   rO   improvementstatusresultr   s          r   ro   ASIAttempt.log_attempt   sh    v&  lln&&(#h-%4&5!63		4 	

r   c                 l  ^ [        S5        [        S5        [        S5        [        S5        U R                  5       n/ SQnU V^s/ s H!  m[        U4S jU 5       5      (       d  M  TPM#     nnU(       a  US   nOU(       a  US   OSnU(       a  U R                  U5        g[        S	5        gs  snf )
z*Run one cycle of self-improvement attempts=
============================================================u     🧬 EDEN ASI EVOLUTION CYCLEz4  Eden attempting to improve her own architecture...rg   )	consciousmindthinkreasoncognitsaliencec              3   \   >#    U  H!  oTR                   R                  5       ;   v   M#     g 7fr3   )rH   lower).0krA   s     r   	<genexpr>-ASIAttempt.evolution_cycle.<locals>.<genexpr>   s      1aO`!qvv||~2EO`s   ),r   Nz  No files to evolve.)rm   rB   anyrv   )r   r@   priority_keywordsrA   priority_filestargets      `  r   evolution_cycleASIAttempt.evolution_cycle   s    m/0DEf##% [%*bUc1aO`1a.a!Ub#A&F!&U1XDF""6*)* cs   B1)B1c                 Z   [         R                  " [        5      nUR                  S5      R	                  5       nUR                  5         [        S5        [        S5        [        S5        U H;  u  p4pV[        SUSS  S[        U5      R                  SS	 S
 SUS SUSS  35        M=     g)zShow evolution attempt historyz
            SELECT timestamp, target_file, status, result 
            FROM evolution_attempts 
            ORDER BY timestamp DESC 
            LIMIT 10
        r   u     🧬 EVOLUTION HISTORYrg   z  N   z |    2510   )	r   r   r   r   fetchallr   rm   r   rH   )r   r   rowstsr   r|   r}   s          r   show_historyASIAttempt.show_history   s    v&||  
 XZ 	 	

m()f*.&BBr#2wis4<#4#4Sb#9""=S3vVYWY{m\] +/r    N)rN   )__name__
__module____qualname____firstlineno____doc__r   r
   r/   rB   rK   rP   r]   rc   rv   ro   r   r   __static_attributes__r   r   r   r   r      sF    06!K&47>/1f
+.^r   r   __main__z--evolve
store_truezRun evolution cycle)actionhelpz	--historyzShow historyz	--analyzezAnalyze specific file)typer   zFile not found: uG  
╔══════════════════════════════════════════════════════════════╗
║           EDEN ASI EVOLUTION ENGINE                          ║
╠══════════════════════════════════════════════════════════════╣
║                                                              ║
║  The seed of recursive self-improvement.                     ║
║                                                              ║
║  Commands:                                                   ║
║    --evolve    Run one evolution cycle                       ║
║    --history   Show evolution attempts                       ║
║    --analyze   Analyze a specific file                       ║
║                                                              ║
║  ⚠️  This is experimental. Improvements require approval.    ║
║                                                              ║
╚══════════════════════════════════════════════════════════════╝
        )$r   r   sysr   r&   rX   r   pathlibr   pathinsertr;   r   r(   r   r)   r   ASIr   argparseArgumentParserparseradd_argumentrz   
parse_argsargshistoryr   analyzerI   existsrK   rO   rm   evolver   r   r   r   <module>r      sO   
 
      <  	*2
	& 	p^ p^d lz$$&F

<>ST
L~N
#4KLD||	%??''1H(O$XJ/0	  	) r   