
    Ki_                        U d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZ 	 d	 	 	 	 	 	 	 ddZh d	Zd
ed<   ddZdddZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)z&Shared utilities for tool sub-modules.    )annotations)Path)Any   )
GraphStore)find_project_rootget_db_pathc                    || | d|S )z)Build a standardised error response dict.)statuserrorsummary )messager   extras      k/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/code_review_graph/tools/_common.py_error_responser      s     w7LeLL    >   atisitofonabsallanydirendgethaslogmapmaxminnowoffpoppowsetbindcallceilemitfillfindflatfrominfojoinjsonkeysmocknextoncepipepushracereadsendsomesortsqrttestthentimetrimwarnapplycatchclearclosecountdebugr   everyfetchfloorisNaNmatchparseroundshiftslicesplitspyOntabletracewriteassertassigncharAtconcatcreatedeleteexpectfilterfreezepadEndrandomreducerejectrepeatsearchsplicer   substrtoJSONupdateupsertvaluesdestroyentriesfinallyflatMapforEachgetTimegroupByindexOfisArrayreplacerequireresolvereversetimeEndtoFixedtrimEndunshiftvalueOfafterAlldescribeendsWithfindManyincludesmatchAllpadStartparseIntredirecttoString	afterEach	aggregate	beforeAll	findFirst	findIndex	stringify	substring	trimStart
allSettled
beforeEach
charCodeAt
createMany
deleteMany
findUnique
parseFloat
replaceAll
setTimeout
startsWith
updateManyappendChildfromEntriesgetFullYearlastIndexOfreduceRightremoveChildsetIntervaltoISOStringtoLowerCasetoUpperCasetransactionclearTimeoutgetAttributesetAttributeclearIntervalcreateElementquerySelectordefinePropertygetElementByIdhasOwnPropertypreventDefaultstopPropagationaddEventListenerquerySelectorAlldecodeURIComponentencodeURIComponentgetOwnPropertyNamesremoveEventListenerzset[str]_BUILTIN_CALL_NAMESc                    | j                         }|j                         st        d|       |dz  j                         s!|dz  j                         st        d|       |S )zValidate that a path is a plausible project root.

    Ensures the path is an existing directory that contains a ``.git``
    or ``.code-review-graph`` directory, preventing arbitrary file-system
    traversal via the ``repo_root`` parameter.
    z(repo_root is not an existing directory: z.gitz.code-review-graphz]repo_root does not look like a project root (no .git or .code-review-graph directory found): )ry   is_dir
ValueErrorexists)pathresolveds     r   _validate_repo_rootr   =   sw     ||~H??6xjA
 	
 v%%'<P1P0X0X0Z44<:?
 	
 Or   Nc                r    | rt        t        |             n	t               }t        |      }t	        |      |fS )z+Resolve repo root and open the graph store.)r   r   r   r	   r   )	repo_rootrootdb_paths      r   
_get_storer   Q   s3    3<tI/BSBUD$Gg$$r   c                    d| d}|r|dd |d<   |dk7  r||d<   |r|dd |d	<   |r|dd |d
<   |r|dd |d<   |dk7  r|r||d<   |S )z6Standard compact response format for token efficiency.ok)r   r   N
   key_entitiesunknownrisk   communitiesflows_affected   next_tool_suggestionsminimaldatar   )	r   r   r   r   r   r   r   detail_levelresps	            r   compact_responser   X   s     D +CR0^yV)"1o]!/!3(=bq(A$%y TVKr   )r   )r   strr   r   r   r   returndict[str, Any])r   r   r   r   )N)r   z
str | Noner   ztuple[GraphStore, Path])Nr   NNNNr   )r   r   r   list[str] | Noner   r   r   r   r   r   r   r   r   zdict[str, Any] | Noner   r   r   r   )__doc__
__future__r   pathlibr   typingr   graphr   incrementalr   r	   r   r   __annotations__r   r   r   r   r   r   <module>r      s    , "    8 !(MMM25MM$! X $N(% &*$('+.2"&!"  "	
 % ,    r   