
    p#jt                    h    d Z ddlmZ ddlmZ ddlmZ  ee          j        j        dz  Z	dddZ
dS )u  
Baked-in build metadata for Hermes Agent.

Source installs report their git revision live via ``git rev-parse`` (see
``hermes_cli/dump.py`` and ``hermes_cli/banner.py``).  That doesn't work inside
the published Docker image because ``.dockerignore`` excludes ``.git``, so
those callsites fall back to ``"(unknown)"`` / drop the banner suffix entirely.

To make ``hermes dump`` and the startup banner identify the exact commit the
image was built from, the Docker build writes the build-time ``$HERMES_GIT_SHA``
arg into ``<project_root>/.hermes_build_sha``.  This module is the single
read-side helper consumed by both callsites — keeping the lookup in one place
so the file path and missing-file behaviour stay consistent.

Behaviour:

- Returns ``None`` when the file is absent.  Source installs and dev images
  built without the ``HERMES_GIT_SHA`` build-arg fall through to live-git
  resolution in the caller, so non-Docker installs are unaffected.
- Returns ``None`` on any IO / decoding error.  The build-sha is a nice-to-have
  for support triage; nothing in the CLI is allowed to crash because of it.
- Truncates to ``short`` characters (default 8) to match the format used by
  ``git rev-parse --short=8`` throughout the codebase.
    )annotations)Path)Optionalz.hermes_build_sha   shortintreturnOptional[str]c                    	 t                                           sdS t                               d                                          }n# t          $ r Y dS w xY w|sdS | r| dk    r
|d|          n|S )a  Return the baked-in build SHA, truncated to ``short`` chars, or None.

    Reads ``<project_root>/.hermes_build_sha`` if present.  The file is
    written by the Dockerfile's ``HERMES_GIT_SHA`` build-arg and contains
    the full 40-character commit hash on a single line.
    Nzutf-8)encodingr   )_BUILD_SHA_FILEis_file	read_textstrip	Exception)r   shas     :/home/ubuntu/.hermes/hermes-agent/hermes_cli/build_info.pyget_build_shar   $   s    &&(( 	4'''99??AA   tt t6EAII3vv;;36s   A -A 
AAN)r   )r   r   r	   r
   )__doc__
__future__r   pathlibr   typingr   __file__parentr   r        r   <module>r      s    2 # " " " " "             $x..'.1DD7 7 7 7 7 7 7r   