Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion .agent/harness/hooks/_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

_CACHED_COMMIT = None
_CACHED_RUN_ID = None
_CACHED_PROFILE = None


def run_id():
Expand All @@ -14,6 +15,41 @@ def run_id():
return _CACHED_RUN_ID


def profile():
"""Return the active harness profile name, or "default" when unknown.

Harnesses that run multiple isolated agent identities against the same
portable brain (e.g. Hermes's --profile flag spawning distinct
specialist agents) should set ``AGENT_PROFILE`` to the active name so
every episodic entry is tagged. Enables cross-profile clustering and
per-specialist retrospectives in the dream cycle.

Fallback detection covers known harnesses without code changes there:
* ``AGENT_PROFILE`` - canonical, any harness.
* ``HERMES_HOME`` - if it points under ``<...>/profiles/<name>``
use that name; otherwise "default".
"""
global _CACHED_PROFILE
if _CACHED_PROFILE is not None:
return _CACHED_PROFILE

explicit = os.environ.get("AGENT_PROFILE", "").strip()
if explicit:
_CACHED_PROFILE = explicit
return _CACHED_PROFILE

hermes_home = os.environ.get("HERMES_HOME", "").rstrip("/")
if hermes_home:
if "/profiles/" in hermes_home:
_CACHED_PROFILE = hermes_home.rsplit("/", 1)[-1]
else:
_CACHED_PROFILE = "default"
return _CACHED_PROFILE

_CACHED_PROFILE = "default"
return _CACHED_PROFILE


def commit_sha():
global _CACHED_COMMIT
if _CACHED_COMMIT is None:
Expand All @@ -30,4 +66,9 @@ def commit_sha():


def build_source(skill):
return {"skill": skill, "run_id": run_id(), "commit_sha": commit_sha()}
return {
"skill": skill,
"profile": profile(),
"run_id": run_id(),
"commit_sha": commit_sha(),
}