Documentation
¶
Overview ¶
Package scenario defines the back-end plugin contract of the remote middle layer. A Scenario is a named provider of "content" that flows through a Channel to a human (Claude Code hooks, agent chat, future PR-review or CI-gate plugins).
Plugins receive an Event from a Source (HTTP, in-process, future RPC) and use a Runtime to resolve channels, send notifications, ask questions, and emit audit records. The Outcome the plugin returns drives the Source's response (e.g. the notify HTTP endpoint maps non-empty InteractionID to a 202 + wait URL).
Index ¶
- func BindingOptions(ev Event) map[string]any
- type AuditFunc
- type DefaultRuntime
- func (r *DefaultRuntime) Ask(ctx context.Context, ch channel2.Channel, target channel2.Target, ...) (interaction.Reply, error)
- func (r *DefaultRuntime) Audit(action string, fields map[string]any)
- func (r *DefaultRuntime) Notify(ctx context.Context, ch channel2.Channel, target channel2.Target, ...) error
- func (r *DefaultRuntime) Resolve(_ context.Context, ev Event) (channel2.Channel, channel2.Target, bool, error)
- type Event
- type Outcome
- type Registry
- type Runtime
- type Scenario
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindingOptions ¶
BindingOptions returns the resolved binding's free-form options map from the event Meta, or nil if Resolve has not been called yet. Plugins use this to read scenario-specific settings (e.g. permission policy) without a second store lookup.
Types ¶
type AuditFunc ¶
AuditFunc is the audit callback the runtime emits to. Production wiring connects this to the audit.Logger; tests can pass a closure that records into a slice.
type DefaultRuntime ¶
type DefaultRuntime struct {
// contains filtered or unexported fields
}
DefaultRuntime is the production Runtime backed by a channel.Registry, a binding.Resolver, and an optional AuditFunc.
func NewDefaultRuntime ¶
func NewDefaultRuntime(channels *channel2.Registry, bindings *binding.Resolver, audit AuditFunc) *DefaultRuntime
NewDefaultRuntime wires the runtime to its dependencies. audit may be nil (Audit becomes a no-op).
func (*DefaultRuntime) Ask ¶
func (r *DefaultRuntime) Ask(ctx context.Context, ch channel2.Channel, target channel2.Target, ix interaction.Interaction) (interaction.Reply, error)
Ask blocks on the channel's Prompt until a reply arrives or the context fires.
func (*DefaultRuntime) Audit ¶
func (r *DefaultRuntime) Audit(action string, fields map[string]any)
Audit records a structured event when an audit sink is wired.
func (*DefaultRuntime) Notify ¶
func (r *DefaultRuntime) Notify(ctx context.Context, ch channel2.Channel, target channel2.Target, msg interaction.Notification) error
Notify pushes a one-way message asynchronously. Errors are logged (the source has already responded by the time delivery happens).
func (*DefaultRuntime) Resolve ¶
func (r *DefaultRuntime) Resolve(_ context.Context, ev Event) (channel2.Channel, channel2.Target, bool, error)
Resolve matches the event to a registered channel via the binding resolver. ok=false means no binding (the source falls back); err is non-nil only on store / configuration faults.
type Event ¶
type Event struct {
// Source is one of "http", "inproc", or future "rpc" markers.
Source string
// Scenario is the registered plugin name (matches the URL path
// parameter in /tingly/:scenario/notify).
Scenario string
// Payload is the raw event data as a JSON-friendly map.
Payload map[string]any
// Meta carries cross-cutting hints (request id, trace id, …).
Meta map[string]any
}
Event is a normalized trigger handed to a Scenario. Source identifies where the trigger originated; Payload carries the original event shape (e.g. the Claude Code hook JSON marshaled to a map).
type Outcome ¶
type Outcome struct {
Handled bool
InteractionID string
ExpiresAt time.Time
Decision map[string]any
Reason string
}
Outcome is the synchronous result of Scenario.Trigger.
Handled tells the source whether the plugin took ownership of this event. False means the plugin chose not to handle (e.g. no binding): the source may fall through to a default behavior such as a desktop notification.
If InteractionID is non-empty the plugin has spawned an asynchronous producer (typically an Ask goroutine) and the source should hand the caller a wait URL keyed on that ID. The actual decision is delivered later via interaction.Registry.Resolve and surfaced through the long- poll endpoint. Handled is implicitly true in this case.
If InteractionID is empty and Handled is true the trigger was push- only (no human reply expected) and Decision is the immediate response the source may surface.
func (Outcome) IsInteractive ¶
IsInteractive reports whether the outcome started an asynchronous interaction (the source should reply 202 + wait URL).
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps scenario names to their plugin implementations.
type Runtime ¶
type Runtime interface {
// Resolve returns the channel + target the event should be routed
// to, based on the bound binding for the scenario. ok=false means
// no binding exists for this event (the source should fall back).
Resolve(ctx context.Context, ev Event) (channel.Channel, channel.Target, bool, error)
// Notify pushes a one-way message to the channel. It is best-effort
// fire-and-forget; the caller does not block on delivery.
Notify(ctx context.Context, ch channel.Channel, target channel.Target, msg interaction.Notification) error
// Ask runs an interactive prompt synchronously. The returned Reply
// is the human's response (or an error on cancel/timeout/transport
// failure). Scenarios typically call this from a goroutine they
// spawned in Trigger.
Ask(ctx context.Context, ch channel.Channel, target channel.Target, ix interaction.Interaction) (interaction.Reply, error)
// Audit emits a structured audit record for the action.
Audit(action string, fields map[string]any)
}
Runtime is what scenarios see at execution time. The interface is deliberately minimal: scenarios should not reach for global state directly; they ask the runtime for channels, push notifications, run interactive prompts, and emit audit records.
type Scenario ¶
type Scenario interface {
// Name is the unique identifier (matches /tingly/:scenario URL).
Name() string
// Trigger handles one event. The call should return promptly; long-
// running interactive flows must be spawned in a goroutine that
// resolves the matching interaction.Registry entry.
Trigger(ctx context.Context, ev Event, rt Runtime) (Outcome, error)
}
Scenario is the plugin contract. Implementations must be safe for concurrent Trigger calls.
Directories
¶
| Path | Synopsis |
|---|---|
|
builtin
|
|
|
claudecode
Package claudecode implements the Claude Code hook scenario plugin.
|
Package claudecode implements the Claude Code hook scenario plugin. |