Ë
    ÛJêjúm  ã                  óô  — d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	 d dl
mZmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZ d d
lmZmZ  ej4                  e«      ZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,e G d„ d«      «       Z- G d„ de«      Z. G d„ d e«      Z/ G d!„ d"«      Z0 G d#„ d$e«      Z1 G d%„ d&e1«      Z2 G d'„ d(e1«      Z3 G d)„ d*e1«      Z4 G d+„ d,e1«      Z5 G d-„ d.e1«      Z6 G d/„ d0e1«      Z7y)1é    )ÚannotationsN)ÚABCÚabstractmethod)Ú	dataclassÚfield)ÚAnyÚProtocol)Úuuid4)ÚAsyncEventBusÚMemoryTaskQueue)ÚAuthorizedExecutionServiceÚExecutionRefused)ÚAgentIdentity)ÚPermissionGatewayÚSecurityErrorzplanner.task_requestzplanner.task_completedzcoder.task_requestzcoder.task_completedzevaluator.task_requestzevaluator.task_completedzsecurity.task_requestzsecurity.task_completedzresearch.task_requestzresearch.task_completedzbrowser.task_requestzbrowser.task_completedÚexecuteé   é2   zmBrowserAgent has no browsing backend; the capability is not implemented and no page was fetched or inspected.c                  óh   — e Zd ZU dZded<   ded<   ded<    ee¬«      Zd	ed
<   dZded<   dZ	ded<   y)ÚAgentResultaÝ  Structured outcome of one agent run.

    ``execution_attempted`` records whether the sandbox may already have run
    code for this result. It defaults to True on purpose: a consumer that
    cannot prove the code never started must assume side effects are possible
    and therefore must not re-run the step. Only an agent that structurally
    knows it was refused *before* the provider was invoked may set it to False,
    which is what makes a blocked step retryable.
    ÚstrÚ
agent_nameú
str | NoneÚtask_idÚboolÚsuccess)Údefault_factoryúdict[str, Any]ÚdataNÚerrorTÚexecution_attempted)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   Údictr   r    r!   © ó    úF/home/oem/CyberBrain26-unified/src/cyberbrain26/agents/orchestrator.pyr   r   ,   s=   … ñð ƒOØÓØƒMÙ °Ô6€Dˆ.Ó6Ø€Eˆ:ÓØ $Ð˜Ô$r)   r   c                  ó   — e Zd ZdZdd„Zy)ÚTaskAuthorizera&  Authorization collaborator required before bus-driven agent work.

    Security rationale: the event bus is a shared, publicly reachable channel
    (``PtahBridge.bus`` is exposed to callers), so a published
    ``*_TASK_REQUEST`` is untrusted input. An agent therefore never calls
    ``execute`` for a bus task on its own: it first hands the payload to an
    injected authorizer that must run the canonical chain
    (identity -> scope -> policy -> approval -> audit).

    Contract for implementations:

    * return normally when the request may proceed;
    * raise (``SecurityError`` for a policy refusal, or any other exception
      when the decision could not be made) when it may not.

    Only "returned without raising" counts as authorization. A return value is
    deliberately not inspected, so an implementation cannot accidentally turn a
    falsy return into an approval. ``BaseAgent`` treats every raise as a
    refusal and treats a missing authorizer as a refusal too, which keeps the
    failure mode closed when wiring is incomplete.
    c              ƒ  ó   K  — y ­w©Nr(   ©ÚselfÚ	task_datas     r*   Ú__call__zTaskAuthorizer.__call__W   s   è ø� ùó   ‚N©r1   r   ÚreturnÚNone)r"   r#   r$   r%   r2   r(   r)   r*   r,   r,   @   s   „ ñô, Er)   r,   c                  ó2   — e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 dd„Zy)ÚDispatcherAuthorizerPorta  Structural view of ``InMemoryTaskDispatcher._authorize``.

    Declared structurally rather than imported so the agents module keeps no
    import-time dependency on the extension layer, and so the extension layer
    can rename its internals without a silent behaviour change here.
    c              ƒ  ó   K  — y ­wr.   r(   )r0   r   Úregistered_agent_idÚagentÚactionÚresources         r*   Ú
_authorizez#DispatcherAuthorizerPort._authorizeb   s   è ø€ ð ùr3   N).)r   r   r:   r   r;   r   r<   r   r=   r   r5   r6   )r"   r#   r$   r%   r>   r(   r)   r*   r8   r8   Z   sK   „ ñð  #ðàðð !ðð ð	ð
 ðð ðð 
ôr)   r8   c                  ó>   — e Zd ZdZeddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zy)ÚDispatcherAuthorizera,  Adapter binding a bus task to a dispatcher's authorization decision.

    ``InMemoryTaskDispatcher._authorize`` already implements the canonical
    chain (identity match -> policy -> approval -> audit) and already fails
    closed by raising ``SecurityError``. This adapter forwards to it so the bus
    path and the dispatcher path share one decision instead of duplicating -
    and eventually weakening - policy evaluation inside the agents.

    Construction order matters: the bridge must build the agents first and then
    assign the adapter, because the adapter needs both the agent and its
    identity::

        agent = PlannerAgent(bridge.bus, bridge.queue, identity=..., permission_gateway=...)
        agent.authorizer = DispatcherAuthorizer(bridge.dispatcher, agent.identity.agent_id, agent)
    N)r<   r=   c               óJ   — || _         || _        || _        || _        || _        y r.   )Ú_dispatcherÚ	_agent_idÚ_agentÚ_actionÚ	_resource)r0   Ú
dispatcherÚagent_idr;   r<   r=   s         r*   Ú__init__zDispatcherAuthorizer.__init__}   s(   € ð &ˆÔØ!ˆŒØˆŒØˆŒØ!ˆ�r)   c              ƒ  ó  K  — |j                  d«      }|rt        |«      ndt        «       j                  › �}| j                  j                  || j                  | j                  | j                  | j                  «      ƒ d {  –—†  y 7 Œ­w)Nr   zbus-)
Úgetr   r
   ÚhexrB   r>   rC   rD   rE   rF   )r0   r1   Úraw_task_idr   s       r*   r2   zDispatcherAuthorizer.__call__Œ   sl   è ø€ Ø—m‘m IÓ.ˆÙ&1”#�kÔ"¸¼e»g¿k¹k¸]Ð7KˆØ×Ñ×)Ñ)ØØ�N‰NØ�K‰KØ�L‰LØ�N‰Nó
÷ 	
ò 	
ús   ‚B B
ÂBÂB
)rG   r8   rH   r   r;   r   r<   r   r=   r   r5   r6   r4   )r"   r#   r$   r%   ÚBUS_TASK_ACTIONrI   r2   r(   r)   r*   r@   r@   l   sS   „ ñð, &Ø#ñ"à,ð"ð ð"ð ð	"ð ð"ð ð"ð 
ó"ô	
r)   r@   c                  óà   — e Zd Z	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd„Zeedd„«       «       Zeedd„«       «       Zdd„Zdd„Z	edd„«       Z
	 	 	 	 dd„Zdd	„Zdd
„Z	 	 dddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zddd„Zy)Ú	BaseAgentNc                ót   — || _         || _        g | _        d| _        d| _        || _        || _        || _        y)a½  Wire the agent onto the bus.

        ``authorizer`` gates every bus-delivered task request. It defaults to
        ``None``, which means "no authorization collaborator was injected" and
        therefore **deny**: the agent refuses bus-driven work instead of
        executing it. The default is deliberately fail-closed so that a
        construction site which has not been migrated to the new contract
        loses the unauthenticated entry point rather than keeping it. Callers
        that legitimately drive agents over the bus must inject a
        ``TaskAuthorizer`` (see ``DispatcherAuthorizer``), either in this
        constructor or by assigning ``agent.authorizer`` afterwards.
        N)ÚbusÚqueueÚresultsÚ_task_request_eventÚ_task_completed_eventÚidentityÚpermission_gatewayÚ
authorizer)r0   rR   rS   rW   rX   rY   s         r*   rI   zBaseAgent.__init__™   s?   € ð( ˆŒØˆŒ
Ø*,ˆŒØ/3ˆÔ Ø15ˆÔ"Ø ˆŒØ"4ˆÔØ$ˆ�r)   c                 ó   — y r.   r(   ©r0   s    r*   ÚnamezBaseAgent.name¶   ó   € àr)   c                 ó   — y r.   r(   r[   s    r*   ÚrolezBaseAgent.roleº   r]   r)   c                ó~   — | j                   r1| j                  j                  | j                   | j                  «       y y r.   )rU   rR   Ú	subscribeÚ_on_task_requestr[   s    r*   Ú
_subscribezBaseAgent._subscribe¾   s0   € Ø×#Ò#Ø�H‰H×Ñ˜t×7Ñ7¸×9NÑ9NÕOð $r)   c              ƒ  ó´  K  — t        |dd«      }t        |t        «      r|ni }| j                  |«      ƒ d{  –—† }|�|n| j	                  |«      ƒ d{  –—† }|�t| j
                  rh| j                  j                  | j
                  | j                  |j                  |j                  |j                  dœ|j                  dœ«      ƒ d{  –—†  |S 7 Œ™7 Œ~7 Œ
­w)a  Handle a bus-delivered task request.

        Security rationale: this handler used to call ``execute`` directly, so
        anyone holding a reference to the event bus could run an agent body with
        an arbitrary payload and no identity, scope, policy or approval check
        at all - the bus was a full bypass of the authorization chain. Every
        bus task must now clear an injected ``TaskAuthorizer`` first; a missing
        or denying authorizer produces a recorded refusal instead of work.
        ÚpayloadN)r   r   r    )r;   Úresultr   )ÚgetattrÚ
isinstancer'   Ú_authorize_task_requestr   rV   rR   Úpublishr\   r   r   r    r   )r0   Úeventre   r1   Úrefusalrf   s         r*   rb   zBaseAgent._on_task_requestÂ   sÇ   è ø€ ô ˜% ¨DÓ1ˆÜ/9¸'Ä4Ô/H¡GÈbˆ	Ø×4Ñ4°YÓ?×?ˆØ#Ð/‘¸4¿<¹<È	Ó;R×5RˆØÐ $×"<Ò"<Ø—(‘(×"Ñ" 4×#=Ñ#=ØŸ™Ø&,§n¡n¸f¿k¹kÐTZ×T`ÑT`ÑaØ!Ÿ>™>ñ@ó ÷ ð ð
 ˆð @øØ5Røðús4   ‚6C¸C¹CÁCÁA5CÃCÃCÃCÃCc              ƒ  ó   K  — y ­wr.   r(   r/   s     r*   r   zBaseAgent.executeØ   s	   è ø€ àùr3   c              ƒ  óp  K  — | j                   €| j                  |d«      S 	 | j                  |«      ƒ d{  –—†  y7 Œ# t        $ r%}| j                  |t        |«      «      cY d}~S d}~wt        $ r@}t
        j                  d| j                  |«       | j                  |d|› �«      cY d}~S d}~ww xY w­w)a7  Authorize one bus task request before the agent body may run.

        Returns ``None`` when the request is authorized (the caller then runs
        ``execute``), or an ``AgentResult`` describing a refusal. Fail-closed:
        no authorizer, a raising authorizer, or any unexpected exception from
        the authorizer all mean "refuse". A refusal is recorded with
        ``execution_attempted=False`` because it is structurally known to have
        happened before the agent body started, which keeps the step retryable
        once the wiring is fixed.
        NzDbus task requests require an injected authorizer; none is configuredz>%s bus task authorization could not be completed, refusing: %szauthorization failed closed: )rY   Ú_refuse_task_requestr   r   Ú	ExceptionÚloggerÚwarningr\   )r0   r1   Úexcs      r*   ri   z!BaseAgent._authorize_task_requestÜ   s¹   è ø€ ð �?‰?Ð"Ø×,Ñ,ØØVóð ð	Ø—/‘/ )Ó,×,Ð,ð ð -ùÜò 	BØ×,Ñ,¨Y¼¸C»ÓAÕAûÜò 
	ô �N‰NØPØ—	‘	Øôð
 ×,Ñ,ØÐ:¸3¸%Ð@óõ ûð
	üsU   ‚B6¢> ¶<·> »B6¼> ¾	B3ÁA'Á!B3Á"B6Á'B3Á35B.Â(B3Â)B6Â.B3Â3B6c                ó¨   — t         j                  d| j                  |«       | j                  | j	                  |«      d| j
                  ddœ|d¬«      S )zARecord and return a refusal for an unauthorized bus task request.z!%s refused a bus task request: %sFÚ	event_bus)r_   Úsource©r!   )rq   rr   r\   Úpublish_resultÚ_task_id_fromr_   )r0   r1   Úreasons      r*   ro   zBaseAgent._refuse_task_requestÿ   sR   € ä�‰Ð:¸D¿I¹IÀvÔNØ×"Ñ"Ø×Ñ˜yÓ)ØØ—Y‘Y¨+Ñ6ØØ %ð #ó 
ð 	
r)   c                óB   — |j                  d«      }|€dS t        |«      S )zCBest-effort task id for a refusal or unavailable-capability result.r   N)rK   r   )r0   r1   Úraws      r*   ry   zBaseAgent._task_id_from
  s#   € à�m‰m˜IÓ&ˆØ�{ˆtÐ0¬¨C«Ð0r)   Trw   c               óz   — t        | j                  |||xs i ||¬«      }| j                  j                  |«       |S )z;Record an outcome and mark whether execution was attempted.)r   r   r   r   r    r!   )r   r\   rT   Úappend)r0   r   r   r   r    r!   rf   s          r*   rx   zBaseAgent.publish_result  sA   € ô Ø—y‘yØØØ’˜ØØ 3ô
ˆð 	�‰×Ñ˜FÔ#Øˆr)   c                ó´   — | j                   �| j                  €y| j                  j                  | j                   ||«      }|j                  j                  dk(  S )zŒCheck whether this agent is permitted to perform an action.

        Returns True if allowed, False if denied or requires approval.
        FÚallow)rW   rX   ÚevaluateÚdecisionÚvalue)r0   r<   r=   rf   s       r*   Úcheck_permissionzBaseAgent.check_permission$  sO   € ð
 �=‰=Ð  D×$;Ñ$;Ð$CØØ×(Ñ(×1Ñ1°$·-±-ÀÈÓRˆØ�‰×$Ñ$¨Ñ/Ð/r)   ©NNN©rR   r   rS   r   rW   úAgentIdentity | NonerX   úPermissionGateway | NonerY   úTaskAuthorizer | Noner5   r6   ©r5   r   )r5   r6   )rk   r   r5   úAgentResult | None©r1   r   r5   r‹   )r1   r   rz   r   r5   r   )r1   r   r5   r   ©NN)r   r   r   r   r   zdict[str, Any] | Noner    r   r!   r   r5   r   r.   )r<   r   r=   r   r5   r   )r"   r#   r$   rI   Úpropertyr   r\   r_   rc   rb   r   ri   ro   ry   rx   r„   r(   r)   r*   rP   rP   ˜   s  „ ð
 *.Ø7;Ø,0ð%àð%ð ð%ð 'ð	%ð
 5ð%ð *ð%ð 
ó%ð: ØÚó ó ààØÚó ó àóPóð, òó ðð!Ø'ð!à	ó!óF	
ó1ð '+Ø ðð %)ñàðð ðð $ð	ð
 ðð "ðð 
óõ*0r)   rP   c                  óˆ   ‡ — e Zd Z	 	 d	ddœ	 	 	 	 	 	 	 	 	 	 	 d
ˆ fd„Zedd„«       Zedd„«       Zdd„Zedd„«       Z	dd„Z
ˆ xZS )ÚPlannerAgentN©rY   c               ó†   •— t         ‰| �  |||||«       t        | _        t        | _        g | _        | j                  «        y r.   )ÚsuperrI   ÚPLANNER_TASK_REQUESTrU   ÚPLANNER_TASK_COMPLETEDrV   Ú_planrc   ©r0   rR   rS   rW   rX   rY   Ú	__class__s         €r*   rI   zPlannerAgent.__init__0  s<   ø€ ô 	‰Ñ˜˜e XÐ/AÀ:ÔNÜ#7ˆÔ Ü%;ˆÔ"Ø+-ˆŒ
Ø�‰Õr)   c                 ó   — y)Nr�   r(   r[   s    r*   r\   zPlannerAgent.name?  ó   € àr)   c                 ó   — y)NÚplannerr(   r[   s    r*   r_   zPlannerAgent.roleC  ó   € àr)   c              ƒ  ór  K  — |j                  dd«      }| j                  |j                  d«      «      \  }}|�| j                  ddd|i|d¬«      S t        d|dz   «      D �cg c]  }||› d|› �d	œ‘Œ }}|| _        | j
                  j                  d
„ «      }| j                  |d|||dœ«      }|S c c}w ­w)a  Build an in-memory plan, honouring ``max_steps`` from the payload.

        ``max_steps`` is what ``cyberbrain plan --steps/-n`` sends, and it used
        to be ignored: the plan was hard-coded to three steps, so the CLI flag
        silently had no effect.
        ÚgoalÚunknownÚ	max_stepsNFrw   é   z - step )ÚstepÚdescriptionc                 ó,   — t        j                  d«      S )Nr   )ÚasyncioÚsleepr(   r)   r*   ú<lambda>z&PlannerAgent.execute.<locals>.<lambda>^  s   € ¬W¯]©]¸1Ó-=€ r)   T)rŸ   Úplanr¡   )rK   Ú_resolve_step_countrx   Úranger–   rS   Úenqueue)	r0   r1   rŸ   Ústepsr    ÚiÚ	sub_tasksr   rf   s	            r*   r   zPlannerAgent.executeG  sê   è ø€ ð �}‰}˜V YÓ/ˆØ×/Ñ/°	·±¸kÓ0JÓK‰ˆˆuØÐð ×&Ñ&ØØØ˜�ØØ$)ð 'ó ð ô GLÈAÈuÐWXÉyÓFYö
ØAB�Q¨$¨¨x¸°sÐ';Ó<ð
ˆ	ð 
ð ˆŒ
Ø—*‘*×$Ñ$Ñ%=Ó>ˆØ×$Ñ$Ø�T D°)È%ÑPó
ˆð ˆùò
ùs   ‚A!B7Á#B2Á4AB7c                ó°   — | €t         dfS t        | t        «      st        | t        «      st         d| ›�fS | dk  rt         d| › �fS t	        | t
        «      dfS )a¨  Validate ``max_steps`` and return ``(steps, error)``.

        Rules, chosen because ``max_steps`` arrives over the event bus and is
        therefore untrusted input:

        * absent (``None``) -> ``DEFAULT_PLAN_STEPS`` (3);
        * ``bool`` or non-integer -> refused, never coerced, because ``True``
          and ``"3"`` are ambiguous input, not a step count;
        * ``<= 0`` -> refused, because an empty plan is not a plan;
        * ``> MAX_PLAN_STEPS`` (50) -> capped, so one request cannot inflate
          the plan and the resulting roadmap without bound. The cap is reported
          back as the effective ``max_steps`` so the caller sees what was used.
        Nz*max_steps must be a positive integer, got r   z)max_steps must be greater than zero, got )ÚDEFAULT_PLAN_STEPSrh   r   ÚintÚminÚMAX_PLAN_STEPS)Ú	requesteds    r*   rª   z PlannerAgent._resolve_step_countd  sk   € ð ÐÜ% tÐ+Ð+Ü�i¤Ô&¬j¸ÄCÔ.HÜ%Ð)SÐT]ÐS`Ð'aÐaÐaØ˜Š>Ü%Ð)RÐS\ÐR]Ð'^Ð^Ð^Ü�9œnÓ-¨tÐ3Ð3r)   c                ó,   — t        | j                  «      S r.   )Úlistr–   r[   s    r*   Úget_planzPlannerAgent.get_plan{  s   € Ü�D—J‘JÓÐr)   r�   r†   rŠ   rŒ   )rµ   r   r5   ztuple[int, str | None]©r5   zlist[dict[str, Any]])r"   r#   r$   rI   rŽ   r\   r_   r   Ústaticmethodrª   r¸   Ú__classcell__©r˜   s   @r*   r�   r�   /  sš   ø„ ð
 *.Ø7;ðð -1ñàðð ðð 'ð	ð
 5ðð *ðð 
õð òó ðð òó ðóð: ò4ó ð4÷, r)   r�   c                  ó„   ‡ — e Zd Z	 	 	 d	ddœ	 	 	 	 	 	 	 	 	 	 	 	 	 d
ˆ fd„Zedd„«       Zedd„«       Zdd„Zdd„Zdd„Z	ˆ xZ
S )Ú
CoderAgentNr‘   c               ó”   •— t         ‰| �  |||||«       || _        t        | _        t
        | _        g | _        | j                  «        y r.   )	r“   rI   Úexecution_serviceÚCODER_TASK_REQUESTrU   ÚCODER_TASK_COMPLETEDrV   Ú_implementedrc   )r0   rR   rS   rW   rX   rÀ   rY   r˜   s          €r*   rI   zCoderAgent.__init__€  sE   ø€ ô 	‰Ñ˜˜e XÐ/AÀ:ÔNØ!2ˆÔÜ#5ˆÔ Ü%9ˆÔ"Ø')ˆÔØ�‰Õr)   c                 ó   — y)Nr¾   r(   r[   s    r*   r\   zCoderAgent.name‘  s   € àr)   c                 ó   — y)NÚcoderr(   r[   s    r*   r_   zCoderAgent.role•  s   € àr)   c           
   ƒ  óä  K  — d|v �rÇ|j                  dd«      }|j                  d«      }|j                  d«      }t        |j                  d«      xs dt        «       j                  › �«      }t	        |t        «      rt	        |t        «      s| j                  |dd|idd¬	«      S | j                  �| j                  €| j                  |dd|id
d¬	«      S 	 | j                  j                  | j                  ||||j                  dd«      |j                  d«      ¬«      ƒ d {  –—† }|j                  d«      dk(  xr |j                  dd«       }|r$| j                  j                  t        |«      «       d }	|s;|j                  d«      xs( |j                  dd«      rdnd|j                  d«      › �}	| j                  ||||dœ|	«      S | j                  j!                  | j"                  «      }	 | j                  j                  |«      }
|
€J ‚| j                  j%                  |
«      ƒ d {  –—†  |j                  dd«      }| j                  j                  |«       | j                  |d|ddœ«      }|S 7 �ŒW# t        $ r+}| j                  |dd|it        |«      d¬	«      cY d }~S d }~wt        t        t        f$ r)}| j                  |dd|it        |«      «      cY d }~S d }~ww xY w7 Œ¾# t&        t        t(        j*                  f$ r }t,        j/                  d|«       Y d }~Œõd }~wt        $ r t,        j/                  d«       ‚ t0        $ r t,        j3                  d«       ‚ w xY w­w)NÚcoder¤   zcode executionÚlanguager   zcoder-Fz!code and language must be stringsrw   z<authorized execution service and agent identity are requiredÚtimeout_secondsé   Ú	workspace)r   rÊ   rÌ   Úreturn_coder   Ú	timed_outÚstderrzexecution timed outzexecution exited with code )r¤   Ú	executionz$CoderAgent queue dispatch failed: %sz-CoderAgent permission denied during executionz1CoderAgent unexpected error during queue dispatchr    TÚimplemented)r¤   Ústatus)rK   r   r
   rL   rh   rx   rÀ   rW   r   r   r   ÚRuntimeErrorÚ
ValueErrorrÃ   r~   rS   r¬   Ú_do_codeÚdispatchÚKeyErrorr¦   ÚCancelledErrorrq   rr   rp   Ú	exception)r0   r1   r¤   rÈ   rÉ   r   rÐ   rs   r   r    Úrecordrf   s               r*   r   zCoderAgent.execute™  sk  è ø€ Ø�YÒØ#Ÿ-™-¨Ð7GÓHˆKØ—=‘= Ó(ˆDØ —}‘} ZÓ0ˆHÜ˜)Ÿ-™-¨	Ó2ÒL¸¼u»w¿{¹{¸mÐ6LÓMˆGÜ˜d¤CÔ(´
¸8ÄSÔ0Ià×*Ñ*ØØØ" KÐ0Ø7Ø(-ð +ó ð ð ×%Ñ%Ð-°·±Ð1Fð ×*Ñ*ØØØ" KÐ0ØRØ(-ð +ó ð ðØ"&×"8Ñ"8×"@Ñ"@Ø—M‘MØØØ#Ø$-§M¡MÐ2CÀRÓ$HØ'Ÿm™m¨KÓ8ð #Aó #÷ �	ð<  —m‘m MÓ2°aÑ7ÒaÀ	ÇÁÈkÐ[`Ó@aÐ<aˆGÙØ×!Ñ!×(Ñ(¬¨[Ó)9Ô:ØˆEÙØ!Ÿ™ hÓ/ò à —}‘} [°%Ô8ñ *à6°y·}±}À]Ó7SÐ6TÐUð ð
 ×&Ñ&ØØØ +¸)ÑDØó	ð ð —*‘*×$Ñ$ T§]¡]Ó3ˆð	Ø—Z‘Z—^‘^ GÓ,ˆFØÐ%Ð%Ð%Ø—*‘*×%Ñ% fÓ-×-Ð-ð  —m‘m M°9Ó=ˆØ×Ñ× Ñ  Ô-Ø×$Ñ$ W¨dÀKÐ[hÑ4iÓjˆØˆðúô $ò ð
 ×*Ñ*ØØØ" KÐ0Ü˜“HØ(-ð +ó õ ûô "¤<´Ð<ò ð ×*Ñ*ØØØ" KÐ0Ü˜“Hó	õ ûðúð> .ùÜœ,¬×(>Ñ(>Ð?ò 	HÜ�N‰NÐAÀ3×GÑGûÜò 	Ü�N‰NÐJÔKØÜò 	Ü×ÑÐPÔQØð	üs    ‚CM0ÃAI? Ä%I<Ä&I? Ä*C
M0Ç5=K3 È2K1È3K3 È7AM0É<I? É?	K.Ê J.Ê(K.Ê)M0Ê.K.ËK)Ë#K.Ë$M0Ë)K.Ë.M0Ë1K3 Ë3M-ÌL,Ì'M0Ì,AM-Í-M0c              ƒ  ó   K  — y­w)NÚcode_completer(   r[   s    r*   rÕ   zCoderAgent._do_codeõ  s	   è ø€ Øùr3   c                ó,   — t        | j                  «      S r.   )r·   rÃ   r[   s    r*   Úget_implementedzCoderAgent.get_implementedø  ó   € Ü�D×%Ñ%Ó&Ð&r)   r…   )rR   r   rS   r   rW   r‡   rX   rˆ   rÀ   z!AuthorizedExecutionService | NonerY   r‰   r5   r6   rŠ   rŒ   )r5   z	list[str])r"   r#   r$   rI   rŽ   r\   r_   r   rÕ   rÞ   r»   r¼   s   @r*   r¾   r¾     sš   ø„ ð
 *.Ø7;Ø?Cðð -1ñàðð ðð 'ð	ð
 5ðð =ðð *ðð 
õð" òó ðð òó ðóZóx÷'r)   r¾   c                  ó~   ‡ — e Zd Z	 	 d	ddœ	 	 	 	 	 	 	 	 	 	 	 d
ˆ fd„Zedd„«       Zedd„«       Zdd„Zdd„Zdd„Z	ˆ xZ
S )ÚEvaluatorAgentNr‘   c               ó†   •— t         ‰| �  |||||«       t        | _        t        | _        g | _        | j                  «        y r.   )r“   rI   ÚEVALUATOR_TASK_REQUESTrU   ÚEVALUATOR_TASK_COMPLETEDrV   Ú_assessmentsrc   r—   s         €r*   rI   zEvaluatorAgent.__init__ý  s=   ø€ ô 	‰Ñ˜˜e XÐ/AÀ:ÔNÜ#9ˆÔ Ü%=ˆÔ"Ø24ˆÔØ�‰Õr)   c                 ó   — y)Nrá   r(   r[   s    r*   r\   zEvaluatorAgent.name  s   € àr)   c                 ó   — y)NÚ	evaluatorr(   r[   s    r*   r_   zEvaluatorAgent.role  s   € àr)   c              ƒ  óp  K  — | j                   j                  | j                  «      }	 | j                   j                  |«      }|€J ‚| j                   j	                  |«      ƒ d {  –—†  |j                  dd«      }|dk\  }||dœ}| j                  j                  |«       | j!                  |||«      }|S 7 ŒP# t
        t        t        j                  f$ r }t        j                  d|«       Y d }~Œ‡d }~wt        $ r t        j                  d«       ‚ t        $ r t        j                  d«       ‚ w xY w­w)Nz(EvaluatorAgent queue dispatch failed: %sz1EvaluatorAgent permission denied during executionz5EvaluatorAgent unexpected error during queue dispatchÚscoreg        g      à?)Úpassedrê   )rS   r¬   Ú_do_evaluaterK   rÖ   r×   rÓ   r¦   rØ   rq   rr   r   rp   rÙ   rå   r~   rx   )	r0   r1   r   rÚ   rs   rê   rë   Ú
assessmentrf   s	            r*   r   zEvaluatorAgent.execute  s  è ø€ Ø—*‘*×$Ñ$ T×%6Ñ%6Ó7ˆð	Ø—Z‘Z—^‘^ GÓ,ˆFØÐ%Ð%Ð%Ø—*‘*×%Ñ% fÓ-×-Ð-ð —‘˜g sÓ+ˆØ˜#‘ˆØ &°Ñ7ˆ
Ø×Ñ× Ñ  Ô,Ø×$Ñ$ W¨f°jÓAˆØˆð .ùÜœ,¬×(>Ñ(>Ð?ò 	LÜ�N‰NÐEÀs×KÑKûÜò 	Ü�N‰NÐNÔOØÜò 	Ü×ÑÐTÔUØð	üóB   ‚&D6©=B9 Á&B7Á'B9 Á+AD6Â7B9 Â9D3ÃC2Ã-D6Ã2AD3Ä3D6c              ƒ  ó   K  — ddiS ­w)NrÒ   Ú	evaluatedr(   r[   s    r*   rì   zEvaluatorAgent._do_evaluate)  s   è ø€ Ø˜+Ð&Ð&ùó   ‚c                ó,   — t        | j                  «      S r.   )r·   rå   r[   s    r*   Úget_assessmentszEvaluatorAgent.get_assessments,  rß   r)   r�   r†   rŠ   rŒ   ©r5   r   r¹   )r"   r#   r$   rI   rŽ   r\   r_   r   rì   ró   r»   r¼   s   @r*   rá   rá   ü  s‹   ø„ ð
 *.Ø7;ðð -1ñàðð ðð 'ð	ð
 5ðð *ðð 
õð ò ó ð ð òó ðóó*'÷'r)   rá   c                  ó~   ‡ — e Zd Z	 	 d	ddœ	 	 	 	 	 	 	 	 	 	 	 d
ˆ fd„Zedd„«       Zedd„«       Zdd„Zdd„Zdd„Z	ˆ xZ
S )ÚSecurityAgentNr‘   c               ó†   •— t         ‰| �  |||||«       t        | _        t        | _        g | _        | j                  «        y r.   )r“   rI   ÚSECURITY_TASK_REQUESTrU   ÚSECURITY_TASK_COMPLETEDrV   Ú	_findingsrc   r—   s         €r*   rI   zSecurityAgent.__init__1  ó<   ø€ ô 	‰Ñ˜˜e XÐ/AÀ:ÔNÜ#8ˆÔ Ü%<ˆÔ"Ø/1ˆŒØ�‰Õr)   c                 ó   — y)Nrö   r(   r[   s    r*   r\   zSecurityAgent.name@  ó   € àr)   c                 ó   — y)NÚsecurityr(   r[   s    r*   r_   zSecurityAgent.roleD  ó   € àr)   c              ƒ  óp  K  — | j                   j                  | j                  «      }	 | j                   j                  |«      }|€J ‚| j                   j	                  |«      ƒ d {  –—†  |j                  dd«      }||rdnddœ}| j                  j                  |«       | j!                  || |«      }|S 7 ŒP# t
        t        t        j                  f$ r }t        j                  d|«       Y d }~Œ‡d }~wt        $ r t        j                  d«       ‚ t        $ r t        j                  d«       ‚ w xY w­w)	Nz'SecurityAgent queue dispatch failed: %sz0SecurityAgent permission denied during executionz4SecurityAgent unexpected error during queue dispatchÚrequires_reviewFÚhighÚlow)r  Úseverity)rS   r¬   Ú_do_security_checkrK   rÖ   r×   rÓ   r¦   rØ   rq   rr   r   rp   rÙ   rú   r~   rx   )r0   r1   r   rÚ   rs   r  Úfindingrf   s           r*   r   zSecurityAgent.executeH  s  è ø€ Ø—*‘*×$Ñ$ T×%<Ñ%<Ó=ˆð	Ø—Z‘Z—^‘^ GÓ,ˆFØÐ%Ð%Ð%Ø—*‘*×%Ñ% fÓ-×-Ð-ð $Ÿ-™-Ð(9¸5ÓAˆØ&5É_Á6ÐbgÑhˆØ�‰×Ñ˜gÔ&Ø×$Ñ$ W°/Ð.AÀ7ÓKˆØˆð .ùÜœ,¬×(>Ñ(>Ð?ò 	KÜ�N‰NÐDÀc×JÑJûÜò 	Ü�N‰NÐMÔNØÜò 	Ü×ÑÐSÔTØð	ürî   c              ƒ  ó   K  — ddiS ­w)NrÒ   Úcheckedr(   r[   s    r*   r  z SecurityAgent._do_security_check\  s   è ø€ Ø˜)Ð$Ð$ùrñ   c                ó,   — t        | j                  «      S r.   )r·   rú   r[   s    r*   Úget_findingszSecurityAgent.get_findings_  ó   € Ü�D—N‘NÓ#Ð#r)   r�   r†   rŠ   rŒ   rô   r¹   )r"   r#   r$   rI   rŽ   r\   r_   r   r  r  r»   r¼   s   @r*   rö   rö   0  s‹   ø„ ð
 *.Ø7;ðð -1ñàðð ðð 'ð	ð
 5ðð *ðð 
õð òó ðð òó ðóó(%÷$r)   rö   c                  ó~   ‡ — e Zd Z	 	 d	ddœ	 	 	 	 	 	 	 	 	 	 	 d
ˆ fd„Zedd„«       Zedd„«       Zdd„Zdd„Zdd„Z	ˆ xZ
S )ÚResearchAgentNr‘   c               ó†   •— t         ‰| �  |||||«       t        | _        t        | _        g | _        | j                  «        y r.   )r“   rI   ÚRESEARCH_TASK_REQUESTrU   ÚRESEARCH_TASK_COMPLETEDrV   Ú	_researchrc   r—   s         €r*   rI   zResearchAgent.__init__d  rû   r)   c                 ó   — y)Nr  r(   r[   s    r*   r\   zResearchAgent.names  rý   r)   c                 ó   — y)NÚresearchr(   r[   s    r*   r_   zResearchAgent.rolew  r   r)   c              ƒ  ól  K  — | j                   j                  | j                  «      }	 | j                   j                  |«      }|€J ‚| j                   j	                  |«      ƒ d {  –—†  |j                  dd«      }| j                  j                  d|i«       | j!                  |d|d|› �dœ«      }|S 7 ŒN# t
        t        t        j                  f$ r }t        j                  d|«       Y d }~Œ…d }~wt        $ r t        j                  d«       ‚ t        $ r t        j                  d«       ‚ w xY w­w)	Nz'ResearchAgent queue dispatch failed: %sz0ResearchAgent permission denied during executionz4ResearchAgent unexpected error during queue dispatchÚtopicr    TzResearch on )r  Úsummary)rS   r¬   Ú_do_researchrK   rÖ   r×   rÓ   r¦   rØ   rq   rr   r   rp   rÙ   r  r~   rx   )r0   r1   r   rÚ   rs   r  rf   s          r*   r   zResearchAgent.execute{  s  è ø€ Ø—*‘*×$Ñ$ T×%6Ñ%6Ó7ˆð	Ø—Z‘Z—^‘^ GÓ,ˆFØÐ%Ð%Ð%Ø—*‘*×%Ñ% fÓ-×-Ð-ð —‘˜g yÓ1ˆØ�‰×Ñ˜w¨Ð.Ô/Ø×$Ñ$ W¨d¸eÐR^Ð_dÐ^eÐPfÑ4gÓhˆØˆð .ùÜœ,¬×(>Ñ(>Ð?ò 	KÜ�N‰NÐDÀc×JÑJûÜò 	Ü�N‰NÐMÔNØÜò 	Ü×ÑÐSÔTØð	üsB   ‚&D4©=B7 Á&B5Á'B7 Á+A
D4Â5B7 Â7D1ÃC0Ã+D4Ã0AD1Ä1D4c              ƒ  ó   K  — ddiS ­w)NrÒ   Ú
researchedr(   r[   s    r*   r  zResearchAgent._do_researchŽ  s   è ø€ Ø˜,Ð'Ð'ùrñ   c                ó,   — t        | j                  «      S r.   )r·   r  r[   s    r*   Úget_researchzResearchAgent.get_research‘  r  r)   r�   r†   rŠ   rŒ   rô   r¹   )r"   r#   r$   rI   rŽ   r\   r_   r   r  r  r»   r¼   s   @r*   r  r  c  s‹   ø„ ð
 *.Ø7;ðð -1ñàðð ðð 'ð	ð
 5ðð *ðð 
õð òó ðð òó ðóó&(÷$r)   r  c                  óv   ‡ — e Zd Z	 	 dddœ	 	 	 	 	 	 	 	 	 	 	 d	ˆ fd„Zed
d„«       Zed
d„«       Zdd„Zdd„Zˆ xZ	S )ÚBrowserAgentNr‘   c               ó†   •— t         ‰| �  |||||«       t        | _        t        | _        g | _        | j                  «        y r.   )r“   rI   ÚBROWSER_TASK_REQUESTrU   ÚBROWSER_TASK_COMPLETEDrV   Ú_browsedrc   r—   s         €r*   rI   zBrowserAgent.__init__–  s<   ø€ ô 	‰Ñ˜˜e XÐ/AÀ:ÔNÜ#7ˆÔ Ü%;ˆÔ"Ø.0ˆŒØ�‰Õr)   c                 ó   — y)Nr  r(   r[   s    r*   r\   zBrowserAgent.name¥  rš   r)   c                 ó   — y)NÚbrowserr(   r[   s    r*   r_   zBrowserAgent.role©  r�   r)   c           	   ƒ  óŒ   K  — | j                  | j                  |«      d|j                  d«      ddt        dœt        d¬«      S ­w)a©  Report the browsing capability as unavailable.

        Security rationale: this agent has no browsing backend. It used to
        enqueue a no-op coroutine that returned ``{"status": "browsed"}``, then
        published ``success=True`` with a ``"Browsed <url>"`` summary - a fake
        success report in a product whose whole point is trustworthy verdicts.
        A consumer had no way to tell "inspected the page" from "did nothing",
        and a negative finding that never happened looks exactly like a clean
        one. The agent now refuses every request with an explicit reason,
        records ``execution_attempted=False`` (nothing was attempted), and never
        appends to ``self._browsed``, so absence of evidence can no longer be
        read as evidence of absence.

        The role stays registered so the six-role Ptah topology is unchanged;
        it is a capability stub, not a working browser agent.
        FÚurlÚcapability_unavailableÚbrowsing)r(  rÒ   Ú
capabilityrz   rw   )rx   ry   rK   Ú%BROWSER_CAPABILITY_UNAVAILABLE_REASONr/   s     r*   r   zBrowserAgent.execute­  sS   è ø€ ð" ×"Ñ"Ø×Ñ˜yÓ)Øà —}‘} UÓ+Ø2Ø(Ü?ñ	ô 2Ø %ð #ó 
ð 	
ùs   ‚AAc                ó,   — t        | j                  «      S )z¤Pages actually fetched.

        Always empty: ``BrowserAgent`` has no backend, so nothing is ever
        recorded. Kept so existing callers keep working.
        )r·   r#  r[   s    r*   Úget_browsedzBrowserAgent.get_browsedË  s   € ô �D—M‘MÓ"Ð"r)   r�   r†   rŠ   rŒ   r¹   )
r"   r#   r$   rI   rŽ   r\   r_   r   r.  r»   r¼   s   @r*   r  r  •  s†   ø„ ð
 *.Ø7;ðð -1ñàðð ðð 'ð	ð
 5ðð *ðð 
õð òó ðð òó ðó
÷<#r)   r  )8Ú
__future__r   r¦   ÚloggingÚabcr   r   Údataclassesr   r   Útypingr   r	   Úuuidr
   Úcyberbrain26.control_planer   r   Ú+cyberbrain26.execution_plane.secure_gatewayr   r   Ú$cyberbrain26.security_plane.identityr   Ú&cyberbrain26.security_plane.permissionr   r   Ú	getLoggerr"   rq   r”   r•   rÁ   rÂ   rã   rä   rø   rù   r  r  r!  r"  rN   r±   r´   r,  r   r,   r8   r@   rP   r�   r¾   rá   rö   r  r  r(   r)   r*   ú<module>r:     s<  ðÝ "ã Û ß #ß (ß  Ý ç E÷õ ?ß Sà	ˆ×	Ñ	˜8Ó	$€à-Ð Ø1Ð Ø)Ð Ø-Ð Ø1Ð Ø5Ð Ø/Ð Ø3Ð Ø/Ð Ø3Ð Ø-Ð Ø1Ð à€àÐ Ø€ð,ð &ð ÷%ð %ó ð%ô&E�Xô Eô4˜xô ÷$)
ñ )
ôXT0�ô T0ônM �9ô M ô`z'�ô z'ôz1'�Yô 1'ôh0$�Iô 0$ôf/$�Iô /$ôd<#�9õ <#r)   