Documentation
¶
Overview ¶
Package hook defines the in-process interception contracts for bounded Harness runtime operations.
Index ¶
- func Deny(code, reason string) error
- func ValidateCall(call Call) error
- func ValidateSet(set Set) error
- type Around
- type BeginFunc
- type Call
- type CallError
- type CallErrorKind
- type CloneError
- type CloneErrorKind
- type CompactionData
- type ConfigError
- type ConfigErrorKind
- type Denial
- type FinishFunc
- type GateWaitData
- type Guard
- type GuardError
- type GuardFunc
- type InferenceData
- type JournalAppendData
- type Operation
- type Outcome
- type RecordFamily
- type Result
- type Runner
- type Set
- type StepData
- type StepIndex
- type ToolCallData
- type ToolExecutionData
- type TurnData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deny ¶
Deny constructs an intentional denial or returns ConfigError when its diagnostic fields violate the bounded public contract.
func ValidateCall ¶
ValidateCall validates the closed operation-payload union.
Types ¶
type BeginFunc ¶
BeginFunc begins observation of an operation and returns its derived context and optional terminal callback. A returned context may add values or tighter cancellation, but Runner preserves cancellation and deadlines from the input context even if the returned context is detached.
type Call ¶
type Call struct {
// Operation selects the one matching operation-specific payload below.
Operation Operation
// StartedAt is the runtime-owned operation start time.
StartedAt time.Time
// Coordinates locate the operation in the session/loop/turn/step hierarchy.
Coordinates identity.Coordinates
// AgentName is the immutable attribution name of the executing loop.
AgentName identity.AgentName
// Cause is the direct causal edge that initiated the operation.
Cause identity.Cause
// Exactly one pointer below is non-nil and matches Operation.
Turn *TurnData
Step *StepData
Inference *InferenceData
Compaction *CompactionData
ToolCall *ToolCallData
GateWait *GateWaitData
ToolExecution *ToolExecutionData
JournalAppend *JournalAppendData
}
Call is the immutable typed snapshot supplied when an operation begins. Exactly one operation-specific payload must be non-nil and match Operation.
type CallError ¶
type CallError struct {
Kind CallErrorKind
Operation Operation
}
CallError reports a malformed runtime operation snapshot.
type CallErrorKind ¶
type CallErrorKind string
CallErrorKind identifies a malformed operation call snapshot.
const ( CallUnknownOperation CallErrorKind = "unknown_operation" CallInvalidPayload CallErrorKind = "invalid_payload" )
type CloneError ¶
type CloneError struct {
Kind CloneErrorKind
ValueType string
}
CloneError reports a sealed content variant the hook snapshot clone does not yet support. CloneCall panics with this error rather than silently losing data.
func (*CloneError) Error ¶
func (e *CloneError) Error() string
type CloneErrorKind ¶
type CloneErrorKind string
CloneErrorKind identifies the sealed union that gained an unsupported variant.
const ( CloneUnknownConversation CloneErrorKind = "unknown_conversation" CloneUnknownBlock CloneErrorKind = "unknown_block" )
type CompactionData ¶
type CompactionData struct {
// AttemptID correlates the operation with compaction lifecycle events.
AttemptID event.CompactAttemptID
// Input is the exact transcript and context identity being compacted.
Input *loop.CompactionInput
// Output is the validated summary, when compaction succeeds.
Output *loop.CompactionOutput
}
CompactionData carries one transcript-compaction attempt and its optional terminal summary.
type ConfigError ¶
type ConfigError struct {
Kind ConfigErrorKind
Operation Operation
Index int
Field string
}
ConfigError reports invalid hook-set or denial configuration.
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
type ConfigErrorKind ¶
type ConfigErrorKind string
ConfigErrorKind identifies an invalid hook declaration or typed payload.
const ( ConfigUnknownOperation ConfigErrorKind = "unknown_operation" ConfigOperationNotGuardable ConfigErrorKind = "operation_not_guardable" ConfigNilGuard ConfigErrorKind = "nil_guard" ConfigNilAround ConfigErrorKind = "nil_around" ConfigMissingPolicyRevision ConfigErrorKind = "missing_policy_revision" ConfigUnexpectedPolicyRevision ConfigErrorKind = "unexpected_policy_revision" ConfigInvalidPolicyRevision ConfigErrorKind = "invalid_policy_revision" ConfigInvalidDenial ConfigErrorKind = "invalid_denial" )
type Denial ¶
Denial is an intentional, bounded guard refusal.
type FinishFunc ¶
type FinishFunc func(Result)
FinishFunc observes the terminal result of an operation.
type GateWaitData ¶
type GateWaitData struct {
// GateID identifies the gate being awaited.
GateID gate.ID
// Kind identifies the user-facing gate scenario.
Kind gate.Kind
// Resolver identifies the component responsible for resolving the gate.
Resolver gate.ResolverKind
// Blocks identifies the execution scope held by the gate.
Blocks gate.Blocks
// Effect identifies what resolution does to execution.
Effect gate.Effect
// Answer is the validated live answer, when one was delivered.
Answer *gate.Answer
}
GateWaitData describes the time spent waiting for one gate resolution.
type GuardError ¶
GuardError reports an internal guard callback failure. Intentional denials are returned as validated *Denial values instead.
func (*GuardError) Error ¶
func (e *GuardError) Error() string
func (*GuardError) Unwrap ¶
func (e *GuardError) Unwrap() error
Unwrap exposes the trusted in-process cause for classification.
type InferenceData ¶
type InferenceData struct {
// Request is the provider-neutral request submitted to inference.
Request *inference.Request
// AIMessage is the completed assistant message, when produced.
AIMessage *content.AIMessage
// StreamResult is authoritative terminal provider metadata, when produced.
StreamResult *stream.StreamResult
}
InferenceData carries the provider-neutral request and terminal model output. Terminal fields are nil until their corresponding values exist.
type JournalAppendData ¶
type JournalAppendData struct {
// Family is the closed record family.
Family RecordFamily
// RecordID is the record's bounded textual identity.
RecordID string
}
JournalAppendData describes one bounded durable append without exposing serialized record bytes.
type Operation ¶
type Operation uint8
Operation identifies one bounded runtime operation.
type RecordFamily ¶
type RecordFamily string
RecordFamily identifies the bounded journal record family being appended.
const ( RecordEvent RecordFamily = "event" RecordCommand RecordFamily = "command" RecordGatePrepared RecordFamily = "gate_prepared" RecordFence RecordFamily = "fence" // RecordCommandApplication is the private prefix correlating a public CommandID // with the RuntimeCommandID and lease epoch of its application. RecordCommandApplication RecordFamily = "command_application" )
type Result ¶
type Result struct {
Call
// EndedAt is the runtime-owned operation completion time.
EndedAt time.Time
// Outcome is the bounded terminal classification.
Outcome Outcome
// Err is the original trusted in-process terminal error and is not
// deep-cloned. Consumers must redact or classify it before exporting it to
// logs, telemetry, or another trust boundary.
Err error
}
Result is the terminal snapshot supplied to an around hook.
func CloneResult ¶
CloneResult clones the embedded Call while intentionally retaining Err.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner is an immutable, compiled hook set safe for concurrent dispatch.
func Compile ¶
Compile validates a hook set and takes independent ownership of its registration slices.
func (*Runner) Handles ¶
Handles reports whether the compiled runner has a guard or observer for operation. It is nil-safe and lets operation boundaries skip snapshot and clock work when no callback can run.
func (*Runner) Start ¶
Start begins observation and evaluates policy for one valid operation call. Matching begin callbacks run in registration order with chained contexts, followed by matching guards in registration order. Every callback receives an independent snapshot.
Observer panics are logged without callback-owned details and fail open. A guard or denial-classification panic fails closed as *GuardError. A validated intentional denial is returned as *Denial; every other guard failure is returned as *GuardError.
The returned FinishFunc runs completed observers in reverse registration order exactly once, including when a guard blocks. Every non-nil context returned by Begin keeps its values and tighter cancellation while also preserving cancellation and deadlines from the previous context. Calling Finish releases the resources used to bridge detached contexts, even when no observer returned its own finish callback. The caller must therefore always invoke Finish and supply a valid Result for the same operation with a valid terminal Outcome.
type Set ¶
type Set struct {
// PolicyRevision identifies behavior implemented by Guards. It is required
// when Guards is non-empty and forbidden otherwise; Around observers are
// operational configuration and do not contribute to policy identity.
PolicyRevision string
// Guards run in registration order at guardable operation boundaries.
Guards []Guard
// Around observers begin in registration order and finish in reverse order.
Around []Around
}
Set is an ordered collection of guards and around observers. A Set and its backing slices are immutable after installation. Callbacks may run concurrently for different operations and must be concurrency-safe; Call and Result arguments are read-only snapshots.
type StepData ¶
type StepData struct {
// Index is the step's zero-based turn-local index.
Index StepIndex
}
StepData describes one bounded inference/tool step within a turn.
type ToolCallData ¶
type ToolCallData struct {
// ToolExecutionID is the runtime-minted identity for this attempted call.
ToolExecutionID uuid.UUID
// ToolUseID is the model-supplied call identity.
ToolUseID string
// ToolName is the normalized invoked tool name.
ToolName string
// Summary is the bounded, redacted call summary.
Summary string
// ArgsJSON is the raw model-supplied argument object.
ArgsJSON json.RawMessage
// PermissionEffect is the terminal approve/deny decision, when known.
PermissionEffect event.PermissionDecisionEffect
// PermissionReason is the bounded decision reason.
PermissionReason string
// Result is the normalized terminal tool result, including pre-execution
// failures, when the semantic call has completed.
Result *tool.ToolResult
// ResultPreview is the bounded terminal tool-output preview.
ResultPreview string
// IsError reports whether the semantic call ended in an error.
IsError bool
}
ToolCallData describes the semantic tool-call operation, including permission resolution and its normalized terminal result.
type ToolExecutionData ¶
type ToolExecutionData struct {
// ToolExecutionID is the runtime-minted identity for this execution.
ToolExecutionID uuid.UUID
// ToolUseID is the model-supplied call identity.
ToolUseID string
// ToolName is the normalized invoked tool name.
ToolName string
// ArgsJSON is the raw model-supplied argument object.
ArgsJSON json.RawMessage
// Result is the tool's terminal content, when produced.
Result *tool.ToolResult
// ResultPreview is the bounded terminal output preview.
ResultPreview string
// IsError reports whether execution ended in an error.
IsError bool
}
ToolExecutionData describes only the approved tool execution boundary.