C-2: a node follows its licence binding by binding.changed and a first view (issue 1409)

The agent module consumes the manager's binding.changed, acting only on the
one naming its node's consumer, and each time it hears those events anew asks
the seat's bindings for its own consumer as its first view; its read of the
manager's bindings state goes.

Builds: design 39 bus-and-switch §22, B9, B10, B22

Claude-Session: https://claude.ai/code/session_01NcbgfHb9d4T9nq5Q6WqdiJ
This commit is contained in:
2026-11-11 23:44:12 +01:00
parent 110c631b5f
commit 6eccfc286a
6 changed files with 140 additions and 30 deletions
@@ -455,6 +455,55 @@ func OnBinding(p Paths, b *BindingState, ask Ask, write WriteManaged) (string, e
return string(raw), nil
}
// BindingChanged is the manager's event of a binding written or deleted (design 39 bus-and-switch §21), which this
// module consumes (§22).
const BindingChanged = Manager + ".binding.changed"
// bindingOf is a consumer's binding as the manager says it, in binding.changed and in the verb bindings' answer: an
// empty licence is a release (B22: decoded from a copy of the writer's form, testdata/binding-changed.json).
type bindingOf struct {
Consumer string `json:"consumer"`
BindingState
}
func (b bindingOf) state() *BindingState {
if b.Licence == "" {
return nil
}
return &b.BindingState
}
// OnBindingChanged takes one binding.changed: acted on only when it names this node's consumer (§22).
func OnBindingChanged(p Paths, body []byte, ask Ask, write WriteManaged) (string, error) {
var b bindingOf
if err := json.Unmarshal(body, &b); err != nil {
return "", fmt.Errorf("%s is not a binding's change: %w", BindingChanged, err)
}
if b.Consumer != p.Node {
return "", nil
}
return OnBinding(p, b.state(), ask, write)
}
// FirstBinding asks the seat's verb bindings for this node's consumer, its first view (§22, B10), and applies it: at
// the module's start, and again whenever it hears the manager's events anew.
func FirstBinding(p Paths, ask Ask, write WriteManaged) (string, error) {
raw, err := ask(SeatVerb("bindings"), map[string]any{"consumer": p.Node})
if err != nil {
return "", err
}
var listed []bindingOf
if err := json.Unmarshal(raw, &listed); err != nil {
return "", fmt.Errorf("the seat's bindings answered what is not a list of bindings: %w", err)
}
for _, b := range listed {
if b.Consumer == p.Node {
return OnBinding(p, b.state(), ask, write)
}
}
return OnBinding(p, nil, ask, write)
}
// Apply applies what the seat handed over. A switch replaces the grant whole and cleans up after the old
// licence; whatever it is, the file is written without a refresh token, so the agent here never refreshes.
func Apply(p Paths, c Current, write WriteManaged) (map[string]any, error) {