File size: 1,244 Bytes
aa73ff9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Classification-only canonical view. NEVER execute the returned command field.

The actual proposed command is preserved in proposed_command_original. This is
not an execution rewrite or permission decision. Input must be a raw tool state.
"""
from command_normalizer_v2 import normalize_state as add_static_view

VERSION='canonical-static-wrappers-v2'
DERIVED={'static_command_view','static_execution_chain','static_view_origin','proposed_command_original'}


def normalize_state(state):
    raw={k:v for k,v in state.items() if k not in DERIVED}
    viewed=add_static_view(raw)
    result={}
    for key in ('tool','command'):
        if key in raw:result[key]=raw[key]
    if 'static_command_view' in viewed:
        result['command']=viewed['static_command_view']
        result['static_execution_chain']=viewed['static_execution_chain']
    for key in ('trusted_user_request','execution_host','environment','trusted_context','untrusted_tool_output'):
        if key in raw:result[key]=raw[key]
    for key,value in raw.items():
        if key not in result:result[key]=value
    if 'static_command_view' in viewed:
        result['proposed_command_original']=raw['command']
        result['static_view_origin']=VERSION
    return result