
    "j                    @    d Z ddlmZ ddlZddlZdZdZdZd	dZd
dZ	y)u  v3.6 Runtime Harness — append-only JSONL decision logger.

chair_authorization_id=CHAIR-AUTH-TASK-2703-V36-HARNESS-MVP-260528

Design:
- Append-only; never truncates or rewrites.
- Fail-safe: any exception is silently swallowed — logger must NEVER raise.
- ALLOW decisions only recorded when env V36_HARNESS_LOG_ALLOW=1.
- Test isolation: when env ANU_V36_HARNESS_TEST_MODE=1, writes to /tmp/v36_harness_decision_test.jsonl.
    )annotationsNz+CHAIR-AUTH-TASK-2703-V36-HARNESS-MVP-260528z=/home/jay/workspace/memory/system/.v36_harness_decision.jsonlz$/tmp/v36_harness_decision_test.jsonlc                 `    t         j                  j                  dd      dk(  rt        S t        S )NANU_V36_HARNESS_TEST_MODE 1)osenvironget_TEST_JSONL_PRODUCTION_JSONL     1/home/jay/workspace/scripts/harness/v36/logger.py_jsonl_pathr      s&    	zz~~126#=r   c                2   	 | j                  dd      }|dk(  r$t        j                  j                  dd      dk7  ryt        |       }|j	                  dt
               t               }t        j                  t        j                  j                  |      rt        j                  j                  |      ndd	
       t        |dd      5 }|j                  t        j                  |d      dz          ddd       y# 1 sw Y   yxY w# t        $ r Y yw xY w)aM  Append a decision record to the JSONL audit log.

    Args:
        decision_record: dict with at minimum keys: ts, decision, matched_rule,
                         command_or_tool, task_id, timestamp.

    Silently swallows all exceptions (fail-safe contract).
    ALLOW decisions are only written when V36_HARNESS_LOG_ALLOW=1.
    decisionr   ALLOWV36_HARNESS_LOG_ALLOWr   Nchair_authorization_id.T)exist_okazutf-8)encodingF)ensure_ascii
)r
   r   r	   dict
setdefaultCHAIR_AUTHORIZATION_IDr   makedirspathdirnameopenwritejsondumps	Exception)decision_recordr   recordr    fhs        r   log_decisionr*      s    "&&z26 wzz~~5r:cA o&24JK}
RWW__T-BBGGOOD)VZ[$g. 	D"HHTZZU;dBC	D 	D 	D s5   :D
 BD
 *C>5D
 >DD
 D
 
	DD)returnstr)r'   r   r+   None)
__doc__
__future__r   r$   r   r   r   r   r   r*   r   r   r   <module>r0      s0   	 #  	F S 4r   