Package com.tnsai.hooks
Record Class HookContext
java.lang.Object
java.lang.Record
com.tnsai.hooks.HookContext
- Record Components:
agentId- stable agent idagentClass- fully-qualified class name of the agent rolerole- short role identifier ("researcher")capabilities- declared capability interface names; empty when nonegroupId- group id when the agent runs inside a groupgroupTopology- group topology kind ("HIERARCHICAL", …); empty when not in a groupsessionId- framework session idtenantId- multi-tenant deployments — tenant idtraceId- OTel trace id when an active trace existsspanId- OTel span id when an active span existstranscriptPath- 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)
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionHookContext(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) Creates an instance of aHookContextrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theagentClassrecord component.agentId()Returns the value of theagentIdrecord component.static HookContext.BuilderReturns a builder for incremental construction.Returns the value of thecapabilitiesrecord component.final booleanIndicates whether some other object is "equal to" this one.groupId()Returns the value of thegroupIdrecord component.Returns the value of thegroupTopologyrecord component.final inthashCode()Returns a hash code value for this object.static HookContextConvenience for tests / sample contexts where only the agent identity matters and every other field is empty.role()Returns the value of therolerecord component.Returns the value of thesessionIdrecord component.spanId()Returns the value of thespanIdrecord component.tenantId()Returns the value of thetenantIdrecord component.final StringtoString()Returns a string representation of this record class.traceId()Returns the value of thetraceIdrecord component.Returns the value of thetranscriptPathrecord component.
-
Constructor Details
-
HookContext
public 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) Creates an instance of aHookContextrecord class.- Parameters:
agentId- the value for theagentIdrecord componentagentClass- the value for theagentClassrecord componentrole- the value for therolerecord componentcapabilities- the value for thecapabilitiesrecord componentgroupId- the value for thegroupIdrecord componentgroupTopology- the value for thegroupTopologyrecord componentsessionId- the value for thesessionIdrecord componenttenantId- the value for thetenantIdrecord componenttraceId- the value for thetraceIdrecord componentspanId- the value for thespanIdrecord componenttranscriptPath- the value for thetranscriptPathrecord component
-
-
Method Details
-
minimal
Convenience for tests / sample contexts where only the agent identity matters and every other field is empty. -
builder
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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
agentId
Returns the value of theagentIdrecord component.- Returns:
- the value of the
agentIdrecord component
-
agentClass
Returns the value of theagentClassrecord component.- Returns:
- the value of the
agentClassrecord component
-
role
Returns the value of therolerecord component.- Returns:
- the value of the
rolerecord component
-
capabilities
Returns the value of thecapabilitiesrecord component.- Returns:
- the value of the
capabilitiesrecord component
-
groupId
Returns the value of thegroupIdrecord component.- Returns:
- the value of the
groupIdrecord component
-
groupTopology
Returns the value of thegroupTopologyrecord component.- Returns:
- the value of the
groupTopologyrecord component
-
sessionId
Returns the value of thesessionIdrecord component.- Returns:
- the value of the
sessionIdrecord component
-
tenantId
Returns the value of thetenantIdrecord component.- Returns:
- the value of the
tenantIdrecord component
-
traceId
Returns the value of thetraceIdrecord component.- Returns:
- the value of the
traceIdrecord component
-
spanId
Returns the value of thespanIdrecord component.- Returns:
- the value of the
spanIdrecord component
-
transcriptPath
Returns the value of thetranscriptPathrecord component.- Returns:
- the value of the
transcriptPathrecord component
-