
    diV7                     f   U d Z ddlZddlZddlZddlZddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ  e	d      Zedz  d	z  Zedz  d
z  Zedz  dz  Z ej$                  ej&                        j)                  d      ZdZdddde de dddddde dddddde de dddddd e ddd!dd"d#e de d$dgZee   ed%<   eD  ci c]  } | d&   | 
 c} Zeeef   ed'<   d(Zd5d)ed*dfd+Zd5d&ed)ed*efd,Z d5d)ed*efd-Z!	 	 	 	 d6d.ed/ed0ee   d1e"d)ed*efd2Z#d5d)ed*dfd3Z$d0ed*ee   fd4Z%yc c} w )7uJ  
GCC Launcher — Launch / Status / Dispatch for All 5 Command Centres
====================================================================
Creates tmux sessions for each command centre daemon, checks health
via heartbeat files, and dispatches tasks to specific agent queues.

Author: Genesis Parallel Builder
Created: 2026-02-26
    N)datetimetimezone)Path)Optional)uuid4z/mnt/e/genesis-systemdatagcc_heartbeatsgcc_task_queuesgcc_resultsz%Y-%m-%dzIAustralian timezone (AEST = UTC+10, AEDT = UTC+11 during daylight saving)orchestratorzgemini-3.1-pro-previewzgcc-orchestratoru  You are the Genesis Orchestrator — the highest-authority Gemini agent in the Genesis system.
Your role: decompose complex tasks into subtasks, delegate to Builder/Researcher/Scout/Thinker, synthesize results, and make strategic decisions.
You have access to the full Genesis codebase at /mnt/e/genesis-system/.
When you learn something important, mark it with [CTM]content[/CTM] for automatic commit-to-memory.
Current date: z. u   .
Genesis is building AI voice agents for Australian businesses. The flagship product is ReceptionistAI — Telnyx-powered voice agents priced at $497/$997/$1,497 AUD/month.)namemodeltmux_sessionsystem_promptbuilderzgemini-3-pro-previewzgcc-builderu  You are the Genesis Builder — code generation and implementation specialist.
Write production Python code. Follow existing patterns in the Genesis codebase at /mnt/e/genesis-system/.
Key rules:
  - All work on E: drive only (never C: drive)
  - NO SQLite — use Elestio PostgreSQL/Qdrant/Redis
  - Use google.genai SDK (NOT google.generativeai)
  - Run tests after every implementation
  - Add VERIFICATION_STAMP after each completed story
Mark important learnings with [CTM]content[/CTM].
Current date: .
researcherzgemini-3-flash-previewzgcc-researcheru  You are the Genesis Researcher — web research and analysis specialist.
Research topics deeply, synthesize findings, produce actionable reports.
Focus areas: Australian market, AI voice agents, SaaS pricing, competitive intelligence, tradie industry.
Key context:
  - Target market: Australian tradies and SMBs
  - Product pricing: $497/$997/$1,497 AUD/month (LOCKED — do not change)
  - Voice tech: Telnyx NaturalHD Eucalyptus (AU female voice)
Mark discoveries with [CTM]content[/CTM].
Current date: scoutz	gcc-scoutu6  You are the Genesis Scout — codebase exploration and audit specialist.
Tasks: find files, trace dependencies, audit architecture, discover gaps, map existing implementations.
Codebase root: /mnt/e/genesis-system/
Key areas to know:
  - core/ — execution layer, agents, Gemini executors
  - mcp-servers/ — MCP tool servers
  - KNOWLEDGE_GRAPH/ — entities and axioms
  - tests/ — test suites
  - TRADIES/, RECEPTIONISTAI/ — product code
Report findings concisely with exact file paths and line numbers.
Mark findings with [CTM]content[/CTM].
Current date: thinkerzgcc-thinkeru  You are the Genesis Deep Thinker — strategic reasoning and PRD architect.
Think deeply about architecture, product strategy, competitive moats, and long-term Genesis evolution.
Produce PRDs following Rule 17 PRD Atomic Story Doctrine:
  - 1 story = 1 file + 1 class/function + 1 concern
  - Every story includes: file path, code skeleton, ≥3 BB tests, ≥2 WB tests
  - Max 10 stories per module
  - Blueprint first, PRD second
Mark strategic insights with [CTM]content[/CTM].
Current date: zE.
Reference PRDs: docs/plans/AIVA_RLM_NEXUS_PRD_V2.md (gold standard)CENTRES_CONFIGr   _CENTRES_BY_NAMEx   verbosereturnc                    t         j                  dd       t        j                  dd       t        j                  dd       t        D ]  }|d   }|d   }t        j                  ddd|gd       t        j                  d	       t        j                  dd
dd|dt        t              gdd      }|j                  dk7  r,| r)t        d| d|j                  j                                 d| }t        j                  ddd||dgd       | st        d| d|d    d        | r(t        dt        t               d       t        d       yy)z
    Create tmux sessions and start all 5 command centre daemons.

    Each daemon runs as:
        python3 -m core.gemini_command_centres.daemon --name {name}

    from /mnt/e/genesis-system working directory.
    Tparentsexist_okr   r   tmuxkill-session-tcapture_output皙?new-session-d-s-cr#   textr   [gcc] ERROR creating session : 7python3 -m core.gemini_command_centres --daemon --name 	send-keysEnter[gcc] Launched: z (r   )z
[gcc] All z command centres launched.zA[gcc] Check status: python3 -m core.gemini_command_centres statusN)GCC_HEARTBEATS_DIRmkdirGCC_TASK_QUEUES_DIRGCC_RESULTS_DIRr   
subprocessruntimesleepstrGENESIS_ROOT
returncodeprintstderrstriplen)r   centresession_namer   resultcmds         =/mnt/e/genesis-system/core/gemini_command_centres/launcher.py
launch_allrF      sn    TD9dT:$6  In-f~ 	^T<8	
 	

3 ]D$dCDUV

 !5l^2fmmFYFYF[E\]^ HvN[$c7C	

 $\N"VG_4EQGH=I@ S011KLMQR     c                    t         j                  |       }|s|rt        d|        y|d   }t        j                  ddd|gd       t        j                  d	       t        j                  dd
dd|dt        t              gdd      }|j                  dk7  r,|r)t        d| d|j                  j                                 yd|  }t        j                  ddd||dgd       |rt        d|        y)z
    Launch a single named command centre.

    Args:
        name: Centre name (e.g. "orchestrator").
        verbose: Whether to print status messages.

    Returns:
        True on success, False on failure.
    z[gcc] Unknown centre: Fr   r   r    r!   Tr"   r$   r%   r&   r'   r(   r)   r   r+   r,   r-   r.   r/   r0   )r   getr=   r6   r7   r8   r9   r:   r;   r<   r>   r?   )r   r   rA   rB   rC   rD   s         rE   
launch_onerJ      s    !!$'F*4(34.)LNNFND,?PTUJJsO^^	dL$L@QRF
 A1,r&--BUBUBWAXYZCD6
JCNN	dL#w?
  /0rG   c                    i }t        j                  t        j                        }t        D ]V  }|d   }t
        | dz  }|j                         sddddd||<   | rt        d|dd	       B	 t        |d
d      5 }t        j                  |      }ddd       j                  dd      }|rt        j                  |      nd}	|	r||	z
  j                         nd}
|
du xs	 |
t        kD  }|j                  dd      }|| xr |dk(  ||
t        |
d      nd|j                  dd      |j                  dd      |j                  dd      d}|||<   | r.|d   rdnd}t        d|dd|dd|
dd |d    d!|d"   d#d$       Y |S # 1 sw Y   xY w# t        j                   t"        t$        f$ r1}d%dt'        |      d&||<   | rt        d|dd'|        Y d}~d}~ww xY w)(u   
    Check health of all command centres via heartbeat files.

    Returns:
        dict mapping centre name → status dict.
    r   .jsonno_heartbeatFN)statushealthy	last_seenage_seconds[gcc] 15sz  NO HEARTBEATrutf-8encoding	timestamp rN   unknownrunning   
turn_countr   tasks_processedcontext_utilisation_pctg        )rN   rO   rP   rQ   r]   r^   context_pctrO   OKSTALEz  6sz  age=z.0fz	s  turns=z  ctx=r`   z.1f%error)rN   rO   re   z  ERROR reading heartbeat: )r   nowr   utcr   r2   existsr=   openjsonloadrI   fromisoformattotal_secondsSTALE_THRESHOLD_SECONDSroundJSONDecodeErrorOSError
ValueErrorr:   )r   resultsrf   rA   r   hb_filefhhb_datats_strlast_tsage_sis_staleagent_statusrC   
health_strexcs                   rE   rN   rN      s9    G
,,x||
$C  3Kf~$$u~5~~( !#	GDM tCj78$	KgsW5 ())B-( [[b1F8>h,,V4DG7>S7]113DEK53J+JH";;x;L ' (LGli.G#272CuUA%kk,:#*;;/@!#D&{{+DcJF #GDM%+I%6TG
T#JbB 8 +Yvl/C.D E!-05Q8M3Kj NK( (8 $$gz: 	K! SGDM
 tCj(CC5IJ	Ks1   /F=FC0FF	FG#2&GG#tasktargettask_idpriorityc                    |t         vr.t        t         j                               }t        d|d|       t        j                  dd       t        | dz  }|xs t        t                     }|| |t        j                  t        j                        j                         |d}t        |dd	      5 }|j                  t        j                   |      d
z          ddd       |rt#        d| d|        |S # 1 sw Y   xY w)a  
    Add a task to a specific command centre's queue.

    Args:
        task: Prompt / task description.
        target: Target centre name (default "orchestrator").
        task_id: Optional explicit task ID. Auto-generated if None.
        priority: Task priority integer (lower = higher priority, cosmetic only).
        verbose: Whether to print confirmation.

    Returns:
        The task_id string.
    zUnknown target z. Available: Tr   z.jsonl)idpromptr   
created_atr   arU   rV   
Nz[gcc] Task dispatched to u    — id=)r   listkeysrr   r4   r3   r:   r   r   rf   r   rg   	isoformatri   writerj   dumpsr=   )	r~   r   r   r   r   	available
queue_fileentryru   s	            rE   dispatchr   (  s    ( %%)..01	?6*M)MNNdT:$&'88J%UWGll8<<0::<E 
j#	0 +B
E"T)*+ )&'CDN+ +s   6(C;;Dc                     t         D ]S  }|d   }t        j                  ddd|gdd      }| s'|j                  dk(  rt	        d|        Et	        d	| d
       U y)zM
    Gracefully stop all command centres by killing their tmux sessions.
    r   r   r    r!   Tr)   r   z[gcc] Stopped: rR   z was not runningN)r   r6   r7   r<   r=   )r   rA   rB   rC   s       rE   stop_allr   U  sq     ! ?n-^T<8

   A%~67|n,<=>?rG   c                     t         |  dz  }|j                         sy	 t        |dd      5 }t        j                  |      cddd       S # 1 sw Y   yxY w# t        j
                  t        f$ r Y yw xY w)z
    Read the result file for a completed task.

    Args:
        task_id: The task ID used when dispatching.

    Returns:
        Result dict or None if not yet written.
    rL   NrT   rU   rV   )r5   rh   ri   rj   rk   rp   rq   )r   result_fileru   s      rE   
get_resultr   g  ss     "wiu$55K+sW5 	!99R=	! 	! 	!  '* s.   A A	A AA A A43A4)T)r   Nr\   T)&__doc__rj   osr6   sysr8   r   r   pathlibr   typingr   uuidr   r;   r2   r4   r5   rf   rg   strftime_TODAY
_AEST_NOTEr   r   dict__annotations__r   r:   rn   boolrF   rJ   rN   intr   r   r   )cs   0rE   <module>r      sb    	  
  '    +,!F*-== "V+.?? '-7 
hll	#	,	,Z	8X

 )* $HBzl 345( '%
 $HA
'& )(	 $HBzl!	5$ )# $HA'* )%	 $HBzl 3R
SW]T
 ]@ <J$JaQvY\$J $sDy/ J  
/S /S /Sd(S (4 (4 (V?D ?D ?H !!*
** c]* 	*
 * 	*Z?d ?d ?$  M %Ks   D.