Record Class HookContext

java.lang.Object
java.lang.Record
com.tnsai.hooks.HookContext
Record Components:
agentId - stable agent id
agentClass - fully-qualified class name of the agent role
role - short role identifier ("researcher")
capabilities - declared capability interface names; empty when none
groupId - group id when the agent runs inside a group
groupTopology - group topology kind ("HIERARCHICAL", …); empty when not in a group
sessionId - framework session id
tenantId - multi-tenant deployments — tenant id
traceId - OTel trace id when an active trace exists
spanId - OTel span id when an active span exists
transcriptPath - on-disk transcript file path when one is being written

public record HookContext(String agentId, String agentClass, String role, List<String> capabilities, Optional<String> groupId, Optional<String> groupTopology, Optional<String> sessionId, Optional<String> tenantId, Optional<String> traceId, Optional<String> spanId, Optional<Path> transcriptPath) extends Record
Per-event context attached to every HookEvent so a hook implementation has the full surrounding scope without having to fish it out of thread-local state (issue #58).

Mirrors the dimensions that EventContext already carries for observability — kept as a separate record (rather than reusing EventContext) because hook events fire at intercept points that need additional surface like the role + capability list, group topology, and on-disk transcript path that the logging context doesn't carry.

All collection / Optional fields are non-null after construction; unknown values use Optional.empty() or empty collections so downstream switch / pattern-match doesn't have to null-check.

Since:
0.5.0 (issue #58)
  • Constructor Details

  • Method Details

    • minimal

      public static HookContext minimal(String agentId, String agentClass, String role)
      Convenience for tests / sample contexts where only the agent identity matters and every other field is empty.
    • builder

      public static HookContext.Builder builder(String agentId, String agentClass, String role)
      Returns a builder for incremental construction. Reading thread-local state and stamping every Optional inline is verbose; the builder keeps the call sites small.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • agentId

      public String agentId()
      Returns the value of the agentId record component.
      Returns:
      the value of the agentId record component
    • agentClass

      public String agentClass()
      Returns the value of the agentClass record component.
      Returns:
      the value of the agentClass record component
    • role

      public String role()
      Returns the value of the role record component.
      Returns:
      the value of the role record component
    • capabilities

      public List<String> capabilities()
      Returns the value of the capabilities record component.
      Returns:
      the value of the capabilities record component
    • groupId

      public Optional<String> groupId()
      Returns the value of the groupId record component.
      Returns:
      the value of the groupId record component
    • groupTopology

      public Optional<String> groupTopology()
      Returns the value of the groupTopology record component.
      Returns:
      the value of the groupTopology record component
    • sessionId

      public Optional<String> sessionId()
      Returns the value of the sessionId record component.
      Returns:
      the value of the sessionId record component
    • tenantId

      public Optional<String> tenantId()
      Returns the value of the tenantId record component.
      Returns:
      the value of the tenantId record component
    • traceId

      public Optional<String> traceId()
      Returns the value of the traceId record component.
      Returns:
      the value of the traceId record component
    • spanId

      public Optional<String> spanId()
      Returns the value of the spanId record component.
      Returns:
      the value of the spanId record component
    • transcriptPath

      public Optional<Path> transcriptPath()
      Returns the value of the transcriptPath record component.
      Returns:
      the value of the transcriptPath record component