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) }