The gate sits on both handlers the runner serves, a module's tools (its ledger repairs among them) and the seat verbs its modules hold, before the bundle. The same call again is judged on the router's own record of its act's newest ask: held to the warrant (operatorchannelclient.For), the option and the act it bound (Performs), within 30 minutes of the choice, and claimed by compare-and-set (Client.Take) before it runs, so one approval runs one call. A later call is told it still waits, was declined (not asked again for 10 minutes), or asks anew after expired, approved too long ago or already run. A runner's own tool marked is refused unasked; with no state approvals bound a marked call is refused and an unmarked one runs. The gate's reach (state, publish, the router's record) is the runner's own connection, in one place; it waits for the catalog half's first view on the events the runner hears. Builds: design 46 7-approval-mark §13, §14, §15, §17, §20 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
51 lines
1.9 KiB
Go
51 lines
1.9 KiB
Go
package runtime
|
|
|
|
import (
|
|
"github.com/novox/mesh-tools/node-tools/internal/approval"
|
|
"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)
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
|
|
// 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)
|
|
|
|
// 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)
|
|
}
|