scenario

package
v1.261022.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: MPL-2.0 Imports: 10 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindingOptions

func BindingOptions(ev Event) map[string]any

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

type AuditFunc func(action string, fields map[string]any)

AuditFunc is the audit callback the runtime emits to. Production wiring (server.RuntimeAuditSink) logs through the regular application 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 NewRouteRuntime added in v0.260806.1

func NewRouteRuntime(channels *channel2.Registry, routes access.RouteResolver, authorizer access.Authorizer, audit AuditFunc) *DefaultRuntime

func (*DefaultRuntime) Ask

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

Notify pushes a one-way message asynchronously. Errors are logged (the source has already responded by the time delivery happens).

func (*DefaultRuntime) Resolve

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

func (o Outcome) IsInteractive() bool

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.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty registry.

func (*Registry) Get

func (r *Registry) Get(name string) (Scenario, bool)

Get returns the scenario for name and whether one is registered.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the registered scenario names. Order is not guaranteed.

func (*Registry) Register

func (r *Registry) Register(s Scenario)

Register adds (or replaces) a scenario. nil and unnamed scenarios are ignored to keep call sites concise.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL