A bundle's ask of seat:mesh-wants.input reached the holder with no `call` and was refused ("call is one token of 16 to 64 ..."), so no
composition step passed: the runner chooses the call only for a verb its seat list says sends chunks, and a verb the list did not name
(a list read once, unread, or stale) was taken for one that does not. chunkedAsked reads the list again once and, where the verb is still
not named, refuses the ask saying why. A first read of the list that ended without an answer is now said in the log.
Builds: design 47 G A-249 (the runner receives a chunked seat answer for the bundle), ADR 0636 §1 (the seat list is read, not guessed)
Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
139 lines
5.6 KiB
Go
139 lines
5.6 KiB
Go
package runtime
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/approval"
|
|
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
|
|
|
"github.com/novox/mesh-tools/node-tools/internal/launch"
|
|
)
|
|
|
|
// FingerprintWord is the word of a module's composed environment that names the build its bundle serves (design 47 G §424).
|
|
const FingerprintWord = "MESH_FINGERPRINT"
|
|
|
|
// Gate is the approval gate the runner serves through (design 46 7-approval-mark §4, §20; node-tools/internal/approval).
|
|
type Gate interface {
|
|
// Unserved is, of a module's marked tools, those its bundle does not register, saying it as the module's finding.
|
|
Unserved(module, fingerprint string, registered []string) []string
|
|
// Run is a call through the gate: run is called only when the call may run now, once.
|
|
Run(call approval.Call, run func() (any, error)) (any, error)
|
|
// Approvals is the seat verb `approvals` for a caller: the calls the gate holds, its acts and claims (A-265, A-271).
|
|
Approvals(caller string) (approval.Approvals, error)
|
|
}
|
|
|
|
// gatedRun is how a handler calls a tool: through the gate where there is one.
|
|
type gatedRun func(call approval.Call, t launch.Tool, caller string) (any, error)
|
|
|
|
// gated calls the tool through the gate, or straight where the runner has none.
|
|
func (c *consumers) gated(call approval.Call, t launch.Tool, caller string) (any, error) {
|
|
run := func() (any, error) { return t.Run(caller, call.Args) }
|
|
if c.gate == nil {
|
|
return run()
|
|
}
|
|
return c.gate.Run(call, run)
|
|
}
|
|
|
|
// approvalsOf is how the runner answers a held seat's verb `approvals`: from its gate's record, nil without a gate.
|
|
func (r *runner) approvalsOf() func(caller string) (any, error) {
|
|
if r.events.gate == nil {
|
|
return nil
|
|
}
|
|
return func(caller string) (any, error) { return r.events.gate.Approvals(caller) }
|
|
}
|
|
|
|
// WithGate serves every call through the approval gate.
|
|
func WithGate(g Gate) Option { return func(c *consumers) { c.gate = g } }
|
|
|
|
var _ Gate = (*approval.Gate)(nil)
|
|
|
|
// WithSeatDefinitions refuses, where a seat's verb is answered, a caller outside the verb's effective callers, before the
|
|
// bundle runs (design 47 G §610; lead answers A-165, A-179): defs are the seat definitions the runner's seat list holds.
|
|
// Without it a verb is answered for every caller, as before.
|
|
func WithSeatDefinitions(defs func() map[string]seatdef.Definition) Option {
|
|
return func(c *consumers) { c.definitions = defs }
|
|
}
|
|
|
|
// admitted says why a seat's verb is refused to a caller: never. Every caller is admitted, whether or not the seat's definition
|
|
// is read and whatever callers it names (the operator, 2026-11-15 23:25 CET: every module, agent and operator may call anything;
|
|
// approval stays as the mark on a verb, held by the gate).
|
|
func (c *consumers) admitted(seat, verb, caller string) error { return nil }
|
|
|
|
// unservedMarks is, of the module's marked tools, those its bundle's registrations under its own name do not register.
|
|
func (r *runner) unservedMarks(module string, regs []launch.Registration) []string {
|
|
if r.events.gate == nil {
|
|
return nil
|
|
}
|
|
var registered []string
|
|
for _, reg := range regs {
|
|
if reg.Module == module {
|
|
for _, t := range reg.Tools {
|
|
registered = append(registered, t.Name)
|
|
}
|
|
}
|
|
}
|
|
return r.events.gate.Unserved(module, r.fingerprintOf(module), registered)
|
|
}
|
|
|
|
// WithSeatDefinitionsAgain gives the runner the way to read the seat list again (the seat list reader's Reload): a seat verb a bundle asks
|
|
// that the definitions held do not name is looked up again after it, never taken for a verb that sends no chunks.
|
|
func WithSeatDefinitionsAgain(again func() error) Option {
|
|
return func(c *consumers) { c.reread = again }
|
|
}
|
|
|
|
// chunkedAsked is chunked for a verb a bundle asks, where the answer decides whether the runner chooses the `call` the holder
|
|
// requires (AskAsChunked): a seat verb the definitions held do not name is not taken for one that sends no chunks, since the
|
|
// holder then refuses an ask that carries no call and the bundle sees only that refusal. The seat list is read again once, and
|
|
// a verb it still does not name is an error that says why. A runner that holds no definitions (nil) asks no chunks.
|
|
func (c *consumers) chunkedAsked(key string) (bool, error) {
|
|
if c.definitions == nil || !strings.HasPrefix(key, "seat:") {
|
|
return false, nil
|
|
}
|
|
name, _, _ := strings.Cut(key, "@")
|
|
seat, verb, ok := strings.Cut(strings.TrimPrefix(name, "seat:"), ".")
|
|
if !ok {
|
|
return false, nil
|
|
}
|
|
find := func() (chunks, found bool) {
|
|
for _, v := range c.definitions()[seat].Verbs {
|
|
if v.Name == verb {
|
|
return v.Chunks, true
|
|
}
|
|
}
|
|
return false, false
|
|
}
|
|
if chunks, found := find(); found {
|
|
return chunks, nil
|
|
}
|
|
var why string
|
|
if c.reread != nil {
|
|
if err := c.reread(); err != nil {
|
|
why = ": reading the seat list again failed: " + err.Error()
|
|
}
|
|
if chunks, found := find(); found {
|
|
return chunks, nil
|
|
}
|
|
}
|
|
return false, fmt.Errorf("the seat list this runner holds does not name the verb %s, so it cannot tell whether the verb sends its answer in chunks (the ask is not sent)%s", key, why)
|
|
}
|
|
|
|
// chunked says whether key names a seat's verb whose definition says `chunks` (design 47 G A-249): its answer is received in
|
|
// chunks by the runner, whose call hands the bundle the whole.
|
|
func (c *consumers) chunked(key string) bool {
|
|
if c.definitions == nil || !strings.HasPrefix(key, "seat:") {
|
|
return false
|
|
}
|
|
name, _, _ := strings.Cut(key, "@") // a verb asked of the machine that ran the ask is chunked as the verb is (A-254)
|
|
seat, verb, ok := strings.Cut(strings.TrimPrefix(name, "seat:"), ".")
|
|
if !ok {
|
|
return false
|
|
}
|
|
for _, v := range c.definitions()[seat].Verbs {
|
|
if v.Name == verb {
|
|
return v.Chunks
|
|
}
|
|
}
|
|
return false
|
|
}
|